Python SDK

Mesh Storage

API Reference

Public alloy.storage and alloy.sql methods, result objects, environment variables, and errors

This page is a compact reference for the Python SDK surface used with Mesh Storage.

Install

pip install alloy-sdk

The SDK needs Python 3.12 (>=3.12,<3.13).

Environment variables

VariableUsed byDescription
ALLOY_API_KEYalloy.storage, alloy.sqlAlloy API key for your org
ALLOY_DATA_URLalloy.storage, alloy.sqlAlloy data API URL, for example https://data.usealloy.ai

Explicit base_url= and api_key= values override environment defaults.

alloy.storage

Import:

from alloy import storage

Connect

storage.connect(
    *,
    base_url: str | None = None,
    api_key: str | None = None,
    headers=None,
    timeout: float = 120.0,
)

Returns a sync storage.Client.

storage.async_connect(
    *,
    base_url: str | None = None,
    api_key: str | None = None,
    headers=None,
    timeout: float = 120.0,
)

Returns an async storage.AsyncClient.

Both clients are context managers and close SDK-owned HTTP sessions.

Client methods

client.upload_file(
    local_path,
    *,
    path: str | None = None,
    ttl_seconds: int | None = None,
    overwrite: Literal[False] = False,
) -> storage.UploadResult

Uploads one .mcap, .json, .yml, or .yaml file into a Mesh Storage path. overwrite=True raises NotImplementedError.

client.upload_folder(
    local_folder,
    *,
    path: str | None = None,
    ttl_seconds: int | None = None,
    overwrite: Literal[False] = False,
) -> storage.UploadResult

Uploads every file below a folder, preserving relative paths. Sidecars upload before MCAPs. Every file must be .mcap, .json, .yml, or .yaml. One unsupported file stops the whole upload with AlloyStorageTransferError before any file uploads.

client.list_files(
    prefix: str | None = None,
    *,
    path: str | None = None,
    recursive: bool = False,
    max_keys: int = 100,
    continuation_token: str | None = None,
    ttl_seconds: int | None = None,
) -> storage.StorageListResult

Lists objects below either an SDK upload path or a raw Mesh prefix.

client.download_file(
    key: str,
    destination,
    *,
    ttl_seconds: int | None = None,
) -> None

Downloads one Mesh object by exact key.

storage.AsyncClient exposes the same methods with await.

One-shot helpers

storage.upload_file(...)
storage.upload_folder(...)
storage.list_files(...)
storage.download_file(...)
await storage.async_upload_file(...)
await storage.async_upload_folder(...)
await storage.async_list_files(...)
await storage.async_download_file(...)

One-shot helpers open a client, run one operation, and close the client.

Storage result objects

ObjectFields
StorageFilekey, size, last_modified, etag
StorageListResultfiles, directories, next_token, prefix
PlannedUploadlocal_path, relative_path, key, size
UploadResultfiles, total_bytes, path, prefix

alloy.sql

Import:

from alloy import sql

Connect

sql.connect(
    *,
    base_url: str | None = None,
    api_key: str | None = None,
    headers=None,
    timeout: float = 120.0,
)
sql.async_connect(
    *,
    base_url: str | None = None,
    api_key: str | None = None,
    headers=None,
    timeout: float = 120.0,
)

Query methods

MethodReturnsUse for
fetch(sql, *, params=None, timeout=None, max_rows=None)list[dict[str, Any]]small row results
fetchrow(sql, *, params=None, timeout=None)dict[str, Any] | Noneone row
fetchval(sql, *, params=None, timeout=None)first valuescalar queries
fetch_rows(sql, *, params=None, timeout=None, max_rows=None)RowSetrows plus schema/cap metadata
query(sql, *, params=None, timeout=None)QueryResultArrow-backed result object
query_arrow(sql, *, params=None, timeout=None)pyarrow.TableArrow handoff
query_pandas(sql, *, params=None, timeout=None)pandas DataFramenotebook analysis
query_polars(sql, *, params=None, timeout=None)Polars DataFramePolars analysis
query_df(sql, *, params=None, timeout=None)pandas DataFramealias for pandas
stream(sql, *, params=None, timeout=None)QueryStreamArrow batch streaming
query_batches(sql, *, params=None, timeout=None)QueryStreamalias for stream

params, timeout, and max_rows are keyword-only. timeout is in seconds and defaults to the client timeout.

Async clients expose the same method names. Await eager methods; use async with for streams.

SQL result objects

ObjectUseful members
RowSetcolumns, rows, row_count, truncated, named_rows(), to_csv()
AsyncRowSetcolumns, rows, row_count, truncated, await named_rows(), await to_csv()
QueryResultcolumn_names, column_types, row_count, to_arrow(), to_pandas(), to_polars(), to_duckdb()
AsyncQueryResultasync equivalents for expensive conversions
QueryStreamcontext-managed Arrow batch stream
AsyncQueryStreamasync context-managed Arrow batch stream

Errors

Storage errors:

ErrorMeaning
AlloyStorageErrorBase storage SDK error
AlloyStorageHttpErrorThe storage API returned a non-2xx response, for example 402 storage_limit_reached. Has status_code and body
AlloyStorageResponseErrorThe storage API returned an unexpected response shape
AlloyStorageTransferErrorLocal planning failed (missing source, unsupported file type, key over 1024 bytes) or the pre-upload conflict check failed
AlloyStorageConflictErroroverwrite=False found an existing target key
AlloyStorageDependencyErrorRequired transfer dependency is unavailable

Network errors and errors during the file transfer itself (upload, list, or download) come straight from the underlying HTTP and storage client libraries. The SDK does not wrap them in AlloyStorageError.

SQL errors:

ErrorMeaning
AlloySqlErrorBase hosted SQL SDK error
AlloySqlHttpErrorHosted SQL returned a non-2xx response. Has status_code and body
AlloySqlResponseErrorHosted SQL response had an unexpected shape
AlloySqlTransportErrorThe HTTP request failed, or the Arrow stream ended early. Subclass of AlloySqlResponseError
AlloySqlDecodeErrorArrow IPC decoding failed
AlloySqlDependencyErrorPolars or DuckDB is not installed. A missing pandas raises a plain ImportError

Version notes

Storage helpers, async transfers, and hosted SQL are available in the current alloy-sdk package. Upgrade before using this reference:

pip install --upgrade alloy-sdk

On this page