/fastapi-service-template

A template for a backend service using FastAPI + SQLAlchemy

Primary LanguagePythonApache License 2.0Apache-2.0

FastAPI Service Template

Requirements

  • Python 3.10+
  • MySQL 5.7+
  • Poetry

Installation

Clone the project

git clone git@github.com:ducminh-phan/fastapi-service-template.git
cd fastapi-service-template

Set up virtual environment

pyenv local 3.10.9
pyenv exec python3 -m venv venv
source ./venv/bin/activate

Install dependencies

poetry install

Setup database

Create a database

mysql -u root -p
mysql> CREATE DATABASE fastapi_template_development;
mysql> exit

In .env file (create one if it doesn't exist), add database uri

SQLALCHEMY_DATABASE_URI=mysql+aiomysql://root:123456@127.0.0.1/fastapi_template_development

Then upgrade database

alembic upgrade head

Install pre-commit hooks

  • Install pre-commit: https://pre-commit.com/ (should be installed globally)

  • Install pre-commit hooks:

    make install-git-hooks

Running

Inside the virtual environment, run

make run

Run tests

Inside the virtual environment, run

make test