skillfed

asyncpg-trek

A simple migrations system for asyncpg

asyncpg-trek v0.4.0 250.2K downloads/30d#8,637 on PyPI13
Permissive license MIT AGING released

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-trek

uv

uv add asyncpg-trek

poetry

poetry add asyncpg-trek

Installing 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

Development Status :: 3 - AlphaEnvironment :: Web EnvironmentFramework :: AsyncIOIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Typing :: Typed

Tags

asyncpg migrationspostgres migrations asyncsql migrations asyncpgdatabase schema versioningasync database migrationsraw sql migrationsasyncpg schema management
asyncpgmigrationspostgres

More Database packages