Skip to main content

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

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):

  1. PyPI → Account settingsPublishingAdd a new pending publisher.
  2. Project name: ptr727-projecttemplate-library. Owner: ptr727. Repo: ProjectTemplate. Workflow: publish-release.yml. Environment: pypi.
  3. GitHub repo → SettingsEnvironments → create pypi environment (optionally with required reviewers).
  4. 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 (in pyproject.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.py ships with __version__ = "0.0.0" as a placeholder. The publish workflow uses skip-existing: true so the workflow won't fail on duplicate uploads — but no new versions will land on PyPI until you replace 0.0.0 with something that increments. Common options:
    • hatch-vcs — derive the version from git tags. Add it to [build-system].requires and switch [tool.hatch.version] to source = "vcs". Pairs well with tag-driven releases.
    • Read from version.json — the .NET side uses Nerdbank.GitVersioning which reads from version.json. A small custom Hatchling plugin or a CI step can pull the version into _version.py so .NET and Python ship with matching versions.
    • Manual bumps — edit _version.py in 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ptr727_projecttemplate_library-0.0.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file ptr727_projecttemplate_library-0.0.0.tar.gz.

File metadata

File hashes

Hashes for ptr727_projecttemplate_library-0.0.0.tar.gz
Algorithm Hash digest
SHA256 a846d97a436bb1a82e52d41debe218953a5ec4fd67480a0c4dbe225edb2f2b6b
MD5 49de2bd16efd88362ec875cb5fb721f7
BLAKE2b-256 33ed3d72b9f3e2ddf844043b8f69923aeb3c63ebbeb122c1bf0d52f25c75fdfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ptr727_projecttemplate_library-0.0.0.tar.gz:

Publisher: publish-release.yml on ptr727/ProjectTemplate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ptr727_projecttemplate_library-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ptr727_projecttemplate_library-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50ebe50d7f5c27bd68034d1c3e18e68374991d8ffaf08a798d671b3b3397b805
MD5 d44817758a8d5a84c967ce9c4824e732
BLAKE2b-256 e4b46332bc5f6845486b5208f1e50739372dd04144ece3d01556dcccf3988438

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page