dandi.misctypes#

New in version 0.36.0.

Miscellaneous public classes

class dandi.misctypes.BasePath(parts: tuple[str, ...])[source]#

An abstract base class for path-like objects that can be traversed with the / operator à la pathlib.Path (though, unlike pathlib.Path instances, “dividing” by another non-string path is not allowed). All paths are treated as forward-slash-separated relative paths under an empty-name “root” path.

abstract exists() bool[source]#

True iff the resource at the given path exists

abstract is_dir() bool[source]#

True if the resource at the given path exists and is a directory

abstract is_file() bool[source]#

True if the resource at the given path exists and is a file

is_root() bool[source]#

Returns true if this path object represents the root of its hierarchy

abstract iterdir() Iterator[P][source]#

Returns a generator of the paths under the instance, which must be a directory

joinpath(*paths: str) P[source]#

Combine the path with each name or relative path in paths using the / operator

match(pattern: str) bool[source]#

Tests whether the path matches the given glob pattern

property name: str#

The basename of the path object. When the object represents the root of a path hierarchy, this is the empty string.

abstract property parent: P#

The parent path of the object. The parent of the root of a path hierarchy is itself.

property parents: tuple[P, ...]#

A tuple of the path’s ancestors, starting at the parent and going up to (and including) the root of the hierarchy

parts: tuple[str, ...]#

The path components of the object

property root_path: P#

The root of the path object’s hierarchy

abstract property size: int#

The size of the resource at the path

property stem: str#

The basename without its final file extension, if any

property suffix: str#

The final file extension of the basename, if any

property suffixes: list[str]#

A list of the basename’s file extensions

with_name(name: str) P[source]#

Equivalent to p.parent / name

with_stem(stem: str) P[source]#

Returns a new path with the stem changed

with_suffix(suffix: str) P[source]#

Returns a new path with the final file extension changed

dandi.misctypes.DUMMY_DANDI_ETAG = Digest(algorithm=<DigestType.dandi_etag: 'dandi:dandi-etag'>, value='dddddddddddddddddddddddddddddddd-1')#

Placeholder digest used in some situations where a digest is required but not actually relevant and would be too expensive to calculate

class dandi.misctypes.Digest(algorithm: DigestType, value: str)[source]#

A computed digest for a file or directory

algorithm: DigestType#

The digest algorithm used

asdict() dict[DigestType, str][source]#

Convert the instance to a single-item dict mapping the digest algorithm to the digest value

classmethod dandi_etag(value: str) Digest[source]#

Construct a Digest with the given value and a algorithm of DigestType.dandi_etag

classmethod dandi_zarr(value: str) Digest[source]#

Construct a Digest with the given value and a algorithm of DigestType.dandi_zarr_checksum

value: str#

The digest itself

class dandi.misctypes.LocalReadableFile(filepath: str | Path)[source]#

A concrete implementation of Readable for local files.

Instances of this class are obtained by calling LocalFileAsset.as_readable() or DandisetMetadataFile.as_readable().

filepath#

The path to a local file to read

get_filename() str[source]#

Returns the base name of the resource, suitable for use as a file name

get_mtime() datetime[source]#

Returns the time at which the resource’s contents were last modified, if it can be determined

get_size() int[source]#

Returns the size in bytes of the resource

open() IO[bytes][source]#

Returns a readable binary filehandle for accessing the resource’s bytes

class dandi.misctypes.Readable[source]#

New in version 0.50.0.

An abstract base class representing a local or remote resource that can be opened & read like a file

abstract get_filename() str[source]#

Returns the base name of the resource, suitable for use as a file name

abstract get_mtime() datetime | None[source]#

Returns the time at which the resource’s contents were last modified, if it can be determined

abstract get_size() int[source]#

Returns the size in bytes of the resource

abstract open() IO[bytes][source]#

Returns a readable binary filehandle for accessing the resource’s bytes

class dandi.misctypes.RemoteReadableAsset(url: str, size: int, mtime: datetime | None, name: str)[source]#

A concrete implementation of Readable for DANDI blob assets on a remote server. The fsspec library must be installed with the http extra (e.g., pip install "fsspec[http]") in order for open() to be usable.

Instances of this class are obtained by calling BaseRemoteBlobAsset.as_readable().

get_filename() str[source]#

Returns the base name of the resource, suitable for use as a file name

get_mtime() datetime | None[source]#

Returns the time at which the resource’s contents were last modified, if it can be determined

get_size() int[source]#

Returns the size in bytes of the resource

open() IO[bytes][source]#

Returns a readable binary filehandle for accessing the resource’s bytes

url: str#

The URL that data is read from