Python PyPI template library — companion to the .NET NuGetLibrary in this template repo.
Project description
PyPiLibrary
Python PyPI template — companion to the .NET NuGetLibrary in this repo. Published to PyPI as ptr727-projecttemplate-library.
Stack
- Build backend —
hatchlingviapyproject.toml - Env / deps / publish —
uv(Astral) - Lint + format —
ruff - Type checker —
pyright - Tests —
pytest - Publish — PyPI Trusted Publishing via
pypa/gh-action-pypi-publish(no API token in repo secrets)
Layout
PyPiLibrary/
pyproject.toml
README.md
src/
ptr727_projecttemplate_library/
__init__.py
_version.py
example.py
tests/
__init__.py
test_example.py
Local Development
The repo's devcontainer installs uv automatically and runs uv sync for this project on first open. To work outside the devcontainer:
# from the repo root
cd PyPiLibrary
uv sync # creates .venv, installs deps + dev group
uv run ruff check # lint
uv run ruff format --check # formatting check
uv run pyright # type check
uv run pytest # tests
uv build # wheel + sdist into ./dist
Publishing
Releases are produced by .github/workflows/build-pypilibrary-task.yml (called from build-release-task.yml to build, lint, type-check, test, and upload the wheel + sdist as a workflow-run artifact). Publishing is a separate top-level publish-pypi job in publish-release.yml that downloads the artifact by name and runs Trusted Publishing — no PYPI_API_TOKEN secret is involved. The publish job has id-token: write only at that single job level, so the test-pull-request flow (which calls the same build task during PR validation) doesn't need to propagate that permission through the reusable workflow chain.
First-time setup (one-time, on PyPI):
- PyPI → Account settings → Publishing → Add a new pending publisher.
- Project name:
ptr727-projecttemplate-library. Owner:ptr727. Repo:ProjectTemplate. Workflow:publish-release.yml. Environment:pypi. - GitHub repo → Settings → Environments → create
pypienvironment (optionally with required reviewers). - The first successful release converts the pending publisher to a real publisher.
Template Adoption
When deriving a new project from this template:
- Replace the package name
ptr727-projecttemplate-library(inpyproject.toml, this README, and CI) with your name. - Rename
src/ptr727_projecttemplate_library/to your import name. - Re-register the trusted publisher on PyPI under the new project name.
- Wire up a versioning scheme before the first publish.
_version.pyships with__version__ = "0.0.0"as a placeholder. The publish workflow usesskip-existing: trueso the workflow won't fail on duplicate uploads — but no new versions will land on PyPI until you replace0.0.0with something that increments. Common options:hatch-vcs— derive the version from git tags. Add it to[build-system].requiresand switch[tool.hatch.version]tosource = "vcs". Pairs well with tag-driven releases.- Read from
version.json— the .NET side uses Nerdbank.GitVersioning which reads fromversion.json. A small custom Hatchling plugin or a CI step can pull the version into_version.pyso .NET and Python ship with matching versions. - Manual bumps — edit
_version.pyin each release PR. Simplest, but easy to forget.
If you don't want a Python project at all, delete the PyPiLibrary/ folder, the build-pypilibrary-task.yml workflow, the build-pypilibrary job in build-release-task.yml, the publish-pypi job in publish-release.yml, and the uv block in .github/dependabot.yml.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ptr727_projecttemplate_library-0.0.0.tar.gz.
File metadata
- Download URL: ptr727_projecttemplate_library-0.0.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a846d97a436bb1a82e52d41debe218953a5ec4fd67480a0c4dbe225edb2f2b6b
|
|
| MD5 |
49de2bd16efd88362ec875cb5fb721f7
|
|
| BLAKE2b-256 |
33ed3d72b9f3e2ddf844043b8f69923aeb3c63ebbeb122c1bf0d52f25c75fdfd
|
Provenance
The following attestation bundles were made for ptr727_projecttemplate_library-0.0.0.tar.gz:
Publisher:
publish-release.yml on ptr727/ProjectTemplate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ptr727_projecttemplate_library-0.0.0.tar.gz -
Subject digest:
a846d97a436bb1a82e52d41debe218953a5ec4fd67480a0c4dbe225edb2f2b6b - Sigstore transparency entry: 1510459821
- Sigstore integration time:
-
Permalink:
ptr727/ProjectTemplate@ffcb75467eb26a04ace2bb7acbe81c40493c7fc0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ptr727
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-release.yml@ffcb75467eb26a04ace2bb7acbe81c40493c7fc0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ptr727_projecttemplate_library-0.0.0-py3-none-any.whl.
File metadata
- Download URL: ptr727_projecttemplate_library-0.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50ebe50d7f5c27bd68034d1c3e18e68374991d8ffaf08a798d671b3b3397b805
|
|
| MD5 |
d44817758a8d5a84c967ce9c4824e732
|
|
| BLAKE2b-256 |
e4b46332bc5f6845486b5208f1e50739372dd04144ece3d01556dcccf3988438
|
Provenance
The following attestation bundles were made for ptr727_projecttemplate_library-0.0.0-py3-none-any.whl:
Publisher:
publish-release.yml on ptr727/ProjectTemplate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ptr727_projecttemplate_library-0.0.0-py3-none-any.whl -
Subject digest:
50ebe50d7f5c27bd68034d1c3e18e68374991d8ffaf08a798d671b3b3397b805 - Sigstore transparency entry: 1510459974
- Sigstore integration time:
-
Permalink:
ptr727/ProjectTemplate@ffcb75467eb26a04ace2bb7acbe81c40493c7fc0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ptr727
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-release.yml@ffcb75467eb26a04ace2bb7acbe81c40493c7fc0 -
Trigger Event:
push
-
Statement type: