GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - uselessscat/fastapi-migrations: A small integration between Fastapi and Alembic.

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
fastapi_migrations
fastapi_migrations
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.md
README.md
 
 
poetry.lock
poetry.lock
 
 
pyproject.toml
pyproject.toml
 
 
setup.py
setup.py
 
 

Repository files navigation

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.

Notice

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.

Installation

You can install this library with:

pip3 install fastapi-migrations

Usage

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

Imagine your project folders

app/
    cli/
        __init__.py
        action.py
    db/
        __init__.py
        base.py
    models/
        __init__.py
        my_model.py
    endpoints/
        __init__.py
        my_endpoint.py
    __init__.py
    config.py
    main.py

This is an example of main.py:

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
app.include_router(router)

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

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

    cli()

Then your app/cli/__init__.py 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(action.app, name='action', help='Common actions the app do')

# this line adds the fastapi-migrations cli commands to our app
app.add_typer(MigrationsCli())

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

py app/main.py db show

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

The file app/cli/action.py can be like:

import typer
from fastapi_migrations import MigrationsConfig, Migrations

app: typer.Typer = typer.Typer()

@app.command()
def show() -> None:
    config = MigrationsConfig()

    migrations = Migrations(config)

    migrations.show()

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/main.py action show

License

This software is distributed under MIT license.

About

A small integration between Fastapi and Alembic.

Topics

alembicfastapimigrationpythonpython3sqlalchemyvscode

Resources

Readme
MIT license
Activity

Stars

24 stars

Watchers

5 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.