A template repository for modern python package development with uv using Pydantic and Polars. Linted with ruff, type checked with ty and pyright, and tested with pytest using GitHub Actions.
- Replace
YOURUSERNAMEandIMAGENAMEin.github/workflows/docker-image.yml[or delete file]. - Replace test data in
datawith your own data [or delete if you don't have test data]. - Adjust
.gitignoreaccording to your needs. - Setup your
CITATION.cffaccording to your needs [or delete file]. - Update attribution in
Dockerfileand write image instructions. - Replace copyright name in
LICENSE. - Update attributions and package configuration in
pyproject.toml. - Update attributions and write your package in
src/name_of_your_package. - Update attributions and write tests in
tests/. - Add your requirements via
uv add. - Document your code using the numpydoc style and Sphinx:
- Adjust the configuration to your needs in
docs/conf.py. - Automatically via GitHub Actions:
- In the file
.github/workflows/gh-pages.ymlin line55replacesrc/python_pkg_templatewithsrc/name_of_your_package. For example, the full line should read as:uv run sphinx-apidoc -f -o docs src/name_of_your_package
- In the repository go to
Settings➡️Pages➡️Build and deployment➡️Source➡️GitHub Actions. - Select the
gh-pages.yml/Deploy Documentation to Pagesworkflow.
- In the file
- Or build manually:
- Install documentation dependencies via:
uv sync --group docs
- Build documentation with:
which eventually should be replaced with
uv run sphinx-apidoc -f -o docs src/python_pkg_template
and then runuv run sphinx-apidoc -f -o docs src/name_of_your_package
uv run sphinx-build -b html docs html
- Publish documentation [optional]!
- Serving with GitHub pages needs the addition of an empty
.nojekyllfile to your/html.
- Install documentation dependencies via:
- Adjust the configuration to your needs in
- Decide on a type checker and delete the other!
- Adjust this
README.mdto your needs!
Please consider reading the Python Packaging User Guide!
Important
In order to publish your python package you need to create an account on PyPI and ideally also TestPyPI for staging.
- Setup trusted publishing.
- Replace
<NAME-OF-YOUR-PACKAGE>with the name of your package in- ...line
37of.github/workflows/publish-testpypi.yml. - ...line
37of.github/workflows/publish-pypi.yml. - ...line
28of.github/workflows/test-testpypi.yml. - ...line
28of.github/workflows/test-pypi.yml.
- ...line
Whenever you have a new version of your package ready, go to the Actions tab in your GitHub repository and run the following workflows:
- Run
Publish Python Package to TestPyPI(workflow file:publish-testpypi.yml). - Check that the workflow successfully completes!
- Run
Run tests on package from TestPyPI(workflow file:test-testpypi.yml). - Check that the workflow successfully completes!
- Run
Publish Python Package to PyPI(workflow file:publish-pypi.yml). - Check that the workflow successfully completes!
- Run
Run tests on package from PyPI(workflow file:test-pypi.yml). - Check that the workflow successfully completes!
- Done! Your package was successfully published to TestPyPI and PyPI!
Note
You can omit TestPyPI but staging is generally good practice!
- uv:
- Add a dependency/package [
pkg]:uv add pkg
- Upgrade dependencies/packages:
uv lock --upgrade
- Update environment:
uv sync
- Run python:
uv run python
- Run a package script (with arguments):
uv run battle -h
- Add a dependency/package [
- ruff:
- Check and fix (fixable) errors:
uv run ruff check --config ruff.toml --fix
- Check (with explicit config file):
uv run ruff check --config ruff.toml
- Format code:
uv run ruff format
- Format (with explicit config file):
uv run ruff format --config ruff.toml
- Check and fix (fixable) errors:
- ty:
uv run ty check --config-file ty.toml
- pyright:
uv run pyright --warnings
- pytest:
uv run pytest -c pytest.ini --durations=10 --durations-min=1.0 tests/
- Help for this template:
- Contact: micha.birklbauer@gmail.com
Important
The below sections should be adjusted and updated by you!
If you are using PLACEHOLDER please cite:
Very important title
Important Author, and Another Important Author
Journal of Cool Stuff 2023 12 (3), 4567-4589
DOI: 12.3456/cool-stuff