asyncpg-trek
A simple migrations system for asyncpg
What it is and what it does
asyncpg-trek is a lightweight migration tool for developers using asyncpg who want to write migrations as raw SQL or Python rather than adopting a heavier framework. It scans a folder you designate for migration files, tracks which ones have been applied to your database, and executes the necessary migrations to reach a target version—either upgrading, downgrading, or doing nothing if already at the target.
The library is API-centric rather than CLI-driven: you write the code that calls it, controlling how the database connection is created and when migrations run. This makes it straightforward to integrate into tests, Docker entrypoints, admin endpoints, or application startup routines. It requires Python 3.8 or later and depends only on typing_extensions at runtime.
Use it for:
- Running migrations on application startup by specifying a hardcoded target revision for simple deployments.
- Wrapping migrations in a custom CLI or admin HTTP endpoint to manage schema changes in complex systems.
- Executing migrations in test fixtures to ensure a clean, versioned schema for each test run.
- Downgrading to a previous schema version when rolling back a deployment.
- Integrating migrations into a Docker image entrypoint for containerized applications.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Manages database migrations for asyncpg by executing raw SQL or Python files in a specified folder, with async support and declarative version targeting.
Yes, if you use asyncpg and prefer raw SQL migrations without the overhead of SQLAlchemy/Alembic. The low install friction, permissive license, and straightforward API make it a reasonable choice for projects that fit its design. However, the Alpha status and lack of updates since July 2024 mean you should verify that it handles your specific migration patterns and be prepared to maintain it yourself if issues arise.
Install
asyncpg-trek on PyPI
pip
pip install asyncpg-trekuv
uv add asyncpg-trekpoetry
poetry add asyncpg-trekInstalling asyncpg-trek
Before you install
Low install friction with a single runtime dependency (typing_extensions). The package is in Alpha status and has not been updated since July 2024, though the repository remains active.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
from pathlib import Path
import asyncpg
from asyncpg_trek import plan, execute, Direction
from asyncpg_trek.asyncpg import AsyncpgBackend
MIGRATIONS_DIR = Path(__file__).parent / "migrations"
async def migrate(conn: asyncpg.Connection, target_revision: str) -> None:
backend = AsyncpgBackend(conn)
async with backend.connect() as conn:
planned = await plan(conn, backend, MIGRATIONS_DIR, target_revision=target_revision, direction=Direction.up)
await execute(conn, backend, planned)
Requires Python 3.8 or later and an existing asyncpg connection to a PostgreSQL database.
Verify before relying
- Whether the package handles complex migration scenarios like rollbacks, dependencies between migrations, or conflict resolution.
- Performance characteristics when managing large numbers of migrations.
- Community adoption and whether issues are actively addressed beyond the original author.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4,>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing_extensions |
| Maintenance | aging — 756 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 250,166/month — #8,637 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: asyncpg_trek-0.4.0-py3-none-any.whl
Keywords: asyncpg, postgres, postgresql, migrations
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
asyncpgasyncpg is an asyncio-native PostgreSQL client…
permissive · top 1,000 on PyPI
databasesProvides async database access for PostgreSQL,…
permissive · top 5,000 on PyPI
django-pg-zero-downtime-migrationsProvides a Django database backend for…
permissive · top 15,000 on PyPI
pysqlsyncSynchronize database schemas and bulk-load data…
permissive · top 15,000 on PyPI
yoyo-migrationsYoyo-migrations is a database schema migration…
permissive · top 15,000 on PyPI
atlas-provider-sqlalchemyConnects SQLAlchemy models to Atlas to…
unclear · top 15,000 on PyPI
alembicAlembic generates and manages database schema…
permissive · top 1,000 on PyPI
clickhouse-migrationsApplies versioned SQL migrations to ClickHouse…
permissive · top 15,000 on PyPI
migramigra compares PostgreSQL database schemas and…
permissive · top 15,000 on PyPI
piccoloPiccolo is an async-first ORM and query builder…
permissive · top 15,000 on PyPI