Database infrastructure: async engine, session management, and composable SQLAlchemy mixins
Project description
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 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ulfblk_db-0.1.1.tar.gz
(9.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ulfblk_db-0.1.1-py3-none-any.whl
(12.8 kB
view details)
File details
Details for the file ulfblk_db-0.1.1.tar.gz.
File metadata
- Download URL: ulfblk_db-0.1.1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
436a22a8c331e8877087e615c0e3b32f99f7e709a57787daf4581701a673d986
|
|
| MD5 |
bb8836102d60bc2607ee5a750a680f5f
|
|
| BLAKE2b-256 |
ef1717c9483e71427e8d507a48d676da9715abb3da0c8a7d2b0ac2e6d51de251
|
File details
Details for the file ulfblk_db-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ulfblk_db-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0656075adaa5d49773ecceec78fed6872bb047306e7963dfa3ec86dcd3d8939d
|
|
| MD5 |
751719435e692368caa634f148116754
|
|
| BLAKE2b-256 |
e34a5170873c9654556458e21625c95cda55aed975da03cac1385331e93c5271
|