Skip to main content

Configuration-driven PostgreSQL framework

Project description

pgcraft

PyPI Documentation

Pre-alpha — pgcraft is under active development. APIs may change between releases. Feedback and contributions are welcome.

Configuration-driven PostgreSQL data schemas, migrations, and APIs.

pgcraft generates SQLAlchemy models and Alembic migrations from declarative dimension configurations. Define your schema once; pgcraft handles the rest. An optional PostgREST extension adds API views, roles, and grants.


Features

  • Factories — Simple, Append-Only (SCD Type 2), Entity-Attribute-Value, and Ledger, each with generated backing tables, views, and triggers.
  • Plugin architecture — Composable plugins with @requires / @produces decorators, executed in topological order.
  • Automatic migrations — Alembic integration with SQL-formatted migration scripts via sqlglot.
  • Extension system — Opt-in extensions for PostgREST API views, roles, and grants. Third-party extensions via entry points.
  • Postgres is king — Logic lives in the database (views, triggers, check constraints). Python orchestrates; Postgres enforces.

Quick start

Install

pip install pgcraft            # or: uv add pgcraft

Define a dimension

from sqlalchemy import Column, MetaData, String
from pgcraft import PGCraftBase, construct_pgcraft_naming_conventions_dict

metadata = MetaData(naming_convention=construct_pgcraft_naming_conventions_dict())


class Base(PGCraftBase):
    metadata = metadata


class Users(Base):
    __tablename__ = "users"
    __table_args__ = {"schema": "public"}

    name = Column(String, nullable=False)
    email = Column(String)

This creates a public.users table with id, name, and email columns, with Alembic migration support out of the box.

Generate migrations

pgcraft migrate revision --autogenerate -m "add users"
pgcraft migrate upgrade head

Factories

pgcraft ships four built-in factories:

Factory Use case History?
Simple Static reference data No
Append-Only (SCD Type 2) Track changes over time Yes
EAV Flexible / sparse attributes with full audit trail Yes
Ledger Append-only event streams, running balances, charts Yes

See the factories documentation for ERD diagrams, schema details, and worked examples.

Documentation

Full documentation is available at roddarjohn.github.io/pgcraft.

Development

# Clone and install
git clone https://github.com/<username>/pgcraft.git
cd pgcraft
uv sync --all-groups

# Run checks
just lint          # ruff check + format
just type-check    # zuban check src/
just dev-test      # pytest (fast, needs DATABASE_URL)
just test          # tox (full isolation)
just docs          # build Sphinx HTML docs

Tests require a running PostgreSQL instance:

DATABASE_URL=postgresql+psycopg:///pgcraft just dev-test

Design philosophy

See PLAN.md for the full design philosophy. The short version:

  • Explicit over implicit. No magic — if behavior is not obvious from reading the code, it needs a docstring explaining why.
  • Simple over clever. Three similar lines are better than a premature abstraction.

License

See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgcraft-0.13.2.tar.gz (121.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgcraft-0.13.2-py3-none-any.whl (175.2 kB view details)

Uploaded Python 3

File details

Details for the file pgcraft-0.13.2.tar.gz.

File metadata

  • Download URL: pgcraft-0.13.2.tar.gz
  • Upload date:
  • Size: 121.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pgcraft-0.13.2.tar.gz
Algorithm Hash digest
SHA256 d6e6bfcf4a83dadee0626f468bfb88d09392bdd72a223f9695cc893d6e12e5af
MD5 d06d3c8f7d178243b7c7a7b7c72b089d
BLAKE2b-256 55b9004eccbfb1fdfd7a44f8e2afaf97f1db458600ac379b9909b6688e04d4ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgcraft-0.13.2.tar.gz:

Publisher: publish.yml on roddarjohn/pgcraft

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pgcraft-0.13.2-py3-none-any.whl.

File metadata

  • Download URL: pgcraft-0.13.2-py3-none-any.whl
  • Upload date:
  • Size: 175.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pgcraft-0.13.2-py3-none-any.whl
Algorithm Hash digest
SHA256 00f23af7f580274ae83550d96ad550a326defb5ca11904ef5cf6ad7d844c32dd
MD5 5e144976479e552bf6710ede3d5e84ce
BLAKE2b-256 3306d2ba9574a2fb25fb8267220695d4eb92fe5f5aa06453fa62b16fb42de1ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgcraft-0.13.2-py3-none-any.whl:

Publisher: publish.yml on roddarjohn/pgcraft

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page