Data migration framework for versioning ETL and data operations alongside Alembic
Project description
Delembic
Data migration framework for Python — Alembic for ETL and data operations.
Alembic versions schema changes. Delembic versions data changes: vocabulary loads, ETL runs, reference data inserts, corrections. Together they describe the complete database state.
Installation
pip install delembic
Quick Start
# 1. Initialize in your project
delembic init
# 2. Edit delembic.ini — set your database URL
# sqlalchemy.url = postgresql+psycopg://user:pass@host/dbname
# 3. Create a migration
delembic revision -m "load vocabulary"
# 4. Fill in the generated file, then run
delembic upgrade head
Configuration
delembic init creates:
your-project/
├── delembic.ini # config — commit this
└── delembic/
├── env.py # optional connection helpers
└── versions/ # migration files live here
delembic.ini:
[delembic]
script_location = delembic
sqlalchemy.url = postgresql+psycopg://user:pass@localhost/mydb
alembic_config = alembic.ini
You can name the script folder anything:
delembic init data-migrations
Writing Migrations
from delembic import DataMigration
class LoadVocabulary(DataMigration):
revision = "D001"
depends_on = []
description = "Load OMOP vocabulary tables"
def upgrade(self, conn):
conn.execute(...)
def validate(self, conn):
count = conn.execute("SELECT COUNT(*) FROM concept").scalar()
assert count > 0, "vocabulary load produced no rows"
conn is a SQLAlchemy Connection. validate is optional — migration is marked failed if it raises.
Dependency Tracking
Migrations declare explicit dependencies. Delembic builds a DAG and runs them in topological order.
class LoadPerson(DataMigration):
revision = "D002"
depends_on = ["D001"] # waits for D001
Alembic Integration
Point alembic_config at your alembic.ini:
[delembic]
alembic_config = alembic.ini
When you create a migration, Delembic automatically captures the current Alembic head:
delembic revision -m "load person"
# → depends_on = ['3d1e3e6abc12'] (current alembic head)
At upgrade time, Delembic verifies the required Alembic revision has been applied before running:
BLOCKED: Migration D002 requires Alembic revision(s) 3d1e3e6abc12 to be applied first.
Run 'alembic upgrade head' before retrying.
CLI Reference
| Command | Description |
|---|---|
delembic init [DIR] |
Initialize project. DIR defaults to delembic |
delembic revision -m "msg" |
Generate new migration file |
delembic upgrade head |
Run all pending migrations |
delembic upgrade D003 |
Run migrations up to D003 |
delembic current |
Show last applied revision |
delembic history |
List all migrations with status |
Metadata Tables
Delembic creates two tables:
delembic_version -- current status per revision
delembic_run_history -- full audit log (start/end time, duration, exception, user, host)
Failed migration work is rolled back. The failure record is always committed — audit trail survives transaction failures.
Development
pip install -e ".[dev]"
pytest
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
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 delembic-0.4.0.tar.gz.
File metadata
- Download URL: delembic-0.4.0.tar.gz
- Upload date:
- Size: 175.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a53d0dc1095a62d47c3cb3a4598f7524d6384da30e7047d9823ba765004948ab
|
|
| MD5 |
72e31815dfb4e24cda6eb327067e410a
|
|
| BLAKE2b-256 |
a5e9f0b439a4e21a82050b71cda3c2845a4f9cf024505e630768f07a63043606
|
Provenance
The following attestation bundles were made for delembic-0.4.0.tar.gz:
Publisher:
release.yml on pradhanhitesh/delembic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
delembic-0.4.0.tar.gz -
Subject digest:
a53d0dc1095a62d47c3cb3a4598f7524d6384da30e7047d9823ba765004948ab - Sigstore transparency entry: 1774899832
- Sigstore integration time:
-
Permalink:
pradhanhitesh/delembic@9a6e4da8449e2a543529496c9ffe45cff31403bd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pradhanhitesh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9a6e4da8449e2a543529496c9ffe45cff31403bd -
Trigger Event:
push
-
Statement type:
File details
Details for the file delembic-0.4.0-py3-none-any.whl.
File metadata
- Download URL: delembic-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44276be22451b2ecaf9fa5ca845aeafd33413b4a84dd5d49267a9df9e738ec21
|
|
| MD5 |
1ed245b5dfba9aa7cc4945efd987ed76
|
|
| BLAKE2b-256 |
7b54ad7ca6aacb6c46a98dda934311516e22db75a84e8130fae594e91791f709
|
Provenance
The following attestation bundles were made for delembic-0.4.0-py3-none-any.whl:
Publisher:
release.yml on pradhanhitesh/delembic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
delembic-0.4.0-py3-none-any.whl -
Subject digest:
44276be22451b2ecaf9fa5ca845aeafd33413b4a84dd5d49267a9df9e738ec21 - Sigstore transparency entry: 1774900040
- Sigstore integration time:
-
Permalink:
pradhanhitesh/delembic@9a6e4da8449e2a543529496c9ffe45cff31403bd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pradhanhitesh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9a6e4da8449e2a543529496c9ffe45cff31403bd -
Trigger Event:
push
-
Statement type: