Skip to main content

this_file: README.md

pypitrust

One command takes a GitHub repo from "has a pyproject.toml" to "pushing a v* tag publishes it to PyPI". No API token is stored anywhere: publishing uses PyPI Trusted Publishing (OIDC).

uv tool install pypitrust

pypitrust setup octo/my-pkg              # owner/name, a GitHub URL, or a local clone
pypitrust setup octo/my-pkg --dry_run    # show what would change
pypitrust setup octo/my-pkg --test_pypi  # rehearse on test.pypi.org
pypitrust setup repos.txt                # many repos, resumable
pypitrust upgrade ~/src/my-pkg           # write the release files into a clone
pypitrust workflow my-pkg                # print the workflow it would commit
pypitrust config                         # show the settings in effect

What setup does

  1. GitHub, through your logged-in gh CLI:
    • creates the deployment environment (default pypi);
    • commits .github/workflows/release.yml unless you pass --skip_workflow. An existing file is never overwritten; you get a warning if it lacks id-token: write.
  2. PyPI, through a real Chrome driven by playwrightauthor:
    • if the project exists, adds a trusted publisher in its Publishing settings;
    • if it doesn't, adds a pending publisher to your account, so the first release creates the project.
    • It's idempotent: a matching publisher is detected and left alone, and a new one is checked once PyPI lists it.

PyPI has no API for trusted-publisher settings (warehouse#14456), which is why a browser is involved. If PyPI asks you to log in or to confirm your password (its hourly sudo mode), do it in the window that opens, 2FA included. The tool waits, then continues. It never types your password. The browser profile keeps the session for later runs.

The release setup

pypitrust upgrade PATH writes these into a local clone and commits nothing:

  • .github/workflows/release.yml: on a v* tag push, or a manual dispatch with a tag input, the jobs run in order:
    1. create the tag (dispatch only);
    2. uv build from that tag, checking the built version matches it;
    3. create a GitHub Release with the files;
    4. publish to PyPI over OIDC from the protected environment.
  • publish.sh: picks the next patch tag (or takes vX.Y.Z) and dispatches the workflow.
  • build.sh: uv build, added only when missing.
  • .gitignore: gets the hatch-vcs version file (for example src/pkg/__version__.py), which is also untracked, so CI never builds a +dirty version.

It warns about other workflows that still publish with a token. Then run pypitrust setup OWNER/REPO --skip_workflow to register the publisher.

Versions come from git tags via hatch-vcs. Your pyproject.toml needs:

[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
dynamic = ["version"]

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "src/my_pkg/__version__.py"

Repos whose wheels are built on your machine (maturin, several packages per repo) use pypitrust upload-helper PATH instead. It adds scripts/pypi-upload.sh FILE..., which attaches the files to a draft GitHub release, dispatches .github/workflows/pypi-upload.yml and waits for the upload. Drafts create no git tag, so tag-derived versions stay put. Register that workflow with --workflow pypi-upload.yml.

Many repos at once

Give setup a text file instead of a repo. Each line holds one job, REPO [PACKAGE|-] [WORKFLOW], and # starts a comment:

octo/alpha                      # package name read from pyproject.toml
https://github.com/octo/beta beta
acme/gamma - pypi-upload.yml

Each job runs four steps: package, github_env, workflow, pypi_publisher. Every outcome goes into repos.txt.status.json (or the file --status names), so running the same command again skips finished steps.

  • A step skipped with --skip_pypi or --skip_workflow stays pending and runs on a later full run.
  • A failed step stops only its own job; --retry_failed tries it again.
  • PyPI registrations are spaced delay seconds apart.
  • PyPI rate-limits registrations. On a 429 the whole run pauses for cooldown seconds, records the pause in the status file and exits 75 (EX_TEMPFAIL). Before then, running it again does nothing.

Configuration

Settings come from the built-in defaults, then a TOML config file, then command-line flags. The first config file found wins: --config PATH, $PYPITRUST_CONFIG, ./pypitrust.toml, [tool.pypitrust] in ./pyproject.toml, and $XDG_CONFIG_HOME/pypitrust/config.toml (~/.config/...). Unknown keys and wrong types are errors. pypitrust.example.toml lists every key:

key default meaning
environment "pypi" GitHub environment the workflow publishes from
workflow "release.yml" workflow filename registered with PyPI
test_pypi false target test.pypi.org
profile "default" playwrightauthor browser profile
debug_port unset Chrome CDP port, when another Chrome already holds the default
login_timeout 300 seconds to wait for a manual login
action_timeout 30 seconds per browser action
delay 90 list runs: seconds between registrations
cooldown 3600 list runs: pause after a 429

Run-only flags: --package, --dry_run, --skip_pypi, --skip_workflow, --retry_failed, --status, --verbose.

Caveats

  • A pending publisher is void if someone else registers the name first, so register early.
  • When PyPI shows an error page, the tool stops and leaves the browser as it is, rather than retrying blindly.

Development

uv sync
uv run pytest
./build.sh            # version from the latest tag
./publish.sh          # release the next patch version

pypitrust releases itself with the setup it writes. CI runs ruff and the tests on Python 3.12 and 3.13.

Licence

Apache-2.0

Metadata

Release files for pypitrust 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypitrust 1.0.2
File Size Uploaded Provenance Actions
pypitrust-1.0.2.tar.gz 28.8 kB With provenance Details for pypitrust-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pypitrust 1.0.2
File Interpreter ABI Platform Actions
pypitrust-1.0.2-py3-none-any.whl Python 3 none any Details for pypitrust-1.0.2-py3-none-any.whl

Total release size: 58.5 kB

Release files / pypitrust-1.0.2.tar.gz

Download URL pypitrust-1.0.2.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
24cd52da3fc384dd2870aa0b80b87d6ed02ad1dab4da8f50a9c1f7ce8a717402
BLAKE2b-256 checksum
How to use checksums
80b540dbbb92af31256ca3dec86692ec8af162a6871f30c2f7802d1f6dd57c79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / pypitrust-1.0.2-py3-none-any.whl

Download URL pypitrust-1.0.2-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb0d1166d70711c53222ac6e7064b5428f738aec14f090db3791fb25edd5476d
BLAKE2b-256 checksum
How to use checksums
dfebf998779bae2e27b44e4fadbcb8182a426bbdbce3ba40e1c1705754a2f094
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for pypitrust 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pypitrust-1.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page