Databases & Storage

alembic

Version control for your database's structure, so changing it stops feeling like defusing a bomb.

Install it: pip install alembic

What does it do?

Alembic tracks and manages changes to a database’s structure over time — adding a new column, renaming a table, changing a data type — the same way a tool like version control tracks changes to code. Each change becomes a recorded, ordered step that can be applied or reversed, so a database can be reliably brought up to the exact structure a piece of software expects, whether that’s on a developer’s laptop or a live production server. Without it, teams would have to manually remember and apply structural database changes by hand, a process notorious for going wrong in exactly the situations where it matters most. It’s built specifically to work alongside SQLAlchemy, sharing its understanding of how the database is structured.

See it in action

This is an Alembic migration file describing one safe change to a database’s structure, adding an email column to a users table, plus instructions for undoing it if needed.

"""add email column to users

Revision ID: 0001
"""
from alembic import op
import sqlalchemy as sa

def upgrade():
    op.add_column("users", sa.Column("email", sa.String(), nullable=True))

def downgrade():
    op.drop_column("users", "email")

Why would a non-developer care?

Software changes constantly, and its underlying database structure usually has to change right along with it, but a database holding real, valuable data can’t just be deleted and rebuilt like code can. Alembic is what lets a company safely add a new feature that needs a new piece of data stored, without risking the data already there. That safety net is invisible when everything goes right, and painfully obvious in its absence when it doesn’t.

Real-world examples

Any Python-backed application using SQLAlchemy that has shipped more than one version to production is very likely using Alembic behind the scenes to manage those structural changes safely. Companies running live databases with millions of user records depend on tools exactly like this to add features without downtime or data loss. Without automated migration tracking, teams historically kept error-prone spreadsheets or text files tracking manual database changes, a practice that led to plenty of costly mistakes.

Who uses it

Backend developers and database administrators maintaining applications whose database structure needs to evolve safely over time.

How it compares to alternatives

Alembic is built specifically for SQLAlchemy, while Django ships its own separate, built-in migrations system for its own ORM. Flyway and Liquibase serve a similar purpose but are Java-based tools not tied to any particular language’s ORM. For any Python project already using SQLAlchemy, Alembic is effectively the default choice.

Fun fact

Alembic was created by Mike Bayer, the same person who created SQLAlchemy itself, specifically to solve the migration problem SQLAlchemy alone didn’t address.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries