fsspeckit.storage_options.core API Reference¶
LocalStorageOptions¶
Local filesystem configuration options.
Provides basic configuration for local file access. While this class is simple, it maintains consistency with other storage options and enables transparent switching between local and remote storage.
Attributes:
protocol(str): Always "file" for local filesystemauto_mkdir(bool): Create directories automaticallymode(int): Default file creation mode (unix-style)
Example:
to_fsspec_kwargs()¶
Convert options to fsspec filesystem arguments.
Returns:
dict: Arguments suitable for LocalFileSystem
Example:
from_dict()¶
Create appropriate storage options instance from dictionary.
Factory function that creates the correct storage options class based on protocol.
Parameters:
| Name | Type | Description |
|---|---|---|
protocol |
str |
Storage protocol identifier (e.g., "s3", "gs", "file") |
storage_options |
dict |
Dictionary of configuration options |
Returns:
BaseStorageOptions: Appropriate storage options instance
Raises:
ValueError: If protocol is not supported
Example:
from_env()¶
Create storage options from environment variables.
Factory function that creates and configures storage options from protocol-specific environment variables.
Parameters:
| Name | Type | Description |
|---|---|---|
protocol |
str |
Storage protocol identifier (e.g., "s3", "github") |
Returns:
BaseStorageOptions: Configured storage options instance
Raises:
ValueError: If protocol is not supported
Example:
infer_protocol_from_uri()¶
Infer the storage protocol from a URI string.
Analyzes the URI to determine the appropriate storage protocol based on the scheme or path format.
Parameters:
| Name | Type | Description |
|---|---|---|
uri |
str |
URI or path string to analyze. Examples: - "s3://bucket/path" - "gs://bucket/path" - "github://org/repo" - "/local/path" |
Returns:
str: Inferred protocol identifier
Example:
storage_options_from_uri()¶
Create storage options instance from a URI string.
Infers the protocol and extracts relevant configuration from the URI to create appropriate storage options.
Parameters:
| Name | Type | Description |
|---|---|---|
uri |
str |
URI string containing protocol and optional configuration. Examples: - "s3://bucket/path" - "gs://project/bucket/path" - "github://org/repo" |
Returns:
BaseStorageOptions: Configured storage options instance
Example:
merge_storage_options()¶
Merge multiple storage options into a single configuration.
Combines options from multiple sources with control over precedence.
Parameters:
| Name | Type | Description |
|---|---|---|
*options |
BaseStorageOptions or dict |
Storage options to merge. Can be: - BaseStorageOptions instances - Dictionaries of options - None values (ignored) |
overwrite |
bool |
Whether later options override earlier ones |
Returns:
BaseStorageOptions: Combined storage options
Example:
StorageOptions¶
High-level storage options container and factory.
Provides a unified interface for creating and managing storage options for different protocols.
Attributes:
storage_options(BaseStorageOptions): Underlying storage options instance
Example:
create()¶
Create storage options from arguments.
Parameters:
| Name | Type | Description |
|---|---|---|
**data |
dict |
Either: - protocol and configuration options - storage_options=pre-configured instance |
Returns:
StorageOptions: Configured storage options instance
Raises:
ValueError: If protocol missing or invalid
Example:
from_yaml()¶
Create storage options from YAML configuration.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
str |
Path to YAML configuration file |
fs |
fsspec.AbstractFileSystem, optional |
Filesystem for reading configuration |
Returns:
StorageOptions: Configured storage options
Example:
from_env()¶
Create storage options from environment variables.
Parameters:
| Name | Type | Description |
|---|---|---|
protocol |
str |
Storage protocol to configure |
Returns:
StorageOptions: Environment-configured options
Example:
to_filesystem()¶
Create fsspec filesystem instance.
Returns:
AbstractFileSystem: Configured filesystem instance
Example:
to_dict()¶
Convert storage options to dictionary.
Parameters:
| Name | Type | Description |
|---|---|---|
with_protocol |
bool |
Whether to include protocol in output |
Returns:
dict: Storage options as dictionary
Example:
to_object_store_kwargs()¶
Get options formatted for object store clients.
Parameters:
| Name | Type | Description |
|---|---|---|
with_conditional_put |
bool |
Add etag-based conditional put support |
Returns:
dict: Object store configuration dictionary
Example:
BaseStorageOptions¶
Base class for filesystem storage configuration options.
Provides common functionality for all storage option classes including: - YAML serialization/deserialization - Dictionary conversion - Filesystem instance creation - Configuration updates
Attributes:
protocol(str): Storage protocol identifier (e.g., "s3", "gs", "file")
Example:
to_dict()¶
Convert storage options to dictionary.
Parameters:
| Name | Type | Description |
|---|---|---|
with_protocol |
bool |
Whether to include protocol in output dictionary |
Returns:
dict: Dictionary of storage options with non-None values
Example:
from_yaml()¶
Load storage options from YAML file.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
str |
Path to YAML configuration file |
fs |
fsspec.AbstractFileSystem, optional |
Filesystem to use for reading file |
Returns:
BaseStorageOptions: Loaded storage options instance
Example:
to_yaml()¶
Save storage options to YAML file.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
str |
Path where to save configuration |
fs |
fsspec.AbstractFileSystem, optional |
Filesystem to use for writing |
Example:
to_filesystem()¶
Create fsspec filesystem instance from options.
Returns:
AbstractFileSystem: Configured filesystem instance
Example:
update()¶
Update storage options with new values.
Parameters:
| Name | Type | Description |
|---|---|---|
**kwargs |
dict |
New option values to set |
Returns:
BaseStorageOptions: Updated instance
Example: