file_system¶
- class litestar.file_system.BaseFileSystem¶
Bases:
ABC
- class litestar.file_system.BaseLocalFileSystem¶
Bases:
LinkableFileSystem
Base class for a local file system.
- class litestar.file_system.FileInfo¶
Bases:
TypedDict
File information gathered from a file system.
- class litestar.file_system.FileSystemRegistry¶
Bases:
InitPlugin
- __init__(file_systems: Mapping[str, AnyFileSystem] | None = None, default: AnyFileSystem | None = None) None ¶
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 ¶
Return the file system registered under
name
. If no matching file system is found, returnNone
- class litestar.file_system.FsspecAsyncWrapper¶
Bases:
BaseFileSystem
- __init__(fs: FsspecAsyncFileSystem) None ¶
Wrap a
fsspec.asyn.AsyncFileSystem
to provide a class:litestar.file_system.BaseFileSystem compatible interface- Parameters:
fs¶ – An
fsspec.asyn.AsyncFileSystem
instantiated with ` asynchronous=True`
- async info(path: PathType, **kwargs: Any) FileInfo ¶
Return a
FileInfo
for 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 ¶
Read bytes from
path
usingfsspec.asyn.AsyncFileSystem._cat_file
- async iter(path: PathType, chunksize: int, start: int = 0, end: int = -1) AsyncGenerator[bytes, None] ¶
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¶
Bases:
BaseFileSystem
- __init__(fs: FsspecFileSystem) None ¶
Wrap a
fsspec.spec.AbstractFileSystem
to provide alitestar.file_system.BaseFileSystem
compatible interface
- async info(path: PathType, **kwargs: Any) FileInfo ¶
Return a
FileInfo
for 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 ¶
Read bytes from
path
usingfsspec.spec.AbstractFileSystem.cat_file()
- class litestar.file_system.LinkableFileSystem¶
Bases:
BaseFileSystem
,ABC
A file system that supports symlinks
- classmethod register_as_linkable(fs_type: type[AnyFileSystem], resolver: SymlinkResolver) None ¶
Register a file system as ‘linkable’, i.e. supporting symlinks, that does not itself implement
LinkableFileSystem
.By default,
fsspec.implementations.local.LocalFileSystem
is registered.
- classmethod get_symlink_resolver(fs: AnyFileSystem) SymlinkResolver | None ¶
For a given file system, get a function to resolve potential symlinks in a path.
For classes implementing
LinkableFileSystem
, theirresolve_symlinks()
is returned. Otherwise, theresolver
registered viaregister_as_linkable
will be returned.
- litestar.file_system.get_fsspec_mtime_equivalent(info: dict[str, Any]) float | None ¶
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 ¶
If
file_system
is an fsspec file system, wrap it inFsspecSyncWrapper
orFsspecAsyncWrapper
depending on its type. If fsspec is not installed orfile_system
is not an fsspec file system, returnfile_system