Python project, you will need to have Python installed on your machine. You can download the latest version of Python from the official website or using your Operating system's package manager. This project requires Python 3.9 or higher.
I'd recommend using pyenv to manage your Python installations, the pyenv-installer works for Linux and Mac OS X. For Windows, you can use the pyenv-win port. See here for installation instructions.
uv
by following the instructions on their website.uv
can be used to actually install Python, even if you do not have it installed locally (either by system, pyenv or similar).
For example, to install Python 3.12 using uv
, you can run the following command:
uv python install 3.12
If you already have a Python version installed, uv will use this.
Tip
If you don't want to have uv
installed globally for any reason, there is an auto-generated requirements-dev.txt
file in the root of the project. You can use this to install the dependencies using pip
:
$ pip install -r requirements-dev.txt
However, if you are going to be contributing to the project, uv
is strongly recommended as this is what we use internally and in the CI.
Before you start contributing, please make sure you have read and understood our Code of Conduct and License.
To get started, follow these steps:
git checkout -b my-new-feature
.git commit -am 'Add some feature'
.git push origin my-new-feature
.Run the following command to install the required dependencies:
uv sync
You then need to activate the virtual environment:
source .venv/bin/activate
If you are using Windows, you can activate the virtual environment using the following command instead:
.venv\Scripts\activate
From here you can start working on the project. If you are using an IDE such as VSCode or PyCharm, you can set the use their Python interpreter setting to use the virtual environment that has just been created.
I am quite strict about linting and code formatting and have set up a number of pre-commit hooks and tasks to ensure that the code meets the required standards.
We are using Ruff for linting and formatting. These are set up as pre-commit hooks and can be run as below. You can also use the poe ruff
and poe format
commands to run these manually.
All code must pass mypy
checks. This can be run manually using the poe mypy
and is part of the pre-commit hooks.
Please install this if you are intending to submit a PR. It will check commits locally before they are pushed up to the Repo. The GitHub CI runs the linting and mypy checks, and will fail if there are any errors.
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
This will ensure that all code meets the required linting standard before being committed.
You can run these checks manually on all staged files using the below command :
poe pre
We are using pytest for testing.
If you add any new features, please add tests for them. This will help us to ensure that the code is working as expected and will prevent any regressions.
GitHub Actions will run the tests on every commit and PR, failing tests will block the PR from being merged, as will any major drop in test coverage.
There is a task set up to run tests:
$ poe test
You can also run the tests manually using the following command:
$ pytest
The task is set up so we can automatically add other options in the future. Notice that both these commands will run the tests with the --cov
option and show the coverage report at the end.
The changelog is automatically generated, using this project, so please do not edit it manually.
For maintainers, there is a POE task that will run this and update the changelog file.
$ poe changelog
You would also need to add a GitHub Personal Access Token to a local config file as usual. See the section in the Documentation for information.
However, you should NOT include a change to the CHANGELOG.md
file in any Pull Requests. This will be handled by the maintainers when a new release is made. Your GitHub username will be added to the changelog automatically beside your PR.
There are a few other convenience tasks that can be run using the poe
command. These are defined in the pyproject.toml
file.
Each of these tasks can have extra options added which will be passed to the underlying tool.
Run mypy
on the code base in strict mode:
$ poe mypy
Format the code using ruff format
:
$ poe format
Lint the code using ruff
:
$ poe ruff
Check the Markdown:
$ poe markdown
Run ruff
, mypy
, format
and markdown
at the same time:
$ poe lint
These are to help with developing and updating the documentation.
poe docs:serve
- Serve the MkDocs locally for testing and developmentpoe docs:serve:all
- Same as above, but opens to all interfaces so you can view it on other devices on your networkpoe docs:build
- Build the MkDocs site into the dist
folderpoe docs:publish
- Publish the docs to your GitHub pages. Note that only those with write-access to this repo can do this.Here are some guidelines to follow when contributing to fastapi-template
:
pyproject.toml
file. This will be done by the maintainers when a new release is made.If you are using VSCode, there is a config file in the .vscode
folder that will help you to follow these guidelines. You may need to install some extensions to get the most out of it. I'll add a list of recommended extensions here soon. The Python
and Ruff
ones are very helpful (the included .vscode
folder helps configure these).
If you have any questions or need help with contributing, please contact me @seapagan on GitHub. You can also use the GitHub Discussions feature.
Happy contributing!