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, Alembic migrations, and PostgREST API views from declarative dimension configurations. Define your schema once; pgcraft handles the rest.


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 / @produces decorators, executed in topological order.
  • Automatic migrations — Alembic integration with SQL-formatted migration scripts via sqlglot.
  • PostgREST API layer — API views, roles, and grants declared alongside your models.
  • 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.dimension import SimpleDimensionResourceFactory

metadata = MetaData()

SimpleDimensionResourceFactory(
    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.
  • An api.users view exposing the same columns for PostgREST.
  • 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.

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:

  • Postgres is king. Push logic into the database when it is obviously correct and declarative.
  • 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.5.0.tar.gz (52.4 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.5.0-py3-none-any.whl (80.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pgcraft-0.5.0.tar.gz
Algorithm Hash digest
SHA256 df70a6e7db4c961d2f5a4c8e06e8189244e11cdebdb7095347eaef73db2aa298
MD5 9f715fae59e8a9a18040e500f93aa719
BLAKE2b-256 3459631e89b2af725aead0d7f927c29a448e658d034a0a61683de7221c0e5a3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgcraft-0.5.0.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.5.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pgcraft-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da73ab48993ee0cc96a8aa4f65e562867b0d66c400304593c3513a868572e023
MD5 60dc8e6f9cef943fb2eb95b533f60d1a
BLAKE2b-256 8c17e111a288cd91041ec600182f126b77e701f5341365bdf308dd41dab71450

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgcraft-0.5.0-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