Protocols#
Protocol definitions and runtime-checkable interfaces used across SQLSpec's core, drivers, builder, and data dictionary.
Statement and Query Protocols#
- class sqlspec.protocols.StatementProtocol[source]#
Bases:
ProtocolProtocol for statement attribute access.
- __init__(*args, **kwargs)#
- class sqlspec.protocols.SQLBuilderProtocol[source]#
Bases:
ProtocolProtocol for SQL query builders.
- create_placeholder(value, base_name)[source]#
Create placeholder expression with bound parameter (public).
- generate_unique_parameter_name(base_name)[source]#
Generate a unique parameter name exposed via public API.
- Return type:
- build_static_expression(expression=None, parameters=None, *, cache_key=None, expression_factory=None, copy=True, optimize_expression=None, dialect=None)[source]#
Compile a pre-built expression with optional caching and parameters.
- Return type:
- __init__(*args, **kwargs)#
- class sqlspec.protocols.QueryResultProtocol[source]#
Bases:
ProtocolProtocol for query execution results.
- __init__(*args, **kwargs)#
- class sqlspec.protocols.PipelineCapableProtocol[source]#
Bases:
ProtocolProtocol for connections supporting pipeline execution.
- __init__(*args, **kwargs)#
- class sqlspec.protocols.SupportsArrowResults[source]#
Bases:
ProtocolProtocol for adapters that support Arrow result format.
Adapters implementing this protocol can return query results in Apache Arrow format via the select_to_arrow() method, enabling zero-copy data transfer and efficient integration with data science tools.
- select_to_arrow(statement, /, *parameters, statement_config=None, return_format='table', native_only=False, batch_size=None, arrow_schema=None, **kwargs)[source]#
Execute query and return results as Apache Arrow Table or RecordBatch.
- Parameters:
statement_config¶ (
Any|None) -- Optional statement configuration override.return_format¶ (
str) -- Output format - "table", "reader", or "batches".native_only¶ (
bool) -- If True, raise error when native Arrow path unavailable.arrow_schema¶ (
Any|None) -- Optional target Arrow schema for type casting.
- Return type:
- Returns:
ArrowResult containing Arrow data.
- __init__(*args, **kwargs)#
Data Dictionary Protocols#
Storage and Driver Protocols#
- class sqlspec.protocols.ObjectStoreProtocol[source]#
Bases:
ProtocolProtocol for object storage operations.
All synchronous methods use the *_sync suffix for consistency with async methods.
- write_bytes_sync(path, data, **kwargs)[source]#
Write bytes to an object synchronously.
- Return type:
- read_text_sync(path, encoding='utf-8', **kwargs)[source]#
Read text from an object synchronously.
- Return type:
- write_text_sync(path, data, encoding='utf-8', **kwargs)[source]#
Write text to an object synchronously.
- Return type:
- list_objects_sync(prefix='', recursive=True, **kwargs)[source]#
List objects with optional prefix synchronously.
- is_path_sync(path)[source]#
Check if path points to a prefix (directory-like) synchronously.
- Return type:
- read_arrow_sync(path, **kwargs)[source]#
Read an Arrow table from storage synchronously.
- Return type:
- write_arrow_sync(path, table, **kwargs)[source]#
Write an Arrow table to storage synchronously.
- Return type:
- stream_arrow_sync(pattern, *, file_format='parquet', batch_size=65536, **kwargs)[source]#
Stream Arrow record batches from matching objects synchronously.
- Return type:
- stream_read_sync(path, chunk_size=None, **kwargs)[source]#
Stream bytes from an object synchronously.
- async read_text_async(path, encoding='utf-8', **kwargs)[source]#
Async read text from an object.
- Return type:
- async write_text_async(path, data, encoding='utf-8', **kwargs)[source]#
Async write text to an object.
- Return type:
- async stream_read_async(path, chunk_size=None, **kwargs)[source]#
Stream bytes from an object asynchronously.
- Return type:
- async list_objects_async(prefix='', recursive=True, **kwargs)[source]#
Async list objects with optional prefix.
- async read_arrow_async(path, **kwargs)[source]#
Async read an Arrow table from storage.
- Return type:
- async write_arrow_async(path, table, **kwargs)[source]#
Async write an Arrow table to storage.
- Return type:
- stream_arrow_async(pattern, *, file_format='parquet', batch_size=65536, **kwargs)[source]#
Stream Arrow record batches from matching objects.
- Return type:
- property supports_signing: bool#
Whether this backend supports URL signing.
- Returns:
True if the backend supports generating signed URLs, False otherwise. Only S3, GCS, and Azure backends via obstore support signing.
- sign_sync(paths, expires_in=3600, for_upload=False)[source]#
Generate signed URL(s) for object(s).
- Overloads:
self, paths (str), expires_in (int), for_upload (bool) → str
self, paths (list[str]), expires_in (int), for_upload (bool) → list[str]
- Parameters:
- Returns:
Single signed URL string if paths is a string, or list of signed URLs if paths is a list. Preserves input type for convenience.
- Raises:
NotImplementedError -- If the backend does not support URL signing.
- async sign_async(paths, expires_in=3600, for_upload=False)[source]#
Generate signed URL(s) asynchronously.
- Overloads:
self, paths (str), expires_in (int), for_upload (bool) → str
self, paths (list[str]), expires_in (int), for_upload (bool) → list[str]
- Parameters:
- Returns:
Single signed URL string if paths is a string, or list of signed URLs if paths is a list. Preserves input type for convenience.
- Raises:
NotImplementedError -- If the backend does not support URL signing.
- class sqlspec.protocols.SupportsCloseProtocol[source]#
Bases:
ProtocolProtocol for objects exposing close().
- __init__(*args, **kwargs)#
- class sqlspec.protocols.NotificationProtocol[source]#
Bases:
ProtocolProtocol for database event notifications.
- __init__(*args, **kwargs)#
- class sqlspec.protocols.MappingLikeProtocol[source]#
Bases:
ProtocolProtocol for objects that can be converted to dict via dict() constructor.
This matches database row types like sqlite3.Row, asyncpg.Record, psycopg.Row that support dictionary-like access with keys() method.
- __init__(*args, **kwargs)#