Skip to main content


pylembic

📝 Overview

This package provides validation of Alembic migrations for Python projects.

It will check:

  • Linearity: Ensures a clean and predictable migration chain.
  • Circular dependencies: Prevents migration failures due to loops in the dependency chain.
  • Orphan migrations: Identifies migrations improperly created without linking to any other migration.
  • Multiple bases/heads: Identifies multiple bases or heads in the migration graph.
  • Branching: Detects branching in the migration graph.
  • Graph visualization: Provides a visual way to catch anomalies and understand the migration flow.

📦 Installation

You can install this package using pip:

pip install pylembic

⚙️ Usage

🧪 Testing

You can use this module with your preferred testing framework as follows:

from os import path

from pytest import fixture

from pylembic.validator import Validator


@fixture
def with_alembic_config_path():
    # We assume the migrations folder is at the root of the project,
    # and this test file is in the tests folder, also at the root of the project.
    # TODO: Feel free to adjust the path to your project's migrations folder.
    return path.abspath(
        path.join(path.dirname(path.dirname(__file__)), "migrations")
    )


def test_migrations(with_alembic_config_path):
    migration_validator = Validator(with_alembic_config_path)
    assert migration_validator.validate()

📊 Visualizing the migration graph

You can show the migrations graph by calling the method show_graph:

from os import path

from pylembic.validator import Validator

alembic_config_path = path.abspath(path.join("your path", "migrations"))

migration_validator = Validator(alembic_config_path)

migration_validator.show_graph()

💻 Command line interface

You can also use the command line for:

  • Validating migrations:

    pylembic ./path/to/migrations validate
    
  • Validating migrations with branch detection:

    pylembic ./path/to/migrations validate --detect-branches
    
  • Visualizing the migration graph:

    pylembic ./path/to/migrations show-graph
    

CLI is implemented using typer, so you can use the --help flag to get more information about the available options in every command.

  • Show general help:

    pylembic --help
    
  • Show help for a specific command:

    pylembic validate --help
    

⚠️ Caveats

📦 Using project imports in migrations

When you are using the command line interface to validate the migrations and you have specific imports from your project in the migrations, you will probably need to add the path to your project to the PYTHONPATH environment variable. Otherwise, the command line interface will not be able to find the modules.

🤝 Contributors

Contributions are welcome! Please feel free to submit a Pull Request.



📧 Contact

(c) 2025, Created with ❤️ by Marco Espinosa

Release files for pylembic 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylembic 0.9.0
File Size Uploaded
pylembic-0.9.0.tar.gz 75.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylembic 0.9.0
File Interpreter ABI Platform
pylembic-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 84.9 kB

Release files / pylembic-0.9.0.tar.gz

Download URL pylembic-0.9.0.tar.gz
Size 75.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a89076ea5d2074bd84c414d0fe1121411928671de6c0c5d4e418d6330d5f0616
BLAKE2b-256 checksum
How to use checksums
6f211add0684caa37d90cd6d6a6df0e91bf117520057e8c5ee9656815c052dc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pylembic-0.9.0-py3-none-any.whl

Download URL pylembic-0.9.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1c4a6b5e7e0730c59d0374e8dc23869c098aec975a37b4e2e76e24bfd913854
BLAKE2b-256 checksum
How to use checksums
a8dd5d2e6742569b050f711947763a3828e7cb6ed279894925df97bcde408502
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page