The only dependency required to use this template is poetry. The recommended method to install it is through pip.
$ pip3 install poetry
$ poetry config virtualenvs.in-project true
Remember to commit to the repo the poetry.lock
file generated by poetry install
.
The virtual environment is automatically created and activated via poetry.
$ cd to-project-path
$ poetry install
To make sure everything is set up correctly, run the following command which must show the virtual environment path:
$ poetry show -v
If still having problems, you can run source
command to enable the virtual environment from the shell:
$ poetry show -v
Using virtualenv: /home/<User>/<path>/taller2/fastapi-template/.venv
$ source .venv/bin/activate
Check the full poetry docs, but here goes a quick reminder,
poetry add <dependency> [--dev]
This template follows PEP8.
For this purpose, we use:
- black: an opinionated code formatting tool
- flake8: a tool to enforce style guide
- pylint: a source code, bug and quality checker
Linters
flake8 && pylint <module_name>
Formatter
black .
- Development:
uvicorn src.main:app --reload
- Production:
uvicorn src.main:app
- Production Container:
docker-compose up -d
Documentation will be automatically generated at {app}/docs
We use the pytest framework to test. The easiest way to run tests is pytest
.
Remember to create functions with a name that starts with test_
(this is standard pytest conventions).
A few pipelines have been set to run on github actions to ensure code quality and deployment.
- Run Linter
- Run Tests
- Upload Test Coverage
- Deploy to Heroku using docker image
The pipeline automatically generates a coverage report and uploads it to codecov
You'll need to set the following actions secrets:
CODECOV_TOKEN
: Repo Token. Can be obtained on codecov when setting up or on settings
You'll need to set the following actions secrets:
HEROKU_APP_NAME
: App nameHEROKU_EMAIL
: Account emailHEROKU_API_KEY
: Account API key
The heroku Dockerfile includes the DataDog agent. Create a new DataDog API Key from here. Also, you need to set the following config vars in Heroku (you can use Heroku CLI if you want):
DD_API_KEY=<api_key_from_datadog>
DD_DYNO_HOST=false
HEROKU_APP_NAME=<app_name>
DD_TAGS=service:<meaningful_tag_for_datadog>