base

Base model classes for SQLAlchemy ORM with common patterns and functionality.

Common base classes for SQLAlchemy declarative models.

UUID Primary Key Models

class advanced_alchemy.base.UUIDBase[source]

Bases: UUIDPrimaryKey, CommonTableAttributes, AdvancedDeclarativeBase, AsyncAttrs

Base for all SQLAlchemy declarative models with UUID v4 primary keys.

See also

CommonTableAttributes advanced_alchemy.mixins.UUIDPrimaryKey AdvancedDeclarativeBase AsyncAttrs

Base model with UUID primary key (UUID v4).

class advanced_alchemy.base.UUIDAuditBase[source]

Bases: CommonTableAttributes, UUIDPrimaryKey, AuditColumns, AdvancedDeclarativeBase, AsyncAttrs

Base for declarative models with UUID v4 primary keys and audit columns.

See also

CommonTableAttributes advanced_alchemy.mixins.UUIDPrimaryKey advanced_alchemy.mixins.AuditColumns AdvancedDeclarativeBase AsyncAttrs

Base model with UUID primary key and audit columns (created_at, updated_at).

class advanced_alchemy.base.UUIDv6Base[source]

Bases: UUIDv6PrimaryKey, CommonTableAttributes, AdvancedDeclarativeBase, AsyncAttrs

Base for all SQLAlchemy declarative models with UUID v6 primary keys.

See also

advanced_alchemy.mixins.UUIDv6PrimaryKey CommonTableAttributes AdvancedDeclarativeBase AsyncAttrs

Base model with UUID v6 primary key (time-ordered).

class advanced_alchemy.base.UUIDv7Base[source]

Bases: UUIDv7PrimaryKey, CommonTableAttributes, AdvancedDeclarativeBase, AsyncAttrs

Base for all SQLAlchemy declarative models with UUID v7 primary keys.

See also

advanced_alchemy.mixins.UUIDv7PrimaryKey CommonTableAttributes AdvancedDeclarativeBase AsyncAttrs

Base model with UUID v7 primary key (time-ordered, improved sorting).

BigInt Primary Key Models

class advanced_alchemy.base.BigIntBase[source]

Bases: BigIntPrimaryKey, CommonTableAttributes, AdvancedDeclarativeBase, AsyncAttrs

Base for all SQLAlchemy declarative models with BigInt primary keys.

See also

advanced_alchemy.mixins.BigIntPrimaryKey CommonTableAttributes AdvancedDeclarativeBase AsyncAttrs

Base model with BigInt auto-incrementing primary key.

class advanced_alchemy.base.BigIntAuditBase[source]

Bases: CommonTableAttributes, BigIntPrimaryKey, AuditColumns, AdvancedDeclarativeBase, AsyncAttrs

Base for declarative models with BigInt primary keys and audit columns.

See also

CommonTableAttributes advanced_alchemy.mixins.BigIntPrimaryKey advanced_alchemy.mixins.AuditColumns AdvancedDeclarativeBase AsyncAttrs

Base model with BigInt primary key and audit columns (created_at, updated_at).

NanoID Primary Key Models

class advanced_alchemy.base.NanoIDBase[source]

Bases: NanoIDPrimaryKey, CommonTableAttributes, AdvancedDeclarativeBase, AsyncAttrs

Base for all SQLAlchemy declarative models with Nano ID primary keys.

See also

advanced_alchemy.mixins.NanoIDPrimaryKey CommonTableAttributes AdvancedDeclarativeBase AsyncAttrs

Base model with NanoID primary key (requires nanoid extra).

Declarative Base

class advanced_alchemy.base.AdvancedDeclarativeBase[source]

Bases: DeclarativeBase

A subclass of declarative base that allows for overriding of the registry.

Inherits from sqlalchemy.orm.DeclarativeBase.

registry

The registry for the declarative base.

Type:

sqlalchemy.orm.registry

__metadata_registry__

The metadata registry.

Type:

MetadataRegistry

__bind_key__

The bind key for the metadata.

Type:

Optional[str]

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

Parameters:
Return type:

None

metadata: ClassVar[MetaData] = MetaData()

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

Enhanced declarative base with additional functionality.

class advanced_alchemy.base.CommonTableAttributes[source]

Bases: BasicAttributes

Common attributes for SQLAlchemy tables.

Inherits from BasicAttributes and provides a mechanism to infer table names from class names.

__tablename__

The inferred table name.

Type:

str

Common attributes mixed into all base models.

class advanced_alchemy.base.BasicAttributes[source]

Bases: object

Basic attributes for SQLAlchemy tables and queries.

Provides a method to convert the model to a dictionary representation.

to_dict()[source]

Converts the model to a dictionary, excluding specified fields. :no-index:

Basic attributes for models (id, to_dict).