Skip to main content

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 BloqueSettings with pool configuration, reads from env vars with BLOQUE_ prefix
  • create_async_engine: Wrapper with sensible defaults, auto-detects SQLite for testing
  • create_session_factory: Returns async_sessionmaker with expire_on_commit=False
  • get_db_session: FastAPI Depends() compatible async generator
  • db_health_check: SELECT 1 health check for HealthResponse.checks
  • Base: SQLAlchemy DeclarativeBase - no opinionated id column
  • TimestampMixin: created_at + updated_at with auto-defaults
  • SoftDeleteMixin: deleted_at + is_deleted property + 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)

Source distribution for ulfblk-db 0.1.1
File Size Uploaded
ulfblk_db-0.1.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ulfblk-db 0.1.1
File Interpreter ABI Platform
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}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page