pgcraft
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/@producesdecorators, 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.
Metadata
Release files for pgcraft 0.13.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pgcraft-0.13.3.tar.gz | 123.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pgcraft-0.13.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 300.8 kB
Release files / pgcraft-0.13.3.tar.gz
| Download URL | pgcraft-0.13.3.tar.gz |
|---|---|
| Size | 123.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdcacc7a98eb80ea367def1219fe0263dcdf5586875b49dc7f62f82c3824b177
|
|
BLAKE2b-256 checksum How to use checksums |
89057dd3c8aecc7d6690567996f8a17a1240e57873d7aef2db25beaf0766d9e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2026.
Transparency logRelease files / pgcraft-0.13.3-py3-none-any.whl
| Download URL | pgcraft-0.13.3-py3-none-any.whl |
|---|---|
| Size | 177.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5af50a21ea06c7df521af6446bde6064dd3ff03eef2cfe7a1659a75d981c6cc
|
|
BLAKE2b-256 checksum How to use checksums |
a3f493ff32780cbd777cc1ec9c590bb72a18450cd18cf468ec7867569434df6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2026.
Transparency log