Skip to content

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

get(path, *, expected_sha256=None)

Read full object bytes for the given key.

get_view

get_view(path)

Return a zero-copy memoryview over the object payload.

get_stream

get_stream(path, *, chunk_size=None, expected_sha256=None)

Stream object payload chunks as zero-copy StorageBuffer instances.

head

head(path)

Return object metadata without transferring the full payload.

exists

exists(path)

Return True if the object key exists.

delete

delete(path)

Delete the object at the given key.

list

list(prefix='')

List objects matching prefix.

open_reader

open_reader(
    path,
    *,
    size=None,
    chunk_size=65536,
    read_ahead=4194304,
    expected_sha256=None,
)

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_arrow(key, data, *, batch_size=65536, options=None)

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

iter_arrow_batches(key, *, batch_size=65536, options=None)

Yield Arrow IPC RecordBatch objects through native streaming reads.

options keys such as use_threads build pyarrow.ipc.IpcReadOptions.

iter_parquet_batches

iter_parquet_batches(key, *, batch_size=65536, columns=None, options=None)

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

sign(key, *, expires_in=3600, method='GET', timestamp=None)

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
bucketstr

Target S3 bucket name.

regionstr

AWS region used for SigV4 request signing and endpoint resolution.

endpointstr | None

Optional custom S3-compatible endpoint URL (e.g. MinIO, LocalStack, or Ceph RGW).

access_key_idstr | None

Optional AWS IAM access key ID.

secret_access_keystr | None

Optional AWS IAM secret access key.

session_tokenstr | None

Optional AWS STS temporary session token.

virtual_hosted_stylebool

When True, address buckets using virtual-hosted-style URLs (<bucket>.s3.<region>.amazonaws.com).

allow_httpbool

When True, permit unencrypted http:// endpoints for local emulators.

GCSConfig

Configuration for Google Cloud Storage with Application Default Credentials (ADC) support.

Attributes:

Name Type Description
bucketstr

Target Google Cloud Storage bucket name.

service_account_pathstr | None

Optional filesystem path to a Google Cloud service account JSON key file.

service_account_keystr | None

Optional inline JSON string containing a Google Cloud service account key.

application_credentialsstr | None

Optional path to an Application Default Credentials JSON file (authorized_user, external_account, or service_account).

service_account_emailstr | None

Optional service account email used for IAM signBlob V4 URL signing.

target_service_accountstr | None

Optional target service account email for keyless IAM impersonation (generateAccessToken / signBlob).

iam_endpointstr

Base URL for the Google Cloud IAM Credentials REST API.

access_tokenstr | None

Optional OAuth2 bearer access token used for GCS REST and IAM signBlob calls.

endpointstr | None

Optional custom GCS endpoint URL (or automatically resolved from STORAGE_EMULATOR_HOST).

allow_httpbool

When True, permit unencrypted http:// endpoints for local emulators.

skip_signaturebool

When True, send unsigned requests against anonymous buckets or local emulators.

refresh_skew_secondsint

Proactive OAuth2 token refresh skew window in seconds before expiration.

quota_project_idstr | None

Optional Google Cloud quota project ID forwarded as x-goog-user-project.

AzureConfig

Configuration for Azure Blob Storage and ADLS Gen2.

Attributes:

Name Type Description
containerstr

Target Azure Blob Storage container or ADLS Gen2 filesystem name.

accountstr

Azure Storage account name.

access_keystr | None

Optional Base64-encoded Azure Storage account shared key.

sas_tokenstr | None

Optional pre-generated Shared Access Signature (SAS) query string.

tenant_idstr | None

Optional Microsoft Entra ID (Azure AD) tenant ID for service principal auth.

client_idstr | None

Optional Microsoft Entra ID application (client) ID.

client_secretstr | None

Optional Microsoft Entra ID client secret.

endpointstr | None

Optional custom Azure Blob endpoint URL.

use_emulatorbool

When True, connect to the local Azurite emulator endpoint.

R2Config

Configuration for Cloudflare R2 object storage.

Attributes:

Name Type Description
bucketstr

Target Cloudflare R2 bucket name.

account_idstr

Cloudflare 32-character hexadecimal account identifier.

access_key_idstr | None

Optional R2 S3-compatible API token access key ID.

secret_access_keystr | None

Optional R2 S3-compatible API token secret access key.

jurisdictionLiteral['eu', 'fedramp'] | str | None

Optional R2 data-locality jurisdiction subdomain ("eu" or "fedramp").

custom_domainstr | None

Optional public custom domain bound to the R2 bucket.

endpointstr | None

Optional explicit R2 endpoint URL override.

allow_httpbool

When True, permit unencrypted http:// connections for local testing.

OCIConfig

Configuration for native Oracle Cloud Infrastructure (OCI) Object Storage REST v2.

Attributes:

Name Type Description
bucketstr

Target OCI Object Storage bucket name.

namespacestr

OCI Object Storage tenancy namespace string.

regionstr

OCI region identifier (e.g. "us-ashburn-1" or "us-phoenix-1").

tenancy_ocidstr | None

OCID of the Oracle Cloud tenancy (ocid1.tenancy.oc1..).

user_ocidstr | None

OCID of the IAM user signing API requests (ocid1.user.oc1..).

