Python API reference¶
Registered backend classes inherit from fsspec.AbstractFileSystem.
AbstractDatabase defines the custom Python backend contract.
Package Exports¶
- class fsspec_db.AbstractDatabase[source]¶
Bases:
ABCDatabase primitive contract for Python-defined backends.
The method set mirrors the Rust
Databasetrait, except for Rust-only default methods. Metadata methods return the exported*Infoclasses.queryreturns apyarrow.Table.insertreceives apyarrow.Tableand returns the number of rows inserted.- abstractmethod insert(schema: str, relation: str, table: Any, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- abstractmethod list_columns(schema: str, relation: str) list[ColumnInfo][source]¶
Return columns for
schema.relation.
- abstractmethod list_constraints(schema: str, relation: str) list[ConstraintInfo][source]¶
Return constraints for
schema.relation.
- abstractmethod list_indexes(schema: str, relation: str) list[IndexInfo][source]¶
Return indexes for
schema.relation.
- abstractmethod list_relations(schema: str) list[RelationInfo][source]¶
Return tables and views in
schema.
- abstractmethod query(sql: str, params: list[Any] | None = None) Any[source]¶
Return a
pyarrow.Tableforsqland optional scalarparams.
- class fsspec_db.AbstractDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemfsspec filesystem adapter for an
AbstractDatabaseimplementation.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
- class fsspec_db.DuckDBDatabase(database: str = ':memory:', *, connection: Any = None, read_only: bool = False)[source]¶
Bases:
AbstractDatabaseArrow-native Python backend for an embedded DuckDB database.
- insert(schema: str, relation: str, table: Table, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- class fsspec_db.DuckDBDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
PyDatabaseFileSystem
- class fsspec_db.MySQLDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemMySQL-backed fsspec filesystem registered as
db+mysql.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
- class fsspec_db.OdbcDatabase(connection_string: str, *, user: str = '', password: str = '', batch_size: int = 65535)[source]¶
Bases:
AbstractDatabaseArrow-native ODBC backend using the arrow-odbc connection API.
- insert(schema: str, relation: str, table: Table, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- class fsspec_db.OdbcDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
PyDatabaseFileSystem
- class fsspec_db.PostgresDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemPostgreSQL-backed fsspec filesystem registered as
db+postgresql.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
- class fsspec_db.PyDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemDirect Python filesystem adapter for an
AbstractDatabase.Unlike
AbstractDatabaseFileSystem, this class does not call the Rust bridge. It is primarily useful for Python-only backend implementations and conformance testing.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
- class fsspec_db.SQLAlchemyDatabase(url: str | None = None, *, engine: Any = None, **engine_options: Any)[source]¶
Bases:
AbstractDatabaseSQLAlchemy engine adapter implementing the Python database contract.
- insert(schema: str, relation: str, table: Table, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- list_columns(schema: str, relation: str) list[ColumnInfo][source]¶
Return columns for
schema.relation.
- list_constraints(schema: str, relation: str) list[ConstraintInfo][source]¶
Return constraints for
schema.relation.
- list_indexes(schema: str, relation: str) list[IndexInfo][source]¶
Return indexes for
schema.relation.
- query(sql: str, params: list[Any] | None = None) Table[source]¶
Return a
pyarrow.Tableforsqland optional scalarparams.
- class fsspec_db.SQLAlchemyDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
PyDatabaseFileSystem
- class fsspec_db.SQLiteDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemSQLite-backed fsspec filesystem registered as
db+sqlite.Overwrite writes replace table contents; use append mode to preserve rows.
- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
Base Classes¶
- class fsspec_db.spec.AbstractDatabase[source]¶
Bases:
ABCDatabase primitive contract for Python-defined backends.
The method set mirrors the Rust
Databasetrait, except for Rust-only default methods. Metadata methods return the exported*Infoclasses.queryreturns apyarrow.Table.insertreceives apyarrow.Tableand returns the number of rows inserted.- abstractmethod insert(schema: str, relation: str, table: Any, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- abstractmethod list_columns(schema: str, relation: str) list[ColumnInfo][source]¶
Return columns for
schema.relation.
- abstractmethod list_constraints(schema: str, relation: str) list[ConstraintInfo][source]¶
Return constraints for
schema.relation.
- abstractmethod list_indexes(schema: str, relation: str) list[IndexInfo][source]¶
Return indexes for
schema.relation.
- abstractmethod list_relations(schema: str) list[RelationInfo][source]¶
Return tables and views in
schema.
- abstractmethod query(sql: str, params: list[Any] | None = None) Any[source]¶
Return a
pyarrow.Tableforsqland optional scalarparams.
- class fsspec_db.spec.AbstractDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemfsspec filesystem adapter for an
AbstractDatabaseimplementation.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
- class fsspec_db.spec.DatabaseDdlMixin[source]¶
Bases:
objectGuarded database DDL mapped onto fsspec mutation methods.
- class fsspec_db.spec.DeferredDatabaseFile(commit: Any)[source]¶
Bases:
BytesIOWrite buffer committed or discarded by
fsspec.Transaction.
- class fsspec_db.spec.IntrospectionCacheMixin[source]¶
Bases:
objectCache database listings and metadata using fsspec’s bounded TTL cache.
AbstractDatabaseFileSystem and the native SQLite, PostgreSQL, and MySQL filesystem
classes expose query(sql, params=None) for pyarrow.Table results and
open_query(sql, params=None) for Arrow IPC stream bytes.
Python Filesystem Adapter¶
- class fsspec_db.python.PyDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemDirect Python filesystem adapter for an
AbstractDatabase.Unlike
AbstractDatabaseFileSystem, this class does not call the Rust bridge. It is primarily useful for Python-only backend implementations and conformance testing.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
SQLite Backend¶
- class fsspec_db.sqlite.SQLiteDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemSQLite-backed fsspec filesystem registered as
db+sqlite.Overwrite writes replace table contents; use append mode to preserve rows.
- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
PostgreSQL Backend¶
- class fsspec_db.postgres.PostgresDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemPostgreSQL-backed fsspec filesystem registered as
db+postgresql.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
MySQL Backend¶
- class fsspec_db.mysql.MySQLDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
DatabaseDdlMixin,IntrospectionCacheMixin,AbstractFileSystemMySQL-backed fsspec filesystem registered as
db+mysql.- cat_file(path: str, start: int | None = None, end: int | None = None, **kwargs: Any) bytes[source]¶
Get the content of a file
- Parameters:
path (URL of file on this filesystems)
start (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
end (int) – Bytes limits of the read. If negative, backwards from end, like usual python slices. Either can be None for start or end of file, respectively
kwargs (passed to
open().)
- info(path: str, **kwargs: Any) dict[str, Any][source]¶
Give details of entry at path
Returns a single dictionary, with exactly the same information as
lswould withdetail=True.The default implementation calls ls and could be overridden by a shortcut. kwargs are passed on to
`ls().Some file systems might not be able to measure the file’s size, in which case, the returned dict will include
'size': None.- Returns:
dict with keys (name (full path in the FS), size (in bytes), type (file,)
directory, or something else) and other FS-specific keys.
- ls(path: str, detail: bool = True, **kwargs: Any) list[dict[str, Any]] | list[str][source]¶
List objects at path.
This should include subdirectories and files at that location. The difference between a file and a directory must be clear when details are requested.
The specific keys, or perhaps a FileInfo class, or similar, is TBD, but must be consistent across implementations. Must include:
full path to the entry (without protocol)
size of the entry, in bytes. If the value cannot be determined, will be
None.type of entry, “file”, “directory” or other
Additional information may be present, appropriate to the file-system, e.g., generation, checksum, etc.
May use refresh=True|False to allow use of self._ls_from_cache to check for a saved listing and avoid calling the backend. This would be common where listing may be expensive.
- Parameters:
path (str)
detail (bool) – if True, gives a list of dictionaries, where each is the same as the result of
info(path). If False, gives a list of paths (str).kwargs (may have additional backend-specific options, such as version) – information
- Returns:
List of strings if detail is False, or list of directory information
dicts if detail is True.
DuckDB Backend¶
- class fsspec_db.duckdb.DuckDBDatabase(database: str = ':memory:', *, connection: Any = None, read_only: bool = False)[source]¶
Bases:
AbstractDatabaseArrow-native Python backend for an embedded DuckDB database.
- insert(schema: str, relation: str, table: Table, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- class fsspec_db.duckdb.DuckDBDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
PyDatabaseFileSystem
SQLAlchemy Backend¶
- class fsspec_db.sqlalchemy.SQLAlchemyDatabase(url: str | None = None, *, engine: Any = None, **engine_options: Any)[source]¶
Bases:
AbstractDatabaseSQLAlchemy engine adapter implementing the Python database contract.
- insert(schema: str, relation: str, table: Table, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- list_columns(schema: str, relation: str) list[ColumnInfo][source]¶
Return columns for
schema.relation.
- list_constraints(schema: str, relation: str) list[ConstraintInfo][source]¶
Return constraints for
schema.relation.
- list_indexes(schema: str, relation: str) list[IndexInfo][source]¶
Return indexes for
schema.relation.
- query(sql: str, params: list[Any] | None = None) Table[source]¶
Return a
pyarrow.Tableforsqland optional scalarparams.
- class fsspec_db.sqlalchemy.SQLAlchemyDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
PyDatabaseFileSystem
ODBC Backend¶
- class fsspec_db.odbc.OdbcDatabase(connection_string: str, *, user: str = '', password: str = '', batch_size: int = 65535)[source]¶
Bases:
AbstractDatabaseArrow-native ODBC backend using the arrow-odbc connection API.
- insert(schema: str, relation: str, table: Table, mode: str = 'append') int[source]¶
Insert
tableintoschema.relationwithappendortruncatemode.
- class fsspec_db.odbc.OdbcDatabaseFileSystem(*args, **kwargs)[source]¶
Bases:
PyDatabaseFileSystem