This project is an opinionated boilerplate for FastAPI micro framework that uses, Asynchronous SQLAlchemy, PostgresSQL, Alembic, Celery, MongoDB, Redis, Docker and jwt Authentication. You can use this ready to use sample and don't worry about CI pipelines and running database migrations and tests inside a FastAPI project.
git clone https://github.com/payamt007/FastAPI-Toolkit
cd FastAPI-Toolkit/app
Then create new folder (for example artists) in app
directory
cd artists
Create __init__.py
file and a empty models.py
file inside folder
and paste this sample content inside models.py
file:
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import Mapped, declarative_base
Base = declarative_base()
class Artist(Base):
id: Mapped[int] = Column(Integer, primary_key=True)
name: Mapped[str] = Column(String, primary_key=True)
city: Mapped[str] = Column(String, primary_key=True)
go to migrations/env.py
folder in root directory and add this content to it:
from app.artists.models import Artist
then run new migration command in root directory:
alembic revision --autogenerate -m "added_artist_model"
alembic upgrade head
$ docker-compose up -d --build
$ curl -d '{"name":"ALen Fit", "artist":"Helen", "year":"2015"}' -H "Content-Type: application/json" -X POST http://127.0.0.3:8001/songs
$ docker compose exec api pytest