Object Storage¶
vertebra.storage provides backend configs, sync and async object stores, file-like readers and writers, presigned URLs, and HTTP Range helpers backed by vertebra-storage. See the object storage guide for backend selection and examples.
Object stores¶
Construct a store from a URI or configuration with SyncObjectStore(target, *, options=None, signing=None, token_cache=None). Factory methods (from_config, from_local, from_s3, from_gcs, from_azure, from_oci, from_r2, from_http, and from_memory) build the same store from fields. Each store exposes read-only properties (url, scheme, options, token_cache, supports_signing), batch transfers (upload_many, download_many, staged_download), paginated listing (list_page, list_with_delimiter), URL signing (sign, presign_get, presign_put, verify_presigned_url), put_multipart, to_async(), close(), and context-manager support.
AsyncObjectStore mirrors SyncObjectStore with matching constructors, properties, and signatures. I/O methods are awaited, except get_stream, iter_arrow_batches, iter_parquet_batches, open_reader, and open_writer, which return async iterators or file handles directly. staged_download is an async context manager, verify_presigned_url stays synchronous, and to_sync() returns a SyncObjectStore sharing the same Rust handle.
SyncObjectStore
¶
Synchronous object store supporting zero-copy buffers, blocking I/O, and multi-cloud URL signing.
put
¶
put(
path,
data,
*,
content_type=None,
attributes=None,
if_not_exists=False,
if_match=None,
if_none_match=None,
checksum=False,
expected_sha256=None,
expected_crc32c=None,
expected_md5=None,
)
Write any Buffer (bytes, bytearray, memoryview) to the given object key.
put_stream
¶
put_stream(
path,
chunks,
*,
content_type=None,
attributes=None,
if_not_exists=False,
if_match=None,
if_none_match=None,
checksum=False,
expected_sha256=None,
expected_crc32c=None,
expected_md5=None,
)
Stream an iterable of buffer chunks into an incremental multipart upload.
Each chunk passes through the same buffer normalization as put, so typed buffers such as
array("I"), NumPy arrays, and pyarrow.Buffer upload as their raw bytes.
get_stream
¶
Stream object payload chunks as zero-copy StorageBuffer instances.
open_reader
¶
Open a seekable read-only SyncReadableFile stream over the given object key.
Reads shorter than read_ahead are served from one cached read_ahead-byte range window;
read_ahead=0 issues one range request per read. When expected_sha256 is supplied, full
sequential reads verify the SHA-256 digest at EOF and raise IntegrityError on mismatch.
open_writer
¶
open_writer(
path,
*,
content_type=None,
attributes=None,
part_size=8388608,
if_not_exists=False,
if_match=None,
if_none_match=None,
checksum=False,
expected_sha256=None,
expected_crc32c=None,
expected_md5=None,
)
Open a write-only SyncWritableFile that streams buffered part_size slices into a multipart upload.
The upload is created lazily on the first full part or on close, completed by closing the
writer, and aborted by abort() or an exception escaping the context manager.
write_arrow
¶
Write batch-bounded Arrow IPC through native multipart upload.
options keys such as compression build pyarrow.ipc.IpcWriteOptions;
a prebuilt options entry passes through unchanged.
write_parquet
¶
write_parquet(
key,
batches,
*,
schema=None,
compression="zstd",
row_group_size=65536,
use_dictionary=True,
use_byte_stream_split=False,
options=None,
)
Write batch-bounded Parquet rowgroups through native multipart upload.
options is forwarded to pyarrow.parquet.ParquetWriter and overrides
compression, row_group_size, use_dictionary, and use_byte_stream_split.
iter_arrow_batches
¶
Yield Arrow IPC RecordBatch objects through native streaming reads.
options keys such as use_threads build pyarrow.ipc.IpcReadOptions.
iter_parquet_batches
¶
Yield projected Parquet batches through bounded native range reads.
options is forwarded to pyarrow.parquet.ParquetFile, except row_groups
and use_threads, which select and decode rowgroups in iter_batches.
sign
¶
Generate a presigned URL for key using the store's configured provider credentials.
AsyncObjectStore
¶
Bases: _BaseObjectStore
Asynchronous object store supporting zero-copy buffers, Tokio awaitables, and multi-cloud URL signing.
Backend configurations¶
All configurations are frozen msgspec.Struct types. GCSConfig.sync_token_cache() and GCSConfig.async_token_cache() build a shared token cache for the configured identity.
S3Config
¶
Configuration for AWS S3 or S3-compatible object storage.
Attributes:
| Name | Type | Description |
|---|---|---|
bucket | str | Target S3 bucket name. |
region | str | AWS region used for SigV4 request signing and endpoint resolution. |
endpoint | str | None | Optional custom S3-compatible endpoint URL (e.g. MinIO, LocalStack, or Ceph RGW). |
access_key_id | str | None | Optional AWS IAM access key ID. |
secret_access_key | str | None | Optional AWS IAM secret access key. |
session_token | str | None | Optional AWS STS temporary session token. |
virtual_hosted_style | bool | When True, address buckets using virtual-hosted-style URLs ( |
allow_http | bool | When True, permit unencrypted |
GCSConfig
¶
Configuration for Google Cloud Storage with Application Default Credentials (ADC) support.
Attributes:
| Name | Type | Description |
|---|---|---|
bucket | str | Target Google Cloud Storage bucket name. |
service_account_path | str | None | Optional filesystem path to a Google Cloud service account JSON key file. |
service_account_key | str | None | Optional inline JSON string containing a Google Cloud service account key. |
application_credentials | str | None | Optional path to an Application Default Credentials JSON file ( |
service_account_email | str | None | Optional service account email used for IAM |
target_service_account | str | None | Optional target service account email for keyless IAM impersonation ( |
iam_endpoint | str | Base URL for the Google Cloud IAM Credentials REST API. |
access_token | str | None | Optional OAuth2 bearer access token used for GCS REST and IAM |
endpoint | str | None | Optional custom GCS endpoint URL (or automatically resolved from |
allow_http | bool | When True, permit unencrypted |
skip_signature | bool | When True, send unsigned requests against anonymous buckets or local emulators. |
refresh_skew_seconds | int | Proactive OAuth2 token refresh skew window in seconds before expiration. |
quota_project_id | str | None | Optional Google Cloud quota project ID forwarded as |
AzureConfig
¶
Configuration for Azure Blob Storage and ADLS Gen2.
Attributes:
| Name | Type | Description |
|---|---|---|
container | str | Target Azure Blob Storage container or ADLS Gen2 filesystem name. |
account | str | Azure Storage account name. |
access_key | str | None | Optional Base64-encoded Azure Storage account shared key. |
sas_token | str | None | Optional pre-generated Shared Access Signature (SAS) query string. |
tenant_id | str | None | Optional Microsoft Entra ID (Azure AD) tenant ID for service principal auth. |
client_id | str | None | Optional Microsoft Entra ID application (client) ID. |
client_secret | str | None | Optional Microsoft Entra ID client secret. |
endpoint | str | None | Optional custom Azure Blob endpoint URL. |
use_emulator | bool | When True, connect to the local Azurite emulator endpoint. |
R2Config
¶
Configuration for Cloudflare R2 object storage.
Attributes:
| Name | Type | Description |
|---|---|---|
bucket | str | Target Cloudflare R2 bucket name. |
account_id | str | Cloudflare 32-character hexadecimal account identifier. |
access_key_id | str | None | Optional R2 S3-compatible API token access key ID. |
secret_access_key | str | None | Optional R2 S3-compatible API token secret access key. |
jurisdiction | Literal['eu', 'fedramp'] | str | None | Optional R2 data-locality jurisdiction subdomain ( |
custom_domain | str | None | Optional public custom domain bound to the R2 bucket. |
endpoint | str | None | Optional explicit R2 endpoint URL override. |
allow_http | bool | When True, permit unencrypted |
OCIConfig
¶
Configuration for native Oracle Cloud Infrastructure (OCI) Object Storage REST v2.
Attributes:
| Name | Type | Description |
|---|---|---|
bucket | str | Target OCI Object Storage bucket name. |
namespace | str | OCI Object Storage tenancy namespace string. |
region | str | OCI region identifier (e.g. |
tenancy_ocid | str | None | OCID of the Oracle Cloud tenancy ( |
user_ocid | str | None | OCID of the IAM user signing API requests ( |
fingerprint | str | None | MD5 fingerprint of the RSA API signing public key. |
private_key_pem | str | None | Inline PEM-encoded RSA private key used for |
private_key_path | str | Path | None | Filesystem path to a PEM-encoded RSA private key file. |
par_token | str | None | Optional OCI Pre-Authenticated Request (PAR) token for bucket-scoped URL signing. |
par_url_prefix | str | None | Optional full OCI Pre-Authenticated Request base URL prefix ending in |
endpoint | str | None | Optional custom OCI Object Storage REST v2 endpoint URL. |
LocalConfig
¶
Configuration for local filesystem object storage.
Attributes:
| Name | Type | Description |
|---|---|---|
root | str | Path | Root directory on the local filesystem under which object keys are resolved. |
create_dirs | bool | When True, automatically create |
MemoryConfig
¶
Configuration for in-memory object storage.
Attributes:
| Name | Type | Description |
|---|---|---|
namespace | str | Descriptive label for the in-memory store; it does not select or share storage. |
HTTPConfig
¶
Configuration for HTTP/WebDAV object storage.
Attributes:
| Name | Type | Description |
|---|---|---|
url | str | Base |
headers | dict[str, str] | None | Optional static HTTP headers included on every outbound storage request. |
Readers and writers¶
Readers support read, read_at, seek, tell, and close; the async reader awaits read and read_at. Writers support write, tell, close (aclose on the async writer), abort, and the result property.
SyncReadableFile
¶
Bases: _ReadableFileMixin, RawIOBase
Seekable synchronous read-only file-like object backed by SyncObjectStore range and stream reads.
Attributes:
| Name | Type | Description |
|---|---|---|
size | int | Return total object byte size. |
AsyncReadableFile
¶
Bases: _ReadableFileMixin
Seekable asynchronous read-only stream backed by AsyncObjectStore range and stream reads.
Attributes:
| Name | Type | Description |
|---|---|---|
size | int | None | Return total object byte size when resolved. |
SyncWritableFile
¶
Bases: _WritableFileMixin, RawIOBase
Write-only synchronous stream uploading buffered part_size slices through a native multipart upload.
AsyncWritableFile
¶
Bases: _WritableFileMixin
Write-only asynchronous stream uploading buffered part_size slices through a native multipart upload.
Metadata and signing¶
ObjectMeta
¶
Metadata describing an object stored in ObjectStore.
Attributes:
| Name | Type | Description |
|---|---|---|
path | str | Normalized |
size | int | Object payload size in bytes. |
last_modified | str | RFC 3339 / ISO-8601 UTC timestamp of the object's last modification. |
etag | str | None | Optional content entity tag ( |
version | str | None | Optional backend object version identifier. |
content_type | str | None | Optional MIME content type ( |
attributes | dict[str, str] | User-defined string metadata attributes persisted with the object. |
sha256 | str | None | Optional lowercase hexadecimal SHA-256 content digest receipt. |
crc32c | str | None | Optional lowercase hexadecimal Castagnoli CRC32C content digest receipt. |
md5 | str | None | Optional lowercase hexadecimal MD5 content digest receipt. |
PutResult
¶
Bases: ObjectMeta
Result metadata returned from a write operation, carrying sha256/crc32c/md5 receipts when requested.
SigningConfig
¶
Configuration for HMAC-SHA256, S3 SigV4, Azure SAS, OCI PAR, and GCS V4 presigned URL generation.
Attributes:
| Name | Type | Description |
|---|---|---|
provider | Literal['hmac', 's3', 'gcs', 'azure', 'oci'] | URL signing scheme ( |
bucket | str | Target bucket name embedded in S3 SigV4, GCS V4, or OCI PAR presigned URLs. |
namespace | str | OCI Object Storage tenancy namespace used when |
region | str | Region identifier used in S3 SigV4 credential scopes or OCI PAR origins. |
access_key_id | str | Access key ID or GCS HMAC key ID used to sign presigned requests. |
secret_access_key | str | Secret access key used to derive the S3 SigV4 or GCS signing key. |
hmac_secret | str | Shared secret key used when |
service_account_email | str | Google Cloud service account email used for GCS V4 signing. |
target_service_account | str | None | Optional target service account email for keyless IAM |
private_key_pem | str | None | Optional PEM-encoded RSA private key for local zero-network GCS V4 signing. |
verify_key_pem | str | None | Optional PEM-encoded RSA public key for offline GCS V4 signature verification. |
iam_endpoint | str | Google Cloud IAM Credentials API base URL used for keyless GCS V4 signing. |
access_token | str | None | Optional OAuth2 bearer token authenticating keyless IAM |
account | str | Azure Storage account name used when |
container | str | Azure Blob container name used when |
azure_access_key | str | Base64-encoded Azure Storage shared key used when |
par_token | str | None | Optional OCI Pre-Authenticated Request token used when |
par_url_prefix | str | None | Optional full OCI Pre-Authenticated Request URL prefix ending in |
endpoint | str | None | Optional custom origin URL overriding the default cloud storage hostname. |
virtual_hosted_style | bool | When True, S3 SigV4 presigned URLs address the bucket as a host subdomain ( |
GCS token caches¶
vertebra.storage re-exports OAuth bearer token caches (SyncGcpTokenCache, AsyncGcpTokenCache, GcpTokenSnapshot) and audience-bound OIDC ID token caches (SyncGcpIdTokenCache, AsyncGcpIdTokenCache, GcpIdTokenSnapshot) from vertebra._vertebra. It also provides SyncGcsBearerSecretProvider and AsyncGcsBearerSecretProvider for DuckDB GCS bearer-token rotation. Passing one cache via token_cache= or id_token_cache= shares a single token and refresh schedule across multiple stores, secret providers, or embedders. Call get_token() to fetch a snapshot, or to_async() and to_sync() to switch between handles sharing the same Rust cache. See the authentication guide for construction, ADC discovery order, and sharing.
SyncGcsBearerSecretProvider
¶
Callable synchronous DuckDB GCS secret provider backed by SyncGcpTokenCache.
Attributes:
| Name | Type | Description |
|---|---|---|
generation | int | Return the current credential generation tracked by the token cache. |
token_cache | SyncGcpTokenCache | Return the underlying |
AsyncGcsBearerSecretProvider
¶
Callable asynchronous DuckDB GCS secret provider backed by AsyncGcpTokenCache.
Attributes:
| Name | Type | Description |
|---|---|---|
generation | int | Return the current credential generation tracked by the token cache. |
token_cache | AsyncGcpTokenCache | Return the underlying |
HTTP Range responses¶
parse_byte_range(range_header, total_size) resolves one Range header into a ByteRange(start, end_exclusive, total_size), whose content_length and content_range_header properties feed the response headers. It returns None when the header is missing or uses a unit other than bytes, and raises RangeNotSatisfiableError (a ValueError carrying total_size) for malformed or unsatisfiable ranges.
StreamingStorageResponse
¶
Zero-copy chunked HTTP response descriptor backed by ObjectStore.
Attributes:
| Name | Type | Description |
|---|---|---|
store | SyncObjectStore | AsyncObjectStore | None | Underlying object store instance holding the target object. |
key | str | Object key path within |
total_size | int | Total byte length of the stored object. |
chunk_size | int | Maximum byte length yielded per chunk iteration. |
media_type | str | HTTP |
status_code | int | HTTP status code returned with the streamed response. |
headers | dict[str, str] | Additional HTTP response headers attached to the stream. |
content_type | str | None | Optional explicit HTTP |
etag | str | None | Optional HTTP |
content_range | str | None | Optional HTTP |
range_start | int | None | Optional zero-based inclusive start byte offset for range slicing. |
range_end | int | None | Optional zero-based inclusive end byte offset for range slicing. |
signed_url | str | None | Optional presigned object URL for redirect or header forwarding. |
data | bytes | None | Optional pre-loaded object bytes when streaming without a backing store. |
Errors¶
IntegrityError
¶
Bases: VertebraError, OSError
Raised when an object storage content receipt or verified read mismatches an expected digest.
PreconditionError
¶
Bases: VertebraError, OSError
Raised when a conditional storage or resource precondition fails.