Skip to main content

A small integration between Fastapi and Alembic.

Project description

Fastapi Migrations

PyPI PyPI - Python Version PyPI - License

GitHub last commit GitHub commit activity GitHub issues GitHub pull requests

This library provides a small wrapper for alembic.


Under inital development. This can not be ready-for-production library.

This can means:

  • Breaking changes may be introduced
  • Poor documentation and changeslogs
  • Not totally tested
  • Be forced to navigate through the source code to find out how it works

Wait to a version > 0.1.0 for usage in production environments.


You can install this library with:

pip3 install fastapi-migrations


You can use both programatically and by CLI (command line interface).

Imagine your project folders


This is an example of

from fastapi import FastAPI
from fastapi_sqlalchemy import DBSessionMiddleware

# Load configs and endpoints
from app.config import settings
from app.endpoints import router

app: FastAPI = FastAPI(title=settings.project_name)

# register routes

# add middlewares
app.add_middleware(DBSessionMiddleware, db_url=settings.database_uri)

if __name__ == '__main__':
    # Load cli commands
    from app.cli import app as cli


Then your app/cli/ can be like:

import typer

from fastapi_migrations.cli import MigrationsCli
import app.cli.action as action

# main cli app
app: typer.Typer = typer.Typer()

# these are our cli actions
app.add_typer(, name='action', help='Common actions the app do')

# this line adds the fastapi-migrations cli commands to our app

Now you can call your app from the command line and use fastapi-migrations like:

py app/ db show

If you want to use this library programatically, this is an example:

The file app/cli/ can be like:

import typer
from fastapi_migrations import MigrationsConfig, Migrations

app: typer.Typer = typer.Typer()

def show() -> None:
    config = MigrationsConfig()

    migrations = Migrations(config)

You can add this lines where you wish in your proyect. Here we ar adding it to a command line so we can call our app like:

py app/ action show


This software is distributed under MIT license.

Project details

Download files

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

Files for fastapi-migrations, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size fastapi_migrations-0.0.5-py3-none-any.whl (8.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size fastapi-migrations-0.0.5.tar.gz (9.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page