Bake your Python projects to perfection.
A basic Python project template for Cookiecutter.
To see what a project generated with this template looks like, check out crustypy-instance.
Requires cruft.
Note
Install cruft with the optional pyproject extra, e.g. uv tool install 'cruft[pyproject]'.
cruft create https://github.com/MicaelJarniac/crustypyOr without installing it:
uvx --from 'cruft[pyproject]' cruft create https://github.com/MicaelJarniac/crustypyCookiecutter can also be used, but it'll result in fewer features.
uvx cookiecutter gh:MicaelJarniac/crustypyBefore the first push, create the lockfile and commit it:
uv lock
git add uv.lockTo publish to PyPI, add a trusted publisher for workflow ci.yml and environment pypi.
Important
Fill in the environment. PyPI marks it optional, but without it every job in ci.yml could publish, not just the release job.
Then, under Settings → Environments → pypi, limit deployment branches to main (and rc if you use it).
The release job pushes the version bump and changelog straight to the release branch, as github-actions[bot] with the workflow's GITHUB_TOKEN. GitHub doesn't let you add that token to a ruleset's or branch protection's bypass list, so on the release branches:
- Rules that only block force pushes and deletions are fine.
- Rules that require a pull request or passing status checks reject the release push, and the release fails before tagging. To keep them, release with a GitHub App token whose app is on the bypass list instead of
GITHUB_TOKEN.
With cruft, run cruft update and review the diff. Some updates need manual steps on GitHub or PyPI; they're listed below, newest first.
[tool.cruft] skip used to list all of tests, so template changes to tests/test_changelog.py never reached existing projects. It now lists only the example test. cruft reads the skip list from your project before updating, so the first cruft update after this one is the first to touch tests/test_changelog.py.
semantic-release.yml and codecov_action.yml are gone. Releasing and the Codecov upload are now jobs in ci.yml, and publishing runs in a pypi environment. Before the first release after updating:
- On PyPI, edit the project's trusted publisher (Manage → Publishing): set the workflow to
ci.ymland the environment topypi. - On GitHub, create the
pypienvironment (Settings → Environments) and limit its deployment branches to the release branches. - Delete
.python-versions(Nox now reads the versions from the classifiers) anddocs/wordlist.txt(replaced by typos) if cruft left them behind. - If
docs/CHANGELOG.mdconflicts, keep your release history and put<!-- version list -->on the line right under the title. - Run
uv lock --upgrade. A plainuv lockkeeps old pins that predate Python 3.15 (an oldtyping_extensionsbreaks pytest there).
Until step 1 is done, the release job tags and creates the GitHub release, but the PyPI upload fails.