Skip to content

Light-it-labs/fastapi-template

Repository files navigation

FastAPI Tempalte

Auth Service in FastAPI

Install dependencies

  1. Install uv using the command below, or one of other the methods listed in the uv documentation

    brew install uv
  2. Install dependencies

    uv sync
  3. Activate the virtual environment

    source .venv/bin/activate

    [!TIP] If the virtual environment is not active in your shell, run commands inside it with uv run <command>

Run dockerized project

  1. Create .env

    cp .env.example .env
  2. Run with docker compose

    docker compose up --watch -d

Migrations

Migrations can be autogenerated running the scripts/generate_migrations.sh script on the api container:

docker compose exec api scripts/generate_migrations.sh <migration-name>

To apply the migration just restart the container, as the app runs migrations before starting.

Alternatively, you may run it manually with docker compose exec api alembic upgrade head. Other alembic commands can be run in the same way to manage migrations.

Tip

To avoid running the commands through the api container, map the db hostname to 127.0.0.1 by adding the following line to your /etc/hosts file:

127.0.0.1 db

Then you can use alembic directly in your shell, it will be able to find the db.

Linter and static type checker

We use ruff as linter and mypy as static type checker. To run them on pre-commit please run pre-commit install.

Tests

  • You can run tests locally by running ./tests-start.sh (this will use your local database).
  • Tests can also run in docker container with the following command: docker-compose exec api ./tests-start.sh.

Emails

For local development we use mailpit. With the application running, you can access it through localhost:8025 by default. If needed, the port can be configured via the FORWARD_MAILPIT_DASHBOARD_PORT env variable.

The email client is instantiated during app bootup in main.py via app.emails.set_client, and the EmailService will use that instance by default.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors