base

Application ORM configuration.

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]

registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

__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.

metadata: ClassVar[MetaData] = MetaData()

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

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:

to_dict(exclude=None)[source]

Convert model to dictionary.

Returns:

A dict representation of the model

Return type:

Dict[str, Any]

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

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

class advanced_alchemy.base.BigIntBaseT

Type variable for BigIntBase.

alias of TypeVar(‘BigIntBaseT’, bound=BigIntBase)

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

class advanced_alchemy.base.ModelProtocol[source]

Bases: Protocol

The base SQLAlchemy model protocol.

__table__

The table associated with the model.

Type:

sqlalchemy.sql.FromClause

__mapper__

The mapper for the model.

Type:

sqlalchemy.orm.Mapper

__name__

The name of the model.

Type:

str

to_dict(exclude=None)[source]

Convert model to dictionary.

Returns:

A dict representation of the model

Return type:

Dict[str, Any]

__init__(*args, **kwargs)
class advanced_alchemy.base.NanoIDAuditBase[source]

Bases: CommonTableAttributes, NanoIDPrimaryKey, AuditColumns, AdvancedDeclarativeBase, AsyncAttrs

Base for declarative models with Nano ID primary keys and audit columns.

See also

CommonTableAttributes advanced_alchemy.mixins.NanoIDPrimaryKey advanced_alchemy.mixins.AuditColumns AdvancedDeclarativeBase AsyncAttrs

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

class advanced_alchemy.base.NanoIDBaseT

Type variable for NanoIDBase.

alias of TypeVar(‘NanoIDBaseT’, bound=NanoIDBase)

class advanced_alchemy.base.SQLQuery[source]

Bases: BasicAttributes, AdvancedDeclarativeBase, AsyncAttrs

Base for all SQLAlchemy custom mapped objects.

See also

BasicAttributes AdvancedDeclarativeBase AsyncAttrs

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

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

class advanced_alchemy.base.UUIDBaseT

Type variable for UUIDBase.

alias of TypeVar(‘UUIDBaseT’, bound=UUIDBase)

class advanced_alchemy.base.UUIDv6AuditBase[source]

Bases: CommonTableAttributes, UUIDv6PrimaryKey, AuditColumns, AdvancedDeclarativeBase, AsyncAttrs

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

See also

CommonTableAttributes advanced_alchemy.mixins.UUIDv6PrimaryKey advanced_alchemy.mixins.AuditColumns AdvancedDeclarativeBase AsyncAttrs

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

class advanced_alchemy.base.UUIDv6BaseT

Type variable for UUIDv6Base.

alias of TypeVar(‘UUIDv6BaseT’, bound=UUIDv6Base)

class advanced_alchemy.base.UUIDv7AuditBase[source]

Bases: CommonTableAttributes, UUIDv7PrimaryKey, AuditColumns, AdvancedDeclarativeBase, AsyncAttrs

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

See also

CommonTableAttributes advanced_alchemy.mixins.UUIDv7PrimaryKey advanced_alchemy.mixins.AuditColumns AdvancedDeclarativeBase AsyncAttrs

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

class advanced_alchemy.base.UUIDv7BaseT

Type variable for UUIDv7Base.

alias of TypeVar(‘UUIDv7BaseT’, bound=UUIDv7Base)

advanced_alchemy.base.convention: _NamingSchemaTD | Mapping[Any, str | Callable[[Constraint, Table], str]] = {'ck': 'ck_%(table_name)s_%(constraint_name)s', 'fk': 'fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s', 'ix': 'ix_%(column_0_label)s', 'pk': 'pk_%(table_name)s', 'uq': 'uq_%(table_name)s_%(column_0_name)s'}

Templates for automated constraint name generation.

advanced_alchemy.base.create_registry(custom_annotation_map=None)[source]

Create a new SQLAlchemy registry.

Parameters:

custom_annotation_map (dict, optional) – Custom type annotations to use for the registry.

Returns:

A new SQLAlchemy registry with the specified type annotations.

Return type:

sqlalchemy.orm.registry

advanced_alchemy.base.merge_table_arguments(cls, table_args=None)[source]

Merge Table Arguments.

This function helps merge table arguments when using mixins that include their own table args, making it easier to append additional information such as comments or constraints to the model.

Parameters:
  • cls (type[sqlalchemy.orm.DeclarativeBase]) – The model that will get the table args.

  • table_args (TableArgsType, optional) – Additional information to add to table_args.

Returns:

Merged table arguments.

Return type:

TableArgsType

advanced_alchemy.base.table_name_regexp = re.compile('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))')

Regular expression for table name