ulfblk-db
Database infrastructure for the Bloques ecosystem: async engine factory, session management, and composable SQLAlchemy mixins.
Installation
uv add ulfblk-db
Quick Start
from ulfblk_db import (
Base,
DatabaseSettings,
TimestampMixin,
SoftDeleteMixin,
create_async_engine,
create_session_factory,
get_db_session,
db_health_check,
)
# 1. Configure
settings = DatabaseSettings() # reads BLOQUE_DATABASE_URL from env
# 2. Create engine and session factory
engine = create_async_engine(settings)
SessionLocal = create_session_factory(engine)
# 3. Define models with composable mixins
class User(Base, TimestampMixin, SoftDeleteMixin):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
# 4. Use in FastAPI
from fastapi import Depends
from sqlalchemy.ext.asyncio import AsyncSession
app = FastAPI()
db_dep = get_db_session(SessionLocal)
@app.get("/users")
async def list_users(db: AsyncSession = Depends(db_dep)):
result = await db.execute(select(User))
return result.scalars().all()
Features
- DatabaseSettings: Extends
BloqueSettingswith pool configuration, reads from env vars withBLOQUE_prefix - create_async_engine: Wrapper with sensible defaults, auto-detects SQLite for testing
- create_session_factory: Returns
async_sessionmakerwithexpire_on_commit=False - get_db_session: FastAPI
Depends()compatible async generator - db_health_check:
SELECT 1health check forHealthResponse.checks - Base: SQLAlchemy
DeclarativeBase- no opinionatedidcolumn - TimestampMixin:
created_at+updated_atwith auto-defaults - SoftDeleteMixin:
deleted_at+is_deletedproperty +soft_delete()/restore()helpers
Environment Variables
| Variable | Default | Description |
|---|---|---|
BLOQUE_DATABASE_URL |
postgresql+asyncpg://localhost:5432/bloquedb |
Database connection URL |
BLOQUE_DB_POOL_SIZE |
5 |
Connection pool size |
BLOQUE_DB_MAX_OVERFLOW |
10 |
Max overflow connections |
BLOQUE_DB_POOL_TIMEOUT |
30 |
Pool timeout in seconds |
BLOQUE_DB_POOL_RECYCLE |
1800 |
Connection recycle time in seconds |
BLOQUE_DB_ECHO |
false |
Echo SQL statements |
Metadata
Release files for ulfblk-db 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ulfblk_db-0.1.1.tar.gz | 9.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ulfblk_db-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.8 kB
Release files / ulfblk_db-0.1.1.tar.gz
| Download URL | ulfblk_db-0.1.1.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
436a22a8c331e8877087e615c0e3b32f99f7e709a57787daf4581701a673d986
|
|
BLAKE2b-256 checksum How to use checksums |
ef1717c9483e71427e8d507a48d676da9715abb3da0c8a7d2b0ac2e6d51de251
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / ulfblk_db-0.1.1-py3-none-any.whl
| Download URL | ulfblk_db-0.1.1-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0656075adaa5d49773ecceec78fed6872bb047306e7963dfa3ec86dcd3d8939d
|
|
BLAKE2b-256 checksum How to use checksums |
e34a5170873c9654556458e21625c95cda55aed975da03cac1385331e93c5271
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|