FastAPI base code with modern Python & FastAPI pattern and Dependency Injection pattern with following 3 Layer Architecture.
Leveraged techniques described below
- Python 3.12
- Package Manager: uv
- Framework: FastAPI
- Application Command: Typer
- Dependency Injection System: python-dependency-injector
- Docker
- Code Linter: Pre Commit
- Database: MySQL 8.0+
- ORM: SQLAlchemy 2.0 with fully Asynchronous Support
- Migration Tool: Alembic with async base
- Database Driver: Aio-MySQL
- Management: SQLAdmin
- JWT Base Authorization
- SignIn/SignUp
- User List/Retrieve (Only superuser or staff)
role_granted_user
defined inapps.core.auth.context
This base code grants special privileges only to users marked as superuser or staff, allowing them to access specific endpoints and manage the application (e.g., the admin page). To create a superuser, you can use the pre-built command included in this application, available through both make and the Python module run command.
# Use make
make create-superuser
# Python module run command
python -m apps.commands.create_superuser
Execution Example
Check out the README.md for more information on the pre-built commands in this application.
This base code provide model admin page with SQLAdmin
.
Admin page access requires a user account with superuser or staff privileges. Users without either of these cannot log in.
- Endpoint:
/admin
In this base code, Swagger is protected with authentication. Swagger page access requires a user account with superuser or staff privileges. Users without either of these cannot log in.
- Endpoint:
/docs/swagger
Refer to ReadMe.md in apps.core
make run
starts the application with Uvicorn, using uvloop as the event loop. This provides better performance compared to the default asyncio event loop.
Start the project with Docker using:
docker compose up -d
docker compose down
-
Setup Local Environment including uv install
make setup
-
Make migrations
make migration m="(migration message required)"