Git Product home page Git Product logo

fastapi-app's Introduction

FastAPI App

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:

  • FastAPI + Asyncio
  • SQLModel for data models and validation
  • Celery for background tasks
  • Alembic for migrations
  • Supertokens for user authentication
  • Mypy for type checking
  • Make for running commands

Additionally, the codebase showcases the following things:

  • Multiple FastAPI apps in one project
  • Alembic auto-generating migrations from model files
  • Celery tasks communicating through an SQS FIFO queue
  • AWS S3 integration for storing images
  • Loggers that print SQL queries and other useful information
  • Error handler middlewares
  • CORS middleware
  • Two separate types of authentication (static auth token for an internal endpoint + Supertokens for user authentication)
  • Project dependencies using requirements.txt
  • And more.

Inspiration

I took a ton of inspiration from the following articles and projects:

Abstracting FastAPI Services

grillazz/fastapi-sqlalchemy-asyncpg

The ultimate async setup: FastAPI, SQLModel, Alembic, Pytest

Project structure

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

Running the project

Prerequisites

  • Python 3.10
  • Supertokens account
  • GitHub OAuth app (SuperTokens uses GitHub OAuth but that can easily be changed for another OAuth provider)
  • AWS Account, an S3 bucket and an SQS queue
  • PostgreSQL database

Steps

  1. Clone the repo
  2. Change sqlalchemy.url in alembic.ini to point to your database
  3. Use commands in Makefile to install dependencies and run migrations
  4. Rename .env.example to .env and fill in the values
  5. Run make server and make worker to start the web server and the Celery worker

License

MIT License

fastapi-app's People

Contributors

petrgazarov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.