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.0.tar.gz
(6.2 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
File details
Details for the file ulfblk_db-0.1.0.tar.gz.
File metadata
- Download URL: ulfblk_db-0.1.0.tar.gz
- Upload date:
- Size: 6.2 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 |
da6b9fc6a3ce5b2151b3bc32895d9c3add79e2a40f4ef17957428eb0b60619ab
|
|
| MD5 |
a39048326f5d04e4af36c2a852dfedc3
|
|
| BLAKE2b-256 |
a810a0de55f781bfbbdd48050082c1d9aee255fecc2e9d28371bf401e2f30634
|
File details
Details for the file ulfblk_db-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ulfblk_db-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 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 |
6760b9777744c5b3b2907c0f14798b636801d00ebdccef5612313d05ca9eb02f
|
|
| MD5 |
697c7d74f39e19d0442360fbc90d2127
|
|
| BLAKE2b-256 |
c048cd48caa35c06628d25e2122df443e65685746bfb0b1266ffb2345ef79e8a
|