Auth Service in FastAPI
-
Install uv using the command below, or one of other the methods listed in the
uvdocumentationbrew install uv
-
Install dependencies
uv sync
-
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>
-
Create
.envcp .env.example .env
-
Run with
docker composedocker compose up --watch -d
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.
We use ruff as linter and mypy as static type checker. To run them on pre-commit please run pre-commit install.
- 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.
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.