This repository is a batteries included starter project template for the FastAPI framework with the following features:
- Multi-worker hosting with Gunicorn
- Azure AD OpenID Connect user authentication and role-based authorization
- OpenTelemetry monitoring with Azure Application Insights integration
- Rate limiting with SlowApi
- SQL Database integration with SQLAlchemy 2.0 and asyncpg
- Docker container packaging
- Python 3.11 (can be installed from the Windows Store)
- Python Poetry package manager.
- Docker Desktop
- PowerShell
If you are using Visual Studio Code, install the recommended extensions.
Run the Setup Script to install the project dependencies.
This will also create a Python virtual environment you can activate using the activate
scripts in the venv scripts folder.
Make sure to update your editor settings to use the virtual environment to enable linting and autoformatting!
Update or create an ./.env file containing your local environment settings.
The following settings are required to start the application.
TENANT_ID= # Your Azure AD Tenant ID
API_CLIENT_ID= # The Azure AD Application ID used by your API
OPENAPI_CLIENT_ID= # The Azure AD Application ID used by the OpenAPI frontend
You can find additional configuration options in the config.py file.
Run the following docker command or use the tasks to setup your local docker environment.
docker compose -f docker-compose.debug.yml up -d
After the containers are running you will be able to attach the debugger to the API and set breakpoints using the Python: Remote Attach launch configuration. The Python debugger will be listening on port 5678
.
You can open your browser at localhost:5050 to connect to your local database using pgAdmin with the following credentials.
Username: admin@pgadmin.org
Password: admin
The default database is main
. To connect to the pre-configured postgres server use the following credentials.
Username: postgres
Password: postgres
Create automatic revisions from your SQLAlchemy ORM models.
alembic revision --autogenerate -m "Descriptive Message"
Migrations will automatically be applied on the next application start or can be manually applied using the following command.
alembic upgrade head