Configuration-driven PostgreSQL framework
Project description
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
- Dimension types — Simple, Append-Only (SCD Type 2), and Entity-Attribute-Value, 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.factory import PGCraftSimple
metadata = MetaData()
users = PGCraftSimple(
tablename="users",
schemaname="public",
metadata=metadata,
schema_items=[
Column("name", String, nullable=False),
Column("email", 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
Dimension types
pgcraft ships with three built-in dimension types:
| Type | 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 |
See the dimensions documentation for ERD diagrams, schema details, and worked examples.
Documentation
Full documentation is available at roddarjohn.github.io/pgcraft.
- Setup & installation
- Built-in dimensions
- Plugin system
- Extensions
- API reference
- Development guide
- Playground
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 # ty 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
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
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 pgcraft-0.9.0.tar.gz.
File metadata
- Download URL: pgcraft-0.9.0.tar.gz
- Upload date:
- Size: 69.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2ef9696caf66d80668da35d7fd2126d9142845dcf193fc50a588269c5789247
|
|
| MD5 |
68ad42e3e141c4e9cd7cc00a91436096
|
|
| BLAKE2b-256 |
0d0d6fc7ba329fb466ab4fd9db6d48c72423d1bc7ebf79f6f00a85dc22afbb74
|
Provenance
The following attestation bundles were made for pgcraft-0.9.0.tar.gz:
Publisher:
publish.yml on roddarjohn/pgcraft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgcraft-0.9.0.tar.gz -
Subject digest:
f2ef9696caf66d80668da35d7fd2126d9142845dcf193fc50a588269c5789247 - Sigstore transparency entry: 1206450261
- Sigstore integration time:
-
Permalink:
roddarjohn/pgcraft@c57236a67767bdb225fe1090c1b02ffecb1c3bfb -
Branch / Tag:
refs/tags/pgcraft-v0.9.0 - Owner: https://github.com/roddarjohn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c57236a67767bdb225fe1090c1b02ffecb1c3bfb -
Trigger Event:
release
-
Statement type:
File details
Details for the file pgcraft-0.9.0-py3-none-any.whl.
File metadata
- Download URL: pgcraft-0.9.0-py3-none-any.whl
- Upload date:
- Size: 105.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0bd6cd43fde33c1502c978cd1348097bd6efc4b42cb6076d26acb282d0f9110
|
|
| MD5 |
6253fb9623ffb2932041e6bec784ebcd
|
|
| BLAKE2b-256 |
fcadaf38c99cba14ca5477c008a0c4db8cad24aee9ce37753181b16053afebbe
|
Provenance
The following attestation bundles were made for pgcraft-0.9.0-py3-none-any.whl:
Publisher:
publish.yml on roddarjohn/pgcraft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgcraft-0.9.0-py3-none-any.whl -
Subject digest:
b0bd6cd43fde33c1502c978cd1348097bd6efc4b42cb6076d26acb282d0f9110 - Sigstore transparency entry: 1206450266
- Sigstore integration time:
-
Permalink:
roddarjohn/pgcraft@c57236a67767bdb225fe1090c1b02ffecb1c3bfb -
Branch / Tag:
refs/tags/pgcraft-v0.9.0 - Owner: https://github.com/roddarjohn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c57236a67767bdb225fe1090c1b02ffecb1c3bfb -
Trigger Event:
release
-
Statement type: