
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
python-package-template-pypi
Advanced tools
A GitHub template with my python package configurations.
To make sure that the all the tools are available in your virtual environment (and that you are running your code with its latest modifications), install the package in editable mode by running:
pip install --editable ".[dev]"
Alternatively, you can Dev Containers: Reopen in Container
in Visual Studio Code if Docker
is installed.
[!WARNING] This template represents my personal understanding of the current best practices.
It is advised to do further research before implementing these configurations in your environment.
Feel free to open a new issue if you have any questions or suggestions.
This template package relies on the synchronized cooperation of several exceptional tools.
These tools include:
For documentation:
Codecov is used to check the code coverage of the tests.
It also provides a badge that can be added to the README file.
Codecov is set up to be part of the tox reusable workflow, but for this action it is important to generate the coverage report. Currently it is achieved by adding --cov-report=xml:{work_dir}/artifacts/coverage.xml
as part of the tox.toml
configuration and uploading/downloading the results using GitHub Artifacts.
Pre-Commit is used to run certain checks on the code before it is committed.
These checks are defined in the .pre-commit-config.yaml
file.
To use pre-commit is has to be installed in the virtual environment and also added to the git hooks by running pre-commit install
.
In this repository pre-commit is set up for a number of general issues and to run formatting and linting checks with ruff
.
Call pre-commit by running:
pre-commit run --all-files
Python by default is a dynamically typed language, but being explicit about types can help to avoid bugs.
MyPy makes sure that the types are correct and consistent throughout the code.
The mypy
related settings are defined in the pyproject.toml
file.
In this repository MyPy is set up be strict
and it also checks for some additional issues.
Call mypy by running:
mypy src tests
Pytest is a modern testing framework for python.
It is way too complex to explain it here, but it runs all the tests from the tests
directory and also checks the code coverage.
Its settings are defined in the pyproject.toml
file.
Call pytest by running:
pytest
Ruff is a formatter and linter that is built on top of a lot of open source tools.
It is very fast and unifies all the useful code quality solutions into a single tool.
By default it is not too strict, but I like to make it strict by selecting all the available rules.
The exact configuration is defined in the ruff.toml
file.
If for some reason it makes sense not to comply with a certain rule, it can be disabled for that line using # noqa: <rule number>
.
Call ruff by running:
ruff check src tests
Tox is useful for running the above tools in isolated environments.
It makes sure that the package setup is consistent and that the tools are working as expected.
It can be used to test different python versions and different testing scenarios.
I am also using it to automatically generate the documentation and build the package.
In this repository tox is set up to use python 3.11, 3.12 and run codecov, pytest, ruff, mypy, docs and package building.
The settings are specified in the tox.toml
file.
Call tox by running:
tox
The documentation is built with Sphinx and it is hosted both on ReadTheDocs and GitHub Pages.
Both of these services are recommended, however ReadTheDocs requires a bit more setup.
The following settings are enabled in my repository settings:
Code/About:
General/Features:
General/Pull Requests:
Rules/Rulesets:
main
Target branches: Default
Squash
pre-commit.ci - pr
tox / tox (3.11)
tox / tox (3.12)
Pages/Build and deployment:
release
workflow.Add a new pending publisher:
python-package-template-pypi
(has to match the project name in pyproject.toml
)daniel-mizsak
python-package-template
release.yml
Currently I am using a reusable GitHub workflow to test and build the package (tox), and do the publishing with a separate "non-reusble" workflow, so that trusted publishing can be used.
I am trying to use this template in all of my repositories and also contribute back here with new best practices I find. Some of my other repositories that may be interesting to look at:
I have also integrated some of the above mentioned tools into my vscode
settings. You can find them in my more-than-just-dotfiles repository.
FAQs
A GitHub template with my python package configurations.
We found that python-package-template-pypi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.