Skip to content

Starter project with FastAPI, Jinja2, SQLAlchemy, Alembic, PosgreSQL, Docker, Precommit, Github actions

Notifications You must be signed in to change notification settings

XDEVS-PRO/fastapi-jinja2-sqlachemy-starter

Repository files navigation

fastapi_starter

Features

  • FastAPI
  • SQLAlchemy and Alembic
  • Pre-commit hooks (black, autoflake, isort, flake8, prettier)
  • Github Action
  • Dependabot config
  • Docker images

Step 1: Getting started

Start a local development instance with docker-compose

docker-compose up -d

# Run database migration
docker-compose exec backend alembic upgrade head

# Create database used for testing
docker-compose exec postgres createdb apptest -U postgres

Now you can navigate to the following URLs:

Step 2: Setup pre-commit hooks and database

Keep your code clean by using the configured pre-commit hooks. Follow the instructions here to install pre-commit. Once pre-commit is installed, run this command to install the hooks into your git repository:

pre-commit install

Local development

The backend setup of docker-compose is set to automatically reload the app whenever code is updated.

Rebuilding containers

If you add a dependency, you'll need to rebuild your containers like this:

docker-compose up -d --build

Database migrations

These two are the most used commands when working with alembic. For more info, follow through Alembic's tutorial.

# Auto generate a revision
docker-compose exec backend alembic revision --autogenerate -m 'message'

# Apply latest changes
docker-compose exec backend alembic upgrade head

Backend tests

Backend uses a hardcoded database named apptest, first ensure that it's created

docker-compose exec postgres createdb apptest -U postgres

Then you can run tests with this command:

docker-compose exec backend pytest

Recipes

Build and upload docker images to a repository

Configure the build-push-action in .github/workflows/test.yaml.

Credits

Created with FastAPI Starter

About

Starter project with FastAPI, Jinja2, SQLAlchemy, Alembic, PosgreSQL, Docker, Precommit, Github actions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published