larzmigrate
Schema migrations for SQL and larzdb. Pure Python, zero dependencies.
Evolve a schema safely: write ordered migrations with an up and an optional
down, and larzmigrate applies the pending ones in order, records what it did,
and can roll back — against any DB-API connection (sqlite3, psycopg2, …) or
a larzdb database.
import sqlite3
from larzmigrate import Migrator, SQLBackend
m = Migrator(SQLBackend(sqlite3.connect("app.db")))
m.add_sql("001_users",
up="CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)",
down="DROP TABLE users")
@m.migration("002_seed")
def seed(conn):
conn.execute("INSERT INTO users (name) VALUES ('admin')")
m.migrate() # apply everything pending, in order (idempotent)
m.rollback() # undo the most recent migration
m.status() # [("001_users", "applied"), ("002_seed", "applied")]
What makes it different
- Storage-agnostic. The same migrator drives a SQL database (via any DB-API connection) or a larzdb / key-value store — pick the backend, write your migrations once.
- Detects edited migrations. Every migration is checksummed. If one that's
already applied gets changed,
migrate()errors (checksum drift) instead of silently diverging from what actually ran — the bug that bites teams. - Real rollback.
downmigrations run in reverse;rollback(steps=N)undoes the last N. - Idempotent. Re-running only applies what's pending; safe to run on every deploy.
- Zero dependencies. No Alembic, no ORM.
Install
pip install larzmigrate
Backends
from larzmigrate import Migrator, SQLBackend, KVBackend, DictStore
# SQL: any DB-API connection (sqlite3, psycopg2, MySQLdb, ...)
Migrator(SQLBackend(connection))
# larzdb or any get/put store
Migrator(KVBackend(larzdb_database))
Migrator(KVBackend(DictStore())) # in-memory
Function migrations receive the backend's context — the DB connection (SQL) or the store (KV) — so they can do whatever that backend allows.
Commands
m.migrate() # apply all pending
m.migrate(target="003_x") # apply up to (and including) an id
m.rollback() # undo the most recent
m.rollback(steps=3) # undo the last 3
m.status() # [(id, "applied"|"pending"), ...]
m.pending(); m.applied()
Tests
python -m unittest discover -s tests -v # 13 tests incl. real sqlite3 + drift
The Larz stack
Pure-Python, zero-dependency building blocks: larz · larzchain · larzmoney · larzcrypt · larzdb · larzagent · larzchart · larzmark · larztask · larzvault · larzvm · larzcache · larzvalidate · larzid · larzrpc · larzstate · larzhttp · larzconf · larzcron · larzlimit · larzlog · larzcli · larzretry · larztime · larzpdf · larzpack · larztemplate · larzcolor · larztable · larzjson · larzbus · larzmigrate
License
MIT © larz-scripter
Metadata
Release files for larzmigrate 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| larzmigrate-0.1.0.tar.gz | 7.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| larzmigrate-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / larzmigrate-0.1.0.tar.gz
| Download URL | larzmigrate-0.1.0.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e13762c3d822e5e1e2959e755e6c4150f4a52e003896e23cd29106ffb446679
|
|
BLAKE2b-256 checksum How to use checksums |
1948b2855c87a4458cc1cf9acc460a982881e014e0965ad6c7121e9807f19281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / larzmigrate-0.1.0-py3-none-any.whl
| Download URL | larzmigrate-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0772eac2183b977e9eee69c8762d4e7dd7d5a51f38dcfcbee076dd82d76785ba
|
|
BLAKE2b-256 checksum How to use checksums |
ab72a35910c7f329da42b14faa0d2f1325af8a50adba22c499e1a285a25c158a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for larzmigrate 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.