dredd-core 0.1.0 — the family's shared ORM/identity foundation, extracted

Standalone, permissive (SQLAlchemy-only) package the Dredd family apps import as
their core: the single SQLAlchemy Base/metadata + column mixins + custom types
(SafeInet, pg_enum). Modules import it; it never imports a module. First extraction
slice — identity models, auth/security, audit and the db engine helper follow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-12 13:43:16 +02:00
co-authored by Claude Opus 4.8
commit e86b58371c
6 changed files with 126 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
__pycache__/
*.pyc
*.egg-info/
build/
dist/
.venv/
+8
View File
@@ -0,0 +1,8 @@
# dredd-core
The shared foundation for the Dredd family (Galena, Sygna, Counsel Scorecard, Galena Connect).
It owns identity / session / auth / audit + the single SQLAlchemy `Base`/metadata; **modules import
it, it never imports a module.** Install with `pip install -e .` (or as a workspace/path dependency).
Extraction is incremental — see `Playground/Dredd/*.md` and each app's `SHARED.md`. This package is
the "core as its own thing": the byte-identical core the family previously copied now lives here once.
+20
View File
@@ -0,0 +1,20 @@
"""Dredd core — the shared foundation the family's apps (Galena, Sygna, Counsel Scorecard, Galena
Connect) import as an installable package. It owns identity/session/auth/audit + the SQLAlchemy base;
it never imports a module. See Playground/Dredd/*.md for the module plans.
This first slice carries the ORM foundation (the single ``Base`` / metadata + column mixins + custom
types). Later slices move identity models, auth/security, audit and the db engine helper here.
"""
from __future__ import annotations
from .base import NAMING_CONVENTION, Base, TimestampMixin, UUIDPkMixin
from .types import SafeInet, pg_enum
__all__ = [
"Base",
"NAMING_CONVENTION",
"SafeInet",
"TimestampMixin",
"UUIDPkMixin",
"pg_enum",
]
+38
View File
@@ -0,0 +1,38 @@
"""Declarative base + shared column mixins (the family's single SQLAlchemy metadata)."""
from __future__ import annotations
import datetime as dt
import uuid
from sqlalchemy import DateTime, MetaData, Uuid, func, text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
# Predictable constraint/index names → clean Alembic diffs.
NAMING_CONVENTION = {
"ix": "ix_%(column_0_label)s",
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s",
}
class Base(DeclarativeBase):
metadata = MetaData(naming_convention=NAMING_CONVENTION)
class UUIDPkMixin:
id: Mapped[uuid.UUID] = mapped_column(
Uuid(as_uuid=True),
primary_key=True,
server_default=text("gen_random_uuid()"),
)
class TimestampMixin:
created_at: Mapped[dt.datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
updated_at: Mapped[dt.datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now(), onupdate=func.now()
)
+36
View File
@@ -0,0 +1,36 @@
"""Custom SQLAlchemy column types: self-validating INET + native PG enum helper."""
from __future__ import annotations
import ipaddress
from sqlalchemy.dialects.postgresql import ENUM as PGEnum
from sqlalchemy.dialects.postgresql import INET
from sqlalchemy.types import TypeDecorator
class SafeInet(TypeDecorator):
"""An INET column that coerces any non-IP value to NULL on bind, so a bad host
(e.g. Starlette TestClient's literal 'testclient') can never trigger an INET cast error."""
impl = INET
cache_ok = True
def process_bind_param(self, value, dialect):
if value is None:
return None
try:
ipaddress.ip_address(value)
except (ValueError, TypeError):
return None
return value
def pg_enum(py_enum, name: str) -> PGEnum:
# postgresql.ENUM with create_type=False → create_all() never emits CREATE TYPE; the
# Alembic migration's explicit loop is the single source of truth for enum lifecycle.
return PGEnum(
py_enum,
name=name,
create_type=False,
values_callable=lambda enum_cls: [member.value for member in enum_cls],
)
+18
View File
@@ -0,0 +1,18 @@
[project]
name = "dredd-core"
version = "0.1.0"
description = "Dredd core — the shared identity/session/auth/audit/ORM foundation for the family (Galena, Sygna, Counsel Scorecard, Galena Connect). Modules import it; it never imports a module."
readme = "README.md"
requires-python = ">=3.12"
authors = [{ name = "Tobiasz Badura" }]
# Kept deliberately small and permissive — the family's license gate forbids copyleft.
dependencies = [
"SQLAlchemy>=2.0",
]
[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
include = ["dredd_core*"]