common

advanced_alchemy.config.common.ALEMBIC_TEMPLATE_PATH = '/home/runner/work/advanced-alchemy/advanced-alchemy/advanced_alchemy/alembic/templates'

Path to the Alembic templates.

class advanced_alchemy.config.common.ConnectionT

Type variable for SQLAlchemy connection types.

See also

sqlalchemy.Connection sqlalchemy.ext.asyncio.AsyncConnection

alias of TypeVar(‘ConnectionT’, bound=Connection | AsyncConnection)

class advanced_alchemy.config.common.EngineT

Type variable for a SQLAlchemy engine.

See also

sqlalchemy.Engine sqlalchemy.ext.asyncio.AsyncEngine

alias of TypeVar(‘EngineT’, bound=Engine | AsyncEngine)

class advanced_alchemy.config.common.GenericAlembicConfig[source]

Bases: object

Configuration for Alembic’s Config.

For details see: https://alembic.sqlalchemy.org/en/latest/api/config.html

__init__(script_config: str = 'alembic.ini', version_table_name: str = 'alembic_versions', version_table_schema: str | None = None, script_location: str = 'migrations', user_module_prefix: str | None = 'sa.', render_as_batch: bool = True, compare_type: bool = False, template_path: str = '/home/runner/work/advanced-alchemy/advanced-alchemy/advanced_alchemy/alembic/templates') None
script_config: str = 'alembic.ini'

A path to the Alembic configuration file such as alembic.ini. If left unset, the default configuration will be used.

version_table_name: str = 'alembic_versions'

Configure the name of the table used to hold the applied alembic revisions. Defaults to alembic_versions.

version_table_schema: str | None = None

Configure the schema to use for the alembic revisions revisions. If unset, it defaults to connection’s default schema.

script_location: str = 'migrations'

A path to save generated migrations.

user_module_prefix: str | None = 'sa.'

User module prefix.

render_as_batch: bool = True

Render as batch.

compare_type: bool = False

Compare type.

template_path: str = '/home/runner/work/advanced-alchemy/advanced-alchemy/advanced_alchemy/alembic/templates'

Template path.

class advanced_alchemy.config.common.GenericSQLAlchemyConfig[source]

Bases: Generic[EngineT, SessionT, SessionMakerT]

Common SQLAlchemy Configuration.

Types:

EngineT: sqlalchemy.Engine or sqlalchemy.ext.asyncio.AsyncEngine SessionT: sqlalchemy.Session or sqlalchemy.ext.asyncio.AsyncSession SessionMakerT: sqlalchemy.orm.sessionmaker or sqlalchemy.ext.asyncio.async_sessionmaker

create_engine_callable: Callable[[str], EngineT]

Callable that creates an AsyncEngine instance or instance of its subclass.

session_config: GenericSessionConfig[Any, Any, Any]

Configuration options for either the async_sessionmaker or sessionmaker.

session_maker_class: type[sessionmaker[Session] | async_sessionmaker[AsyncSession]]

Sessionmaker class to use.

connection_string: str | None = None

Database connection string in one of the formats supported by SQLAlchemy.

Notes

  • For async connections, the connection string must include the correct async prefix. e.g. 'postgresql+asyncpg://...' instead of 'postgresql://', and for sync connections its the opposite.

engine_config: EngineConfig

Configuration for the SQLAlchemy engine.

The configuration options are documented in the SQLAlchemy documentation.

session_maker: Callable[[], SessionT] | None = None

Callable that returns a session.

If provided, the plugin will use this rather than instantiate a sessionmaker.

__init__(create_engine_callable: Callable[[str], EngineT], session_config: GenericSessionConfig[Any, Any, Any], session_maker_class: type[sessionmaker[Session] | async_sessionmaker[AsyncSession]], connection_string: str | None = None, engine_config: EngineConfig = <factory>, session_maker: Callable[[], SessionT] | None = None, engine_instance: EngineT | None = None, create_all: bool = False, metadata: MetaData | None = None, enable_touch_updated_timestamp_listener: bool = True, bind_key: str | None = None) None
engine_instance: EngineT | None = None

Optional engine to use.

If set, the plugin will use the provided instance rather than instantiate an engine.

