Example app using FastAPI, asyncio, SQLModel, Celery, Alembic and Supertokens
This is a small app that I built while learning Python and FastApi. It allows to create documentations (shared schemas + screenshots) from tracking events. It also serves as a backend for an interface that lets a user register, sign in, set some settings and view documentations.
While building this app, I spent the most time learning the best practices of accomplishing common tasks in the FastAPI ecosystem. I tried out various libraries and arrived at the following list that I think work well together:
Additionally, the codebase showcases the following things:
I took a ton of inspiration from the following articles and projects:
grillazz/fastapi-sqlalchemy-asyncpg
The ultimate async setup: FastAPI, SQLModel, Alembic, Pytest
The project is organized into the following directories and files:
Directory/File Name | Description |
---|---|
background_tasks/ | Celery tasks |
crud/ | CRUD operations |
db/ | Alembic migrations |
models/ | model files that combine data models and Pydantic schemas |
schemas/ | Pydantic schemas for things other than data models (e.g. api requests and responses) |
services/ | business logic |
subapps/ | FastAPI apps with each file containing a separate app |
utils/ | utility functions |
celery.py | Celery app |
config.py | Pydantic settings |
database.py | SQLAlchemy database engine and session |
dependencies.py | FastAPI dependencies |
main.py | main project file |
sqlalchemy.url
in alembic.ini
to point to your database.env.example
to .env
and fill in the valuesmake server
and make worker
to start the web server and the Celery workerIf you are using this project then pre-commit setup would be very helpful for checking your codebase. In short, pre-commit is a tool that allows developers to define and apply automated checks to their code before they commit it to a version control system. You can find more info here
pre-commit install
# for the first time, run on all files
pre-commit run --all-files
MIT License