Skip to content

Reference

elefast

AsyncDatabase

AsyncDatabase(
    engine: AsyncEngine,
    server: AsyncDatabaseServer,
    sessionmaker_factory: Callable[
        [AsyncEngine], Callable[[], AsyncSession]
    ] = async_sessionmaker,
)

Bases: AbstractAsyncContextManager

drop

drop() -> None

engine

engine = engine

name

name: str

server

server = server

session

session() -> AsyncSession

sessionmaker

sessionmaker = sessionmaker_factory(engine)

url

url: URL

AsyncDatabaseServer

AsyncDatabaseServer(
    engine: CanBeTurnedIntoAsyncEngine,
    schema: AsyncMigrator | None = None,
)

create_database

create_database(
    prefix: str = "elefast", encoding: str = "utf8"
) -> AsyncDatabase

drop_database

drop_database(name: str) -> None

ensure_is_ready

ensure_is_ready(
    timeout: float = 30, interval: float = 0.5
) -> Self

url

url: URL

AsyncMetadataMigrator

AsyncMetadataMigrator(metadata: MetaData)

Bases: AsyncMigrator

migrate_async

migrate_async(connection: AsyncConnection) -> None

AsyncMigrator

Bases: Protocol

migrate_async

migrate_async(connection: AsyncConnection) -> None

CanBeTurnedIntoAsyncEngine

CanBeTurnedIntoAsyncEngine: TypeAlias = (
    "AsyncEngine | URL | str"
)

CanBeTurnedIntoEngine

CanBeTurnedIntoEngine: TypeAlias = 'Engine | URL | str'

Database

Database(
    engine: Engine,
    server: DatabaseServer,
    sessionmaker_factory: Callable[
        [Engine], Callable[[], Session]
    ] = sessionmaker,
)

Bases: AbstractContextManager

A Postgres database.

Note that this is usually obtained from DatabaseServer.create_database() and you should not need to construct it yourself.

Parameters:

Name Type Description Default
engine Engine

the engine holding the connections to the specific database.

required
server DatabaseServer

a reference to the database server that created the database.

required
sessionmaker_factory Callable[[Engine], Callable[[], Session]]

allows you to set custom options for the Database.session() utility.

sessionmaker

drop

drop() -> None

Disposes the engine and drops the database.

If you for some reason do not use this class as a context manager, use this to clean up when you don't need it anymore.

engine

engine = engine

name

name: str

The name of the database.

server

server = server

session

session() -> Session

Creates a new ORM session.

You can use the sessionmaker_factory parameter of the constructor to customize options.

sessionmaker

sessionmaker = sessionmaker_factory(engine)

url

url: URL

The engine URL, allowing you to create your own engines with custom options.

DatabaseServer

DatabaseServer(
    engine: CanBeTurnedIntoEngine,
    schema: Migrator | None = None,
    debug=False,
)

create_database

create_database(
    prefix: str = "elefast", encoding: str = "utf8"
) -> Database

drop_database

drop_database(name: str) -> None

ensure_is_ready

ensure_is_ready(
    timeout: float = 30, interval: float = 0.5
) -> Self

url

url: URL

MetadataMigrator

MetadataMigrator(metadata: MetaData)

Bases: Migrator

Creates the database schema based on sqlalchemy.MetaData.

migrate

migrate(connection: Connection) -> None

Drops and creates all tables specified in the metadata object passed via the constructor.

Migrator

Bases: Protocol

Defines how the database schema is created.

migrate

migrate(connection: Connection) -> None

Creates the database schema for the passed connection.

elefast.extras.alembic

Utility functions for working with Alembic.

AlembicMigrator

AlembicMigrator(config_path: PathLike[str])

Bases: Migrator, AsyncMigrator

Runs your migrations to create the testing database schema.

migrate

migrate(connection: Connection) -> None

migrate_async

migrate_async(connection: AsyncConnection) -> None

elefast.extras.docker

This module is part of the 'docker' extra and needs to be explicitly installed before it is safe to use!

postgres

postgres(
    driver: str,
    docker: DockerClient | None = None,
    config: Configuration | None = None,
    keep_container_around: bool = True,
) -> URL