fingerprintstr | None

MD5 fingerprint of the RSA API signing public key.

private_key_pemstr | None

Inline PEM-encoded RSA private key used for draft-cavage-http-signatures-08 signing.

private_key_pathstr | Path | None

Filesystem path to a PEM-encoded RSA private key file.

par_tokenstr | None

Optional OCI Pre-Authenticated Request (PAR) token for bucket-scoped URL signing.

par_url_prefixstr | None

Optional full OCI Pre-Authenticated Request base URL prefix ending in /o/.

endpointstr | None

Optional custom OCI Object Storage REST v2 endpoint URL.

LocalConfig

Configuration for local filesystem object storage.

Attributes:

Name Type Description
rootstr | Path

Root directory on the local filesystem under which object keys are resolved.

create_dirsbool

When True, automatically create root and parent directories on initialization and writes.

MemoryConfig

Configuration for in-memory object storage.

Attributes:

Name Type Description
namespacestr

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
urlstr

Base http:// or https:// origin URL for the HTTP/WebDAV store.

headersdict[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
sizeint

Return total object byte size.

AsyncReadableFile

Bases: _ReadableFileMixin

Seekable asynchronous read-only stream backed by AsyncObjectStore range and stream reads.

Attributes:

Name Type Description
sizeint | 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
pathstr

Normalized /-delimited object key within the bucket or root.

sizeint

Object payload size in bytes.

last_modifiedstr

RFC 3339 / ISO-8601 UTC timestamp of the object's last modification.

etagstr | None

Optional content entity tag (ETag) returned by the storage backend.

versionstr | None

Optional backend object version identifier.

content_typestr | None

Optional MIME content type (Content-Type) associated with the object.

attributesdict[str, str]

User-defined string metadata attributes persisted with the object.

sha256str | None

Optional lowercase hexadecimal SHA-256 content digest receipt.

crc32cstr | None

Optional lowercase hexadecimal Castagnoli CRC32C content digest receipt.

md5str | 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
providerLiteral['hmac', 's3', 'gcs', 'azure', 'oci']

URL signing scheme ("hmac", "s3", "gcs", "azure", or "oci").

bucketstr

Target bucket name embedded in S3 SigV4, GCS V4, or OCI PAR presigned URLs.

namespacestr

OCI Object Storage tenancy namespace used when provider="oci".

regionstr

Region identifier used in S3 SigV4 credential scopes or OCI PAR origins.

access_key_idstr

Access key ID or GCS HMAC key ID used to sign presigned requests.

secret_access_keystr

Secret access key used to derive the S3 SigV4 or GCS signing key.

hmac_secretstr

Shared secret key used when provider="hmac".

service_account_emailstr

Google Cloud service account email used for GCS V4 signing.

target_service_accountstr | None

Optional target service account email for keyless IAM signBlob impersonation.

private_key_pemstr | None

Optional PEM-encoded RSA private key for local zero-network GCS V4 signing.

verify_key_pemstr | None

Optional PEM-encoded RSA public key for offline GCS V4 signature verification.

iam_endpointstr

Google Cloud IAM Credentials API base URL used for keyless GCS V4 signing.

access_tokenstr | None

Optional OAuth2 bearer token authenticating keyless IAM signBlob calls.

accountstr

Azure Storage account name used when provider="azure".

containerstr

Azure Blob container name used when provider="azure".

azure_access_keystr

Base64-encoded Azure Storage shared key used when provider="azure".

par_tokenstr | None

Optional OCI Pre-Authenticated Request token used when provider="oci".

par_url_prefixstr | None

Optional full OCI Pre-Authenticated Request URL prefix ending in /o/.

endpointstr | None

Optional custom origin URL overriding the default cloud storage hostname.

virtual_hosted_stylebool

When True, S3 SigV4 presigned URLs address the bucket as a host subdomain (<bucket>.<endpoint host>).

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
generationint

Return the current credential generation tracked by the token cache.

token_cacheSyncGcpTokenCache

Return the underlying SyncGcpTokenCache instance.

AsyncGcsBearerSecretProvider

Callable asynchronous DuckDB GCS secret provider backed by AsyncGcpTokenCache.

Attributes:

Name Type Description
generationint

Return the current credential generation tracked by the token cache.

token_cacheAsyncGcpTokenCache

Return the underlying AsyncGcpTokenCache instance.

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
storeSyncObjectStore | AsyncObjectStore | None

Underlying object store instance holding the target object.

keystr

Object key path within store.

total_sizeint

Total byte length of the stored object.

chunk_sizeint

Maximum byte length yielded per chunk iteration.

media_typestr

HTTP Content-Type media type header for the streamed response.

status_codeint

HTTP status code returned with the streamed response.

headersdict[str, str]

Additional HTTP response headers attached to the stream.

content_typestr | None

Optional explicit HTTP Content-Type override for the streamed object.

etagstr | None

Optional HTTP ETag header value for the stored object.

content_rangestr | None

Optional HTTP Content-Range header value for byte-range responses.

range_startint | None

Optional zero-based inclusive start byte offset for range slicing.

range_endint | None

Optional zero-based inclusive end byte offset for range slicing.

signed_urlstr | None

Optional presigned object URL for redirect or header forwarding.

databytes | 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.