Skip to content

Minimal FastAPI application with SQL Alchemy and async tests setup

License

Notifications You must be signed in to change notification settings

execreate/fastapi-template

Repository files navigation

FastAPI template

A simple starting point for your FastAPI application.

Features

  1. Pipenv for dependency management. Simply run pipenv install --dev to install get started.
  2. Docker compose for local development and testing
  3. SQLAlchemy for ORM (uses async engine) and Alembic for database migrations
  4. Simple authentication for docs page
  5. CRUD operations generic class with pagination
  6. Support for API versioning (https://api.yourdomain.com/v1/)
  7. Async testing suite with Pytest

Start coding

Just click on that green Use this template button to start coding. There is a dummy app that is already implemented for you so that you can quickly learn how to use the CRUD factory.

Make sure to mark the app/ folder as source in your IDE otherwise you'll get import errors. And since all your code (except tests) lives inside app/ folder, you should import modules like this:

from core.config import settings

and NOT like this:

# this will throw an error!
from app.core.config import settings

Local setup

The following command will run a PostgreSQL database on your docker engine:

docker compose -f docker-compose-local.yml up -d

so that you can do

cd app; uvicorn main:app

or

ENVIRONMENT=test pytest

If you just want to build a docker container with your app and run it, just run:

docker compose up -d

Auto-generated docs

If you run the code without any changes, you'll find the documentation page here. The default username is docs_user and the password is simple_password.

About

Minimal FastAPI application with SQL Alchemy and async tests setup

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published