Skip to main content

Integrate Alembic with Flask.

Project description

Flask-Alembic

Flask-Alembic is a Flask extension that provides a configurable Alembic database migration environment. Supports Flask-SQLAlchemy, Flask-SQLAlchemy-Lite, or plain SQLAlchemy. Supports Alembic's single and multiple database templates.

Pallets Community Ecosystem

[!IMPORTANT]
This project is part of the Pallets Community Ecosystem. Pallets is the open source organization that maintains Flask; Pallets-Eco enables community maintenance of Flask extensions. If you are interested in helping maintain this project, please reach out on the Pallets Discord server.

Basic Usage

You've created a Flask application and some models with Flask-SQLAlchemy. Now start using Flask-Alembic:

from flask_alembic import Alembic

# Intialize the extension
alembic = Alembic()
alembic.init_app(app)

Commands are added to the flask CLI:

$ flask db --help
$ flask db revision "making changes"
$ flask db upgrade

You can also access Alembic's functionality from Python:

with app.app_context():
    # Auto-generate a migration
    alembic.revision('making changes')

    # Upgrade the database
    alembic.upgrade()

    # Access the internals
    environment_context = alembic.env

Differences from Alembic

  • Configuration is taken from Flask.config instead of alembic.ini and env.py.
  • Engines and model/table metadata are taken from Flask-SQLAlchemy(-Lite) if available, or can be configured manually.
  • The migrations are stored directly in the migrations folder instead of the versions folder.
  • Provides the migration environment instead of env.py and exposes Alembic's internal API objects.
  • Differentiates between CLI commands and Python functions. The functions return revision objects and don't print to stdout.
  • Allows operating Alembic at any API level while the app is running, through the exposed objects and functions.
  • Adds a system for managing independent migration branches and makes it easier to work with named branches.
  • Does not (currently) support offline migrations. I don't plan to work on this but am open to patches.
  • Does not (currently) support async engines. I don't plan to work on this but am open to patches.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_alembic-3.1.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

flask_alembic-3.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file flask_alembic-3.1.1.tar.gz.

File metadata

  • Download URL: flask_alembic-3.1.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for flask_alembic-3.1.1.tar.gz
Algorithm Hash digest
SHA256 358a0ad8f74e2969273a8d89feaf5842f65cc909064b51fde4b51415790d92f4
MD5 3193749fdba03b4d3abed3d94e4541bc
BLAKE2b-256 2f0884d5a3155bef151190bf665bc31389971daf9e82271086439bc8f8d3a7a5

See more details on using hashes here.

File details

Details for the file flask_alembic-3.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_alembic-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d0cda58518d4332d8563da555bee03107fe2169c7157f61a2e0759d0150209b
MD5 3c5555111de737a301d4a7a72bcc1d7d
BLAKE2b-256 07329ecc1df856fd6ba96276393d374c8e7592c89bc1e5861c1c66d6a81b68f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page