Skip to main content

SQLAlchemyLiteProtocol

TypeSource

db: SQLAlchemyLiteProtocol

Protocol compatible with Flask SQLAlchemy Lite.

Flask SQLAlchemy Lite provides less functionality compared to Flask SQlAlchemy. It is ready since Python>=3.9. Although this package is new, it is still preferred because it works better with SQLAlchemy>=2 and Python's typing system.

This protocol covers most but does not include all functionalities of flask_sqlalchemy_lite.SQLAlchemy.

Aliases

This type can be acquired by

import flask_sqlalchemy_compat as fsc


fsc.SQLAlchemyLiteProtocol
fsc.protocols.SQLAlchemyLiteProtocol

Protocol methods

init_app

db.init_app(app: App)

Register the extension on an application, creating engines from its Flask.config.

Protocol properties

engine

db.engine: sa.engine.Engine

The default engine associated with the current application.


engines

db.engines: dict[str, sa.engine.Engine]

The engines associated with the current application.


sessionmaker

db.sessionmaker: sa.orm.sessionmaker[sa.orm.Session]

The session factory configured for the current application. This can be used to create sessions directly, but they will not be closed automatically at the end of the application context. Use session and get_session for that.


session

db.session: sa.orm.Session

The default session for the current application context. It will be closed when the context ends.


async_engines

db.async_engines: dict[str, sa.async.AsyncEngine]

The async engines associated with the current application.


async_engine

db.async_engine: sa.async.AsyncEngine

The default async engine associated with the current application.


async_sessionmaker

db.async_sessionmaker: sa.async.async_sessionmaker[sa.async.AsyncSession]

The async session factory configured for the current application.


async_session

db.async_session: sa.async.AsyncSession

The default async session for the current application context. It will be closed when the context ends.