sqlatypemodel.util package

Submodules

sqlatypemodel.util.attrs module

Wrapper for attrs models.

This module provides a wrapper around attrs.define that ensures compatibility with MutableMixin by enforcing safe defaults.

sqlatypemodel.util.attrs.define(cls: type[T]) type[T][source]
sqlatypemodel.util.attrs.define(*args: Any, **kwargs: Any) Callable[[type[T]], type[T]]

Define an attrs class with safe defaults for mutation tracking.

This wrapper enforces:

  • eq=False: Uses identity equality (is) instead of value equality. This ensures correct behavior with WeakKeyDictionary and prevents recursion loops.

  • slots=False: Allows MutableMixin to inject tracking attributes (like _parents) at runtime.

Parameters:
  • *args – Positional arguments passed to attrs.define.

  • **kwargs – Keyword arguments passed to attrs.define.

Returns:

The decorated class.

sqlatypemodel.util.constants module

Static constants and configuration for the library.

sqlatypemodel.util.dataclasses module

Safe wrapper for Python dataclasses.

This module provides a wrapper around dataclasses.dataclass that ensures compatibility with MutableMixin by enforcing safe defaults.

sqlatypemodel.util.dataclasses.dataclass(cls: type[T]) type[T][source]
sqlatypemodel.util.dataclasses.dataclass(*args: Any, **kwargs: Any) Callable[[type[T]], type[T]]

Create a dataclass with safe defaults for mutation tracking.

This wrapper enforces:

  • eq=False: Uses identity equality (is) instead of value equality. This prevents recursion loops during initialization and ensures correct behavior with WeakKeyDictionary.

  • slots=False: Allows MutableMixin to inject tracking attributes (like _parents) at runtime.

Parameters:
  • *args – Positional arguments passed to dataclasses.dataclass.

  • **kwargs – Keyword arguments passed to dataclasses.dataclass.

Returns:

The decorated class.

sqlatypemodel.util.json module

JSON serialization utilities with orjson support and automatic fallback.

This module provides optimized JSON serialization and deserialization functions. It prefers orjson for performance but gracefully falls back to the standard json library when orjson is unavailable or encounters unsupported types (e.g., integers larger than 64-bit).

sqlatypemodel.util.json.get_serializers(use_orjson: bool = True) tuple[Callable[[Any], str], Callable[[str | bytes], Any]][source]

Get the most robust JSON serialization/deserialization pair available.

Selects the best available serializers based on configuration and library availability.

Parameters:

use_orjson – If True, attempts to use orjson with fallback to json. If False (or orjson is missing), uses strict standard json.

Returns:

A tuple of (dumps_function, loads_function).

sqlatypemodel.util.sqlalchemy module

SQLAlchemy engine creation helpers with optimized JSON serializers.

This module provides wrappers around sqlalchemy.create_engine and sqlalchemy.ext.asyncio.create_async_engine that automatically configure orjson (if available) as the default JSON serializer and deserializer.

sqlatypemodel.util.sqlalchemy.create_async_engine(*args: Any, **kwargs: Any) AsyncEngine[source]

Create an asynchronous SQLAlchemy engine with optimized JSON serializers.

This function wraps sqlalchemy.ext.asyncio.create_async_engine and injects orjson (via get_serializers) into json_serializer and json_deserializer arguments if they are not already provided.

Parameters:
  • *args – Positional arguments passed to sqlalchemy.create_async_engine.

  • **kwargs – Keyword arguments passed to sqlalchemy.create_async_engine.

Returns:

An instance of sqlalchemy.ext.asyncio.AsyncEngine.

sqlatypemodel.util.sqlalchemy.create_engine(*args: Any, **kwargs: Any) Engine[source]

Create a synchronous SQLAlchemy engine with optimized JSON serializers.

This function wraps sqlalchemy.create_engine and injects orjson (via get_serializers) into json_serializer and json_deserializer arguments if they are not already provided.

Parameters:
  • *args – Positional arguments passed to sqlalchemy.create_engine.

  • **kwargs – Keyword arguments passed to sqlalchemy.create_engine.

Returns:

An instance of sqlalchemy.Engine.

Module contents

Utility functions and helpers for sqlatypemodel.

Contains helpers for: - JSON serialization (orjson integration) - Constants and sentinel values - Dataclass wrapping - Attrs support - SQLAlchemy engine setup