Storage & Pipelines¶
from sqlspec.storage import (
AsyncStoragePipeline,
PartitionStrategyConfig,
ResolvedStorageTarget,
StorageBridgeJob,
StorageCapabilities,
StorageDestination,
StorageFormat,
StorageRegistry,
StorageTelemetry,
SyncStoragePipeline,
create_storage_bridge_job,
resolve_storage_path,
storage_registry,
)
Multi-backend object storage registry (local, fsspec, obstore) and Apache Arrow / Parquet / JSONL streaming storage pipelines. See Arrow & Storage for configuration and usage examples.
Storage Registry¶
StorageRegistry
¶
Global storage registry for named backend configurations.
Allows registering named storage backends that can be accessed from anywhere in your application. Backends are automatically selected based on URI scheme unless explicitly overridden.
register_alias
¶
Register a named alias for a storage configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
Unique alias name |
required |
uri
|
str
|
Storage URI |
required |
backend
|
str | None
|
Force specific backend ("local", "fsspec", "obstore") instead of auto-detection |
None
|
base_path
|
str
|
Base path to prepend to all operations |
''
|
**kwargs
|
Any
|
Backend-specific configuration options |
{}
|
get
¶
Get backend instance using URI-first routing with automatic backend selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri_or_alias
|
str | Path
|
URI to resolve directly OR named alias |
required |
backend
|
str | None
|
Force specific backend ("local", "fsspec", "obstore") instead of auto-selection |
None
|
**kwargs
|
Any
|
Additional backend-specific configuration options |
{}
|
Returns:
| Type | Description |
|---|---|
ObjectStoreProtocol
|
Backend instance with automatic backend selection |
Raises:
| Type | Description |
|---|---|
ImproperConfigurationError
|
If alias not found or invalid input |
resolve_storage_path
¶
Resolve path relative to base_path with protocol-specific handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to resolve. |
required |
base_path
|
str
|
Base path to prepend if path is relative. |
''
|
protocol
|
str
|
Storage protocol. |
FILE_PROTOCOL
|
strip_file_scheme
|
bool
|
Whether to strip |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Resolved path string suitable for the storage backend. |
Raises:
| Type | Description |
|---|---|
StoragePathTraversalError
|
If the path contains a parent reference or escapes |
Storage Pipelines¶
SyncStoragePipeline
¶
Bases: _StoragePipelineBase
Pipeline coordinating storage registry operations and telemetry.
AsyncStoragePipeline
¶
Bridge Jobs, Capabilities & Telemetry¶
StorageBridgeJob
¶
Bases: NamedTuple
Handle representing a storage bridge operation.
StorageCapabilities
¶
Bases: TypedDict
Runtime-evaluated driver storage capabilities.
Attributes:
| Name | Type | Description |
|---|---|---|
arrow_export_enabled |
bool
|
Whether the driver supports exporting query results as Apache Arrow tables or batches. |
arrow_import_enabled |
bool
|
Whether the driver supports ingesting Apache Arrow tables or record batches. |
parquet_export_enabled |
bool
|
Whether direct or staged Parquet export is available. |
parquet_import_enabled |
bool
|
Whether direct or staged Parquet ingestion is available. |
partition_strategies |
list[str]
|
Supported partition fan-out strategy names (such as |
default_storage_profile |
NotRequired[str | None]
|
Named storage registry profile used when callers omit an explicit backend URI. |
PartitionStrategyConfig
¶
Bases: TypedDict
Configuration for partition fan-out strategies.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
Partitioning strategy identifier ( |
partitions |
int
|
Target number of output partitions to produce. |
rows_per_chunk |
int
|
Maximum row count written per output file or batch chunk. |
manifest_path |
str
|
Optional destination URI or relative path for writing a partition manifest. |
ResolvedStorageTarget
¶
Bases: NamedTuple
A storage destination resolved to an address and its backend protocol.
StorageTelemetry
¶
Bases: TypedDict
Telemetry payload for storage bridge operations.
Attributes:
| Name | Type | Description |
|---|---|---|
destination |
str
|
Resolved target or source storage URI for the bridge transfer. |
bytes_processed |
int
|
Total uncompressed or encoded payload bytes read or written. |
rows_processed |
int
|
Total number of records transferred across the storage bridge. |
partitions_created |
int
|
Number of partitioned output objects written during export. |
duration_s |
float
|
Elapsed wall-clock transfer time in seconds. |
format |
str
|
Serialized wire/file format (such as |
extra |
dict[str, object]
|
Adapter-specific diagnostic counters or native COPY options. |
backend |
str
|
Storage backend implementation name ( |
correlation_id |
str
|
Active request correlation identifier attached to the storage job. |
config |
str
|
Adapter configuration class name executing the storage transfer. |
bind_key |
str
|
Registered SQLSpec configuration bind key, when configured. |
create_storage_bridge_job
¶
Create a storage bridge job handle with a unique identifier.
get_storage_bridge_diagnostics
¶
Return aggregated storage bridge + serializer cache metrics.
reset_storage_bridge_metrics
¶
Reset aggregated storage bridge metrics.