Plugins & Configuration#

Plugin Classes#

class advanced_alchemy.extensions.litestar.plugins.SQLAlchemyPlugin(config)[source]#

Bases: InitPluginProtocol, SlotsBase

A plugin that provides SQLAlchemy integration.

on_app_init(app_config)[source]#

Configure application for use with SQLAlchemy.

Parameters:

app_config (AppConfig) – The AppConfig instance.

Returns:

The AppConfig instance.

Return type:

AppConfig

class advanced_alchemy.extensions.litestar.plugins.SQLAlchemyInitPlugin(config)#

Bases: InitPluginProtocol, CLIPlugin, SlotsBase

SQLAlchemy application lifecycle configuration.

on_app_init(app_config)#

Configure application for use with SQLAlchemy.

Parameters:

app_config (AppConfig) – The AppConfig instance.

Return type:

AppConfig

class advanced_alchemy.extensions.litestar.plugins.SQLAlchemySerializationPlugin#

Bases: SerializationPlugin, InitPluginProtocol, SlotsBase

on_app_init(app_config)#

Register Advanced Alchemy’s built-in type encoders and decoders.

AA encoders/decoders are added with lower precedence so user-supplied type_encoders / type_decoders on the application config win.

Return type:

AppConfig

supports_type(field_definition)#

Given a value of indeterminate type, determine if this value is supported by the plugin.

Parameters:

field_definition (FieldDefinition) – A parsed type.

Returns:

Whether the type is supported by the plugin.

Return type:

bool

Plugin Configuration Classes#

class advanced_alchemy.extensions.litestar.plugins.SQLAlchemyAsyncConfig(
create_engine_callable=<function create_async_engine>,
session_config=<factory>,
session_maker_class=<class 'sqlalchemy.ext.asyncio.session.async_sessionmaker'>,
connection_string=None,
engine_config=<factory>,
session_maker=None,
engine_instance=None,
create_all=False,
metadata=None,
bind_key=None,
enable_touch_updated_timestamp_listener=True,
enable_file_object_listener=True,
file_object_raise_on_error=True,
cache_config=None,
cache_manager=None,
alembic_config=<factory>,
routing_config=None,
before_send_handler=None,
engine_dependency_key='db_engine',
session_dependency_key='db_session',
engine_app_state_key='db_engine',
session_maker_app_state_key='session_maker_class',
session_scope_key='_sqlalchemy_db_session',
set_default_exception_handler=True,
)#

Bases: SQLAlchemyAsyncConfig

Litestar Async SQLAlchemy Configuration.

provide_engine(state)#

Create an engine instance.

Parameters:

state (State) – The Litestar.state instance.

Returns:

An engine instance.

Return type:

AsyncEngine

provide_session(state, scope)#

Create a session instance.

Parameters:
  • state (State) – The Litestar.state instance.

  • scope (Scope) – The current connection’s scope.

Returns:

A session instance.

Return type:

AsyncSession

async create_all_metadata(app)#

Create all metadata

Parameters:

app (Litestar) – The Litestar instance

class advanced_alchemy.extensions.litestar.plugins.SQLAlchemySyncConfig(
create_engine_callable=<function create_engine>,
session_config=<factory>,
session_maker_class=<class 'sqlalchemy.orm.session.sessionmaker'>,
connection_string=None,
engine_config=<factory>,
session_maker=None,
engine_instance=None,
create_all=False,
metadata=None,
bind_key=None,
enable_touch_updated_timestamp_listener=True,
enable_file_object_listener=True,
file_object_raise_on_error=True,
cache_config=None,
cache_manager=None,
alembic_config=<factory>,
routing_config=None,
before_send_handler=None,
engine_dependency_key='db_engine',
session_dependency_key='db_session',
engine_app_state_key='db_engine',
session_maker_app_state_key='session_maker_class',
session_scope_key='_sqlalchemy_db_session',
set_default_exception_handler=True,
)#

Bases: SQLAlchemySyncConfig

Litestar Sync SQLAlchemy Configuration.

provide_engine(state)#

Create an engine instance.

Parameters:

state (State) – The Litestar.state instance.

Returns:

An engine instance.

Return type:

Engine

provide_session(state, scope)#

Create a session instance.

Parameters:
  • state (State) – The Litestar.state instance.

  • scope (Scope) – The current connection’s scope.

Returns:

A session instance.

Return type:

Session

create_all_metadata(app)#

Create all metadata

Parameters:

app (Litestar) – The Litestar instance

class advanced_alchemy.extensions.litestar.plugins.EngineConfig(
connect_args=<class 'advanced_alchemy.utils.dataclass.Empty'>,
echo=<class 'advanced_alchemy.utils.dataclass.Empty'>,
echo_pool=<class 'advanced_alchemy.utils.dataclass.Empty'>,
enable_from_linting=<class 'advanced_alchemy.utils.dataclass.Empty'>,
execution_options=<class 'advanced_alchemy.utils.dataclass.Empty'>,
hide_parameters=<class 'advanced_alchemy.utils.dataclass.Empty'>,
insertmanyvalues_page_size=<class 'advanced_alchemy.utils.dataclass.Empty'>,
isolation_level=<class 'advanced_alchemy.utils.dataclass.Empty'>,
json_deserializer=<function decode_json>,
json_serializer=<function serializer>,
label_length=<class 'advanced_alchemy.utils.dataclass.Empty'>,
logging_name=<class 'advanced_alchemy.utils.dataclass.Empty'>,
max_identifier_length=<class 'advanced_alchemy.utils.dataclass.Empty'>,
max_overflow=<class 'advanced_alchemy.utils.dataclass.Empty'>,
module=<class 'advanced_alchemy.utils.dataclass.Empty'>,
paramstyle=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool=<class 'advanced_alchemy.utils.dataclass.Empty'>,
poolclass=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool_logging_name=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool_pre_ping=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool_size=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool_recycle=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool_reset_on_return=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool_timeout=<class 'advanced_alchemy.utils.dataclass.Empty'>,
pool_use_lifo=<class 'advanced_alchemy.utils.dataclass.Empty'>,
plugins=<class 'advanced_alchemy.utils.dataclass.Empty'>,
query_cache_size=<class 'advanced_alchemy.utils.dataclass.Empty'>,
use_insertmanyvalues=<class 'advanced_alchemy.utils.dataclass.Empty'>,
)#

Bases: EngineConfig

Configuration for SQLAlchemy’s Engine.

For details see: https://docs.sqlalchemy.org/en/20/core/engines.html