create_all: bool = False

If true, all models are automatically created on engine creation.

metadata: MetaData | None = None

Optional metadata to use.

If set, the plugin will use the provided instance rather than the default metadata.

enable_touch_updated_timestamp_listener: bool = True

Enable Created/Updated Timestamp event listener.

This is a listener that will update created_at and updated_at columns on record modification. Disable if you plan to bring your own update mechanism for these columns

bind_key: str | None = None

Bind key to register a metadata to a specific engine configuration.

property engine_config_dict: dict[str, Any]

Return the engine configuration as a dict.

Returns:

A string keyed dict of config kwargs for the SQLAlchemy get_engine function.

property session_config_dict: dict[str, Any]

Return the session configuration as a dict.

Returns:

A string keyed dict of config kwargs for the SQLAlchemy sessionmaker class.

get_engine() sqlalchemy.engine.Engine[source]

Return an engine. If none exists yet, create one.

Returns:

sqlalchemy.Engine or sqlalchemy.ext.asyncio.AsyncEngine instance used by the plugin.

create_session_maker() Callable[[], sqlalchemy.orm.Session][source]

Get a session maker. If none exists yet, create one.

Returns:

sqlalchemy.orm.sessionmaker or sqlalchemy.ext.asyncio.async_sessionmaker factory used by the plugin.

class advanced_alchemy.config.common.GenericSessionConfig[source]

Bases: Generic[ConnectionT, EngineT, SessionT]

SQLAlchemy async session config.

Types:

ConnectionT: sqlalchemy.Connection | sqlalchemy.ext.asyncio.AsyncConnection EngineT: sqlalchemy.Engine | sqlalchemy.ext.asyncio.AsyncEngine SessionT: sqlalchemy.Session | sqlalchemy.ext.asyncio.AsyncSession

autobegin

Automatically start transactions when database access is requested by an operation.

Bool or Empty

alias of Empty

autoflush

When True, all query operations will issue a flush call to this Session before proceeding

alias of Empty

bind

The Engine or Connection that new Session objects will be bound to.

alias of Empty

binds

A dictionary which may specify any number of Engine or Connection objects as the source of connectivity for SQL operations on a per-entity basis. The keys of the dictionary consist of any series of mapped classes, arbitrary Python classes that are bases for mapped classes, Table objects and Mapper objects. The values of the dictionary are then instances of Engine or less commonly Connection objects.

alias of Empty

class_

Class to use in order to create new Session objects.

alias of Empty

expire_on_commit

If True, all instances will be expired after each commit.

alias of Empty

info

Optional dictionary of information that will be available via the Session.info

alias of Empty

join_transaction_mode

Describes the transactional behavior to take when a given bind is a Connection that has already begun a transaction outside the scope of this Session; in other words the Connection.in_transaction() method returns True.

alias of Empty

query_cls

Class which should be used to create new Query objects, as returned by the Session.query() method.

alias of Empty

twophase

When True, all transactions will be started as a “two phase” transaction, i.e. using the “two phase” semantics of the database in use along with an XID. During a commit(), after flush() has been issued for all attached databases, the TwoPhaseTransaction.prepare() method on each database`s TwoPhaseTransaction will be called. This allows each database to roll back the entire transaction, before each transaction is committed.

alias of Empty

__init__(autobegin: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, autoflush: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, bind: EngineT | ConnectionT | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, binds: dict[type[Any] | Mapper | TableClause | str, EngineT | ConnectionT] | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, class_: type[SessionT] | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, expire_on_commit: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, info: dict[str, Any] | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, join_transaction_mode: JoinTransactionMode | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, query_cls: type[Query] | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, twophase: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>) None
class advanced_alchemy.config.common.SessionMakerT

Type variable for a SQLAlchemy sessionmaker.

alias of TypeVar(‘SessionMakerT’, bound=sessionmaker[Session] | async_sessionmaker[AsyncSession])

class advanced_alchemy.config.common.SessionT

Type variable for a SQLAlchemy session.

See also

sqlalchemy.Session sqlalchemy.ext.asyncio.AsyncSession

alias of TypeVar(‘SessionT’, bound=Session | AsyncSession)