Skip to content

common_db

common-db — the one database interface: a typed connection, one client for every table op, and one declarative base every consumer’s tables register on.

from common_db import DBClient, DBConnectionConfig, DBSchemaBuilder, TableRef
db = DBClient(connection=DBConnectionConfig(host=..., database=..., user=..., password=...))
with db:
db.ensure(DBSchemaBuilder(TableRef.parse("raw.bars")).col("symbol", "text", pk=True))
report = db.upsert(frame, "raw.bars") # the sync op engine
async with db:
async with db.atx() as conn: # a consumer's own short transaction
await conn.execute("SELECT 1")

Connection is CONFIG, never code: the application builds the config once and hands it to everything. This package reads no environment and no secret store on its own; DBConnectionConfig.from_env exists for the application to call.