sqlalchemy-multiple-db
Explicit, typed SQLAlchemy 2.x session management for multiple named databases.
Requirements
- Python 3.11, 3.12, 3.13, or 3.14
- SQLAlchemy 2.x (installed automatically)
Installation
uv add sqlalchemy-multiple-db
# or
uv pip install sqlalchemy-multiple-db
Quick start
from sqlalchemy import text
from sqlalchemy_multiple_db import DatabaseConfig, DatabaseManager
configs = {
"primary": DatabaseConfig(url="sqlite:///primary.db"),
"analytics": DatabaseConfig(url="sqlite:///analytics.db"),
}
with DatabaseManager(configs) as databases:
with databases.session("primary") as session:
session.execute(text("CREATE TABLE IF NOT EXISTS events (id INTEGER PRIMARY KEY)"))
session.execute(text("INSERT INTO events DEFAULT VALUES"))
with databases.session("analytics") as session:
session.execute(text("SELECT 1"))
assert databases.healthcheck() == {"primary": True, "analytics": True}
Each session(name) call creates a new SQLAlchemy Session. A normal block commits; an exception
rolls back and is re-raised; the session always closes. Call close() when not using the manager as a
context manager. close() is idempotent, but the manager cannot be used afterward.
Configuration
DatabaseConfig(url, engine_options={}, session_options={}) forwards option mappings to SQLAlchemy's
create_engine and sessionmaker. Options are copied at construction. The library deliberately does
not choose pool sizes or deprecated autocommit behavior; configure dialect-specific options explicitly
when needed.
healthcheck() runs SELECT 1 for every configured engine and returns a {name: bool} mapping.
SQLAlchemy connection failures are logged and reported as False without stopping checks for other
databases.
Migrating from 2.x
| 2.x | 3.0 |
|---|---|
DBConfig(dsn="...") |
DatabaseConfig(url="...") |
DBHelper or global db |
DatabaseManager(configurations) |
setup() |
construct the manager |
session_scope() |
session(name) |
get_status_info() |
healthcheck() |
shutdown() |
close() or with DatabaseManager(...) |
There is no global manager or implicit default database in 3.0. Name every database explicitly.
Examples
Each example uses temporary SQLite files and needs no external database server:
- basic_usage.py — create, write to, and query isolated primary and analytics databases.
- transaction_rollback.py — verify that an exception rolls back a transaction.
- healthcheck_and_options.py — configure engine/session options and inspect database health.
Run an example from a synced checkout:
uv run python examples/basic_usage.py
Development
uv sync --all-groups
uv run pytest
uv run ruff format --check src tests
uv run ruff check src tests
uv run mypy src
uv build
Use uv add <package> to add a dependency and uv lock --upgrade to refresh all locked dependency
versions. Commit every pyproject.toml and uv.lock change together.
License
Apache-2.0. See LICENSE.
Metadata
Release files for sqlalchemy-multiple-db 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlalchemy_multiple_db-3.0.0.tar.gz | 57.2 kB | With provenance | Details for sqlalchemy_multiple_db-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlalchemy_multiple_db-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for sqlalchemy_multiple_db-3.0.0-py3-none-any.whl |
Total release size: 66.9 kB
Release files / sqlalchemy_multiple_db-3.0.0.tar.gz
| Download URL | sqlalchemy_multiple_db-3.0.0.tar.gz |
|---|---|
| Size | 57.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3ca0835075a5f9bcb3e353fa2c727bee2c888cadbf79815a9e08d58645ce68ab
|
|
BLAKE2b-256 checksum How to use checksums |
fe821d212343f721e2febe91884acffb0123ee16b344a6bbd97a3aadc193654a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.
Transparency logRelease files / sqlalchemy_multiple_db-3.0.0-py3-none-any.whl
| Download URL | sqlalchemy_multiple_db-3.0.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01b737c8643e5dbefe2ed8587dc1f396e76c35496209926aca49e72bab5bb083
|
|
BLAKE2b-256 checksum How to use checksums |
799c3a9d2d3f90460a2a2ea54583eacaab84ec8030d56d08bd07af7e047fa66b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.
Transparency logSecurity for sqlalchemy-multiple-db 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sqlalchemy_multiple_db-3.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.