Skip to content

Typing & Schema Aliases

from sqlspec.typing import (
    UNSET,
    ArrowReturnFormat,
    ConnectionT,
    DataclassProtocol,
    DictLike,
    Empty,
    EmptyType,
    PoolT,
    SchemaT,
    StatementParameters,
    SupportedSchemaModel,
    UnsetType,
    get_type_adapter,
)

Public type variables, schema model union aliases, Apache Arrow return format literals, and sentinel types exported by sqlspec.typing. See Schema Mapping for usage examples.

Core Type Variables & Aliases

ConnectionT

ConnectionT = TypeVar('ConnectionT')

Type variable for connection types.

:class:~sqlspec.typing.ConnectionT

PoolT

PoolT = TypeVar('PoolT')

Type variable for pool types.

:class:~sqlspec.typing.PoolT

SchemaT

SchemaT = TypeVar('SchemaT', default=dict[str, Any])

Type variable for schema types (models, TypedDict, dataclasses, etc.).

Unbounded TypeVar for use with schema_type parameter in driver methods. Supports all schema types including TypedDict which cannot be bounded to a class hierarchy.

SupportedSchemaModel

SupportedSchemaModel = (
    DictLike
    | StructStub
    | BaseModelStub
    | DataclassProtocol
    | AttrsInstanceStub
    | Mapping[str, Any]
)

Type alias for pydantic or msgspec models.

:class:msgspec.Struct | :class:pydantic.BaseModel | :class:DataclassProtocol | :class:AttrsInstance

StatementParameters

StatementParameters = (
    "dict[str, object] | list[object] | tuple[object, ...] | object | None"
)

Type alias for statement parameters.

Represents
  • :type:dict[str, object]
  • :type:list[object]
  • :type:tuple[object, ...]
  • :type:object
  • :type:None

ArrowReturnFormat

ArrowReturnFormat = Literal['table', 'reader', 'batch', 'batches']

Type alias for Apache Arrow return format options.

Represents
  • :literal:"table" - Return PyArrow Table
  • :literal:"reader" - Return PyArrow RecordBatchReader
  • :literal:"batch" - Return single PyArrow RecordBatch
  • :literal:"batches" - Return list of PyArrow RecordBatches

Schema Protocols & Adapter Helpers

DictLike

Bases: Protocol

A protocol for objects that behave like a dictionary for reading.

DataclassProtocol

Bases: Protocol

Protocol for instance checking dataclasses.

get_type_adapter

get_type_adapter(f)

Caches and returns a pydantic type adapter.

Parameters:

Name Type Description Default
f type[T]

Type to create a type adapter for.

required

Returns:

Type Description
Any

class:pydantic.TypeAdapter[:class:typing.TypeVar[T]]

Sentinel Types & Optional Dependency Flags

UnsetType

UnsetType = _RealUnsetType

EmptyEnum

Bases: Enum

A sentinel enum used as placeholder.

EMPTY
EMPTY = 0
Constant Description
UNSET Singleton sentinel indicating an omitted optional parameter.
Empty Legacy sentinel alias for omitted parameters.
MSGSPEC_INSTALLED True when msgspec is available at runtime.
PYDANTIC_INSTALLED True when pydantic is available at runtime.
ATTRS_INSTALLED True when attrs is available at runtime.
CATTRS_INSTALLED True when cattrs is available at runtime.
PYARROW_INSTALLED True when pyarrow is available at runtime.
POLARS_INSTALLED True when polars is available at runtime.
PANDAS_INSTALLED True when pandas is available at runtime.
NUMPY_INSTALLED True when numpy is available at runtime.
LITESTAR_INSTALLED True when litestar is available at runtime.
OPENTELEMETRY_INSTALLED True when opentelemetry-api is available at runtime.
PROMETHEUS_INSTALLED True when prometheus-client is available at runtime.
FSSPEC_INSTALLED True when fsspec is available at runtime.
OBSTORE_INSTALLED True when obstore is available at runtime.