Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 109.4MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 12.0s · import 0.000s · 102MB
107MB installed
● package 107MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ConnectionPool
✓ from nsj_multi_database_lib.connection.connection_pool import ConnectionPool
DatabaseManager
✓ from nsj_multi_database_lib.connection.database_manager import DatabaseManager
DaoBase
✓ from nsj_multi_database_lib.dao.dao_base import DaoBase
✗ from nsj_multi_database_lib.dao_base import DaoBase
DaoBase is within the 'dao' submodule, not directly under the root package.
TransactionalDao
✓ from nsj_multi_database_lib.dao.transactional_dao import TransactionalDao
This quickstart demonstrates how to configure multiple in-memory SQLite databases using `nsj-multi-database-lib`. It shows how to initialize the `ConnectionPool` with a dictionary of database configurations, obtain sessions for different databases using `DatabaseManager.get_session()`, and perform basic SQL operations within a transactional context. Remember to replace the SQLite in-memory setup with your actual database connection strings and credentials.
import os
from nsj_multi_database_lib.connection.connection_pool import ConnectionPool
from nsj_multi_database_lib.connection.database_manager import DatabaseManager
from sqlalchemy import text
# Mock Database setup for example (using SQLite in-memory)
DB_NAME_DEFAULT = "default_db"
DB_NAME_AUDIT = "audit_db"
# NOTE: In a real application, connection_string would use actual DB credentials.
# Example for PostgreSQL: "postgresql://user:password@host:port/database"
DATABASE_CONFIGS = {
DB_NAME_DEFAULT: {
"engine": "sqlite",
"db": ":memory:",
"connection_string": "sqlite:///:memory:",
"schema": None,
"label": DB_NAME_DEFAULT
},
DB_NAME_AUDIT: {
"engine": "sqlite",
"db": ":memory:",
"connection_string": "sqlite:///:memory:",
"schema": None,
"label": DB_NAME_AUDIT
}
}
# 1. Initialize the connection pool with your database configurations
ConnectionPool.configure(DATABASE_CONFIGS)
try:
print("\n--- Using Default Database ---")
# 2. Get a database session using the context manager
with DatabaseManager.get_session(DB_NAME_DEFAULT) as session:
# Example operations with SQLAlchemy 1.x compatible syntax
session.execute(text("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)"))
session.execute(text("INSERT INTO users (id, name) VALUES (1, 'Alice')"))
session.execute(text("INSERT INTO users (id, name) VALUES (2, 'Bob')"))
session.commit()
result = session.execute(text("SELECT * FROM users")).fetchall()
print(f"Retrieved from {DB_NAME_DEFAULT}: {result}")
print("\n--- Using Audit Database ---")
with DatabaseManager.get_session(DB_NAME_AUDIT) as session:
session.execute(text("CREATE TABLE logs (id INTEGER PRIMARY KEY, event TEXT)"))
session.execute(text("INSERT INTO logs (id, event) VALUES (1, 'User Alice created')"))
session.commit()
result = session.execute(text("SELECT * FROM logs")).fetchall()
print(f"Retrieved from {DB_NAME_AUDIT}: {result}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# 3. Always close connections when done to release resources
ConnectionPool.close_all_connections()
print("\nAll database connections closed.")
Upgrade
Version history
2.1.0latest on PyPI · released Dec 17, 2025
Audit
Dependencies
SQLAlchemyrequiredCore dependency for ORM and database interactions. The library specifically requires SQLAlchemy < 2.0.0.