file_system¶
- class litestar.file_system.BaseFileSystem[source]¶
Bases:
ABC- abstractmethod async info(path: PathType, **kwargs: Any) FileInfo[source]¶
Return a
FileInfofor the givenpath
- abstractmethod async read_bytes(path: PathType, start: int = 0, end: int = -1) bytes[source]¶
Read bytes from
path
- class litestar.file_system.BaseLocalFileSystem[source]¶
Bases:
LinkableFileSystemBase class for a local file system.
- class litestar.file_system.FileInfo[source]¶
Bases:
TypedDictFile information gathered from a file system.
- is_symlink: NotRequired[bool | None]¶
‘True’ if the file is a symbolic link. ‘None’ if the file system does not support symlinks
- mtime: NotRequired[float]¶
Modified time stamp.
- class litestar.file_system.FileSystemRegistry[source]¶
Bases:
InitPlugin- __init__(file_systems: Mapping[str, AnyFileSystem] | None = None, default: AnyFileSystem | None = None) None[source]¶
File system registry
- Parameters:
file_systems¶ – A mapping of names to file systems
default¶ – Default file system to use when no system is specified. If
None, default toBaseLocalFileSystem
- property default: BaseFileSystem¶
Return the default file system
- get(name: str) BaseFileSystem | None[source]¶
Return the file system registered under
name. If no matching file system is found, returnNone
- class litestar.file_system.FsspecAsyncWrapper[source]¶
Bases:
BaseFileSystem- __init__(fs: FsspecAsyncFileSystem) None[source]¶
Wrap a
fsspec.asyn.AsyncFileSystemto provide a class:litestar.file_system.BaseFileSystem compatible interface- Parameters:
fs¶ – An
fsspec.asyn.AsyncFileSysteminstantiated with ` asynchronous=True`
- async info(path: PathType, **kwargs: Any) FileInfo[source]¶
Return a
FileInfofor the givenpath.Return info verbatim from
fsspec.async.AsyncFileSystem._info, but try to patch ‘mtime’ usinglitestar.file_system.get_fsspec_mtime_equivalent().
- async read_bytes(path: PathType, start: int = 0, end: int = -1) bytes[source]¶
Read bytes from
pathusingfsspec.asyn.AsyncFileSystem._cat_file
- async iter(path: PathType, chunksize: int, start: int = 0, end: int = -1) AsyncGenerator[bytes, None][source]¶
Stream bytes from
path.If no offsets are given and the file system implements
fsspec.async.AsyncFileSystem.async_open, useasync_open, otherwise read chunks manually usingfsspec.async.AsyncFileSystem._cat_file
- class litestar.file_system.FsspecSyncWrapper[source]¶
Bases:
BaseFileSystem- __init__(fs: FsspecFileSystem) None[source]¶
Wrap a
fsspec.spec.AbstractFileSystemto provide alitestar.file_system.BaseFileSystemcompatible interface
- async info(path: PathType, **kwargs: Any) FileInfo[source]¶
Return a
FileInfofor the givenpath.Return info verbatim from
fsspec.spec.AbstractFileSystem.info(), but try to patch ‘mtime’ usinglitestar.file_system.get_fsspec_mtime_equivalent().
- async read_bytes(path: PathType, start: int = 0, end: int = -1) bytes[source]¶
Read bytes from
pathusingfsspec.spec.AbstractFileSystem.cat_file()
- class litestar.file_system.LinkableFileSystem[source]¶
Bases:
BaseFileSystem,ABCA file system that supports symlinks
- abstractmethod async resolve_symlinks(path: PathType) str[source]¶
Return
pathwith all symlinks resolved
- classmethod register_as_linkable(fs_type: type[AnyFileSystem], resolver: SymlinkResolver) None[source]¶
Register a file system as ‘linkable’, i.e. supporting symlinks, that does not itself implement
LinkableFileSystem.By default,
fsspec.implementations.local.LocalFileSystemis registered.
- classmethod get_symlink_resolver(fs: AnyFileSystem) SymlinkResolver | None[source]¶
For a given file system, get a function to resolve potential symlinks in a path.
For classes implementing
LinkableFileSystem, theirresolve_symlinks()is returned. Otherwise, theresolverregistered viaregister_as_linkablewill be returned.
- litestar.file_system.get_fsspec_mtime_equivalent(info: dict[str, Any]) float | None[source]¶
Return the ‘mtime’ or equivalent for different fsspec implementations, since they are not standardized.
- litestar.file_system.maybe_wrap_fsspec_file_system(file_system: AnyFileSystem) BaseFileSystem[source]¶
If
file_systemis an fsspec file system, wrap it inFsspecSyncWrapperorFsspecAsyncWrapperdepending on its type. If fsspec is not installed orfile_systemis not an fsspec file system, returnfile_system