Example FastAPI project with Picodi DI library
2.0K
Example FastAPI project with Picodi integration.
Picodi is a Python DI inspired by FastAPI’s dependency injection system, but it’s a standalone library that can be used in any Python application.
This project is an example of how to use Picodi with FastAPI. Although the project is the FastAPI example, you can use Picodi in any Python application.
This is example of simple weather API with user authentication. Please note that this project is not example of best practices in FastAPI development, but rather an example of how to use Picodi with FastAPI.
poetry install
poetry run uvicorn --factory app.api.main:create_app --host=0.0.0.0 --port=8000
docker run --rm -p 8000:8000 yakimka/picodi-fastapi-example:latest
You can see all available CLI commands in picodi_app.cli module.
To run the CLI command, use the following:
python -m picodi_app.cli <command> # you must be in active virtual environment
The project is divided into several parts:
picodi_app - the main package of the project.picodi_app.conf - application configuration.picodi_app.cli - the CLI commands.picodi_app.deps - Picodi dependencies.
DB connections, http clients, all dependencies
that can be used not only in HTTP-related code but in any part of the application
like CLI commands or background workers.picodi_app.api - the FastAPI application. All FastAPI-related code is here.picodi_app.api.fastapi-deps - FastAPI dependencies. This is FastAPI\HTTP related dependencies.picodi_app.data_access - the data access layer.
All interactions with the database and external services are here.picodi_app.user, picodi_app.weather - "business logic" modules.
Usually this code is in the domain package,
but I decided to put it in the root package for simplicity.You can read all code file by file,
or you can cherry-pick some parts of the code related to Picodi integration.
This parts of code are marked with comments like # Picodi Note:.
docker compose up -d redis
make test
This project was generated with yakimka/cookiecutter-pyproject.
Content type
Image
Digest
sha256:8cb62cbaf…
Size
55.9 MB
Last updated
about 1 year ago
docker pull yakimka/picodi-fastapi-example