repomatic.pypi module¶
PyPI API client for package metadata lookups.
Domain-specific query functions, over the shared client of repomatic.http,
used by repomatic.lint_changelog (release dates, yanked status),
repomatic.deps.pins (release candidates),
repomatic.deps.report (source repository discovery for release notes)
and repomatic.init.local_edits (the wheel of a release).
Also the home of what counts as the public index at all
(PYPI_INDEX_HOSTS), which the shippability gate reads.
- repomatic.pypi.PYPI_INDEX_HOSTS = frozenset({'pypi.org', 'www.pypi.org'})¶
Hosts a package may be resolved from and still count as published.
Anything else is a private index, a staging index (TestPyPI lives on
test.pypi.org, deliberately absent) or a proxy: a user runningpip installoruvxagainst the default index reaches none of them, so a dependency pinned there is no more installable than one pinned to a git branch.
- repomatic.pypi.is_pypi_url(url)[source]¶
Whether url points at the public Python Package Index.
- Parameters:
url (
str) – An index or registry URL.- Return type:
- Returns:
Truewhen its host is one ofPYPI_INDEX_HOSTS.
- repomatic.pypi.PYPI_API_URL = 'https://pypi.org/pypi/{package}/json'¶
PyPI JSON API URL for fetching all release metadata for a package.
- repomatic.pypi.PYPI_PACKAGE_URL = 'https://pypi.org/project/{package}/'¶
PyPI project homepage URL for a package (no version pinned).
- repomatic.pypi.PYPI_PROJECT_URL = 'https://pypi.org/project/{package}/{version}/'¶
PyPI project page URL for a specific version.
- repomatic.pypi.PYPI_VERSION_API_URL = 'https://pypi.org/pypi/{package}/{version}/json'¶
PyPI JSON API URL for the metadata of one version of a package.
- repomatic.pypi.SDIST_SUFFIX = '.tar.gz'¶
Extension of a source distribution, after its
{name}-{version}stem.
- repomatic.pypi.PROPAGATION_ATTEMPTS = 20¶
Lookups
wait_for_release()makes before it gives up.
- repomatic.pypi.PROPAGATION_DELAY = 15¶
Seconds
wait_for_release()waits between two lookups.With
PROPAGATION_ATTEMPTS, the wait lasts about five minutes, which covers the propagation delay of PyPI’s index and CDN.
- repomatic.pypi.PYPI_PROVENANCE_URL = 'https://pypi.org/integrity/{package}/{version}/{filename}/provenance'¶
PyPI integrity API endpoint exposing PEP 740 attestation bundles for a file.
The response includes a
publisherobject per bundle that names the OIDC identity used to upload (kind, repository, workflow filename, environment). This is the only public surface where the OIDCjob_workflow_refclaim is observable: project-level Trusted Publisher settings live behind the owner-only/manage/project/<name>/settings/publishing/page.
- repomatic.pypi.PYPI_TRUSTED_PUBLISHER_SETTINGS_URL = 'https://pypi.org/manage/project/{package}/settings/publishing/'¶
Owner-only page where Trusted Publisher entries are registered.
- repomatic.pypi.PYPI_TRUSTED_PUBLISHER_WORKFLOW = 'release.yaml'¶
Workflow filename each downstream registers as the Trusted Publisher.
The caller-side
publish-pypijob is appended torelease.yamlin every downstream repo (reshaped from the canonical entry byrepomatic.github.workflow_sync._render_publish_pypi_job), and the composite action it invokes inherits the calling job’s OIDC context. The OIDCjob_workflow_refclaim therefore names this file: that is what the PyPI Trusted Publisher entry must match.
- repomatic.pypi.pypi_trusted_publisher_settings_url(package, *, owner=None, repository=None, workflow_filename=None, environment=None)[source]¶
Build the PyPI Trusted Publisher settings page URL for a project.
Without keyword arguments, returns the bare settings URL. When any GitHub publisher field is provided, appends the query string PyPI’s settings page consumes to activate the GitHub tab and pre-populate the form: see the
manage_project_oidc_publishers_prefillview in pypi/warehouse.- Parameters:
package (
str) – PyPI project name.owner (
str|None) – GitHub owner (user or org) prefilled in the form.repository (
str|None) – GitHub repository name prefilled in the form.workflow_filename (
str|None) – Workflow filename prefilled in the form (e.g.,PYPI_TRUSTED_PUBLISHER_WORKFLOW).environment (
str|None) – GitHub Actions environment name prefilled in the form.
- Return type:
- Returns:
The settings URL, optionally with a
?provider=github&…suffix.
- class repomatic.pypi.PyPIRelease(date, yanked, package, yanked_reason='', uploaded_at=None)[source]¶
Bases:
NamedTupleRelease metadata for a single version from PyPI.
Create new instance of PyPIRelease(date, yanked, package, yanked_reason, uploaded_at)
- package: str¶
PyPI package name this release was fetched from.
Needed for projects that were renamed: older versions live under a former package name and their PyPI URLs must point to that name, not the current one.
- repomatic.pypi.pypi_release_dates(package, *, force_refresh=False)[source]¶
Get upload dates and yanked status for all versions from PyPI.
Fetches the package metadata in a single API call. For each version, selects the earliest upload time across all distribution files as the canonical release date. A version is considered yanked only if all of its files are yanked, and carries the first yank reason any of them records.
- Parameters:
- Return type:
- Returns:
Dict mapping version strings to
PyPIReleasetuples. Empty dict if the package is not found or the request fails.
- repomatic.pypi.get_source_url(package)[source]¶
Discover the GitHub repository URL for a PyPI package.
Queries the PyPI JSON API and scans
project_urlsfor keys that typically point to a source repository on GitHub, then reduces the winner to itshttps://github.com/owner/reporoot. An entry often points inside the repository (/issues,/releases,/blob/main/changelog.md), and a caller deriving an API slug from it would otherwise ask the releases API forrepo/issues, which answers 404.
- class repomatic.pypi.TrustedPublisher(kind, repository, workflow, environment)[source]¶
Bases:
NamedTupleOIDC publisher metadata extracted from a PyPI provenance bundle.
Create new instance of TrustedPublisher(kind, repository, workflow, environment)
- repomatic.pypi.get_latest_release_file(package)[source]¶
Return
(version, filename)for the latest non-yanked release on PyPI.Picks the version with the most recent earliest-upload time and returns a representative distribution file from that version. Wheels are preferred over sdists since wheels are guaranteed to exist for any package built with modern tooling.
Two releases uploaded on the same day are ordered by PEP 440, not by the version string: a raw string comparison sorts
1.9.0above1.10.0and would return the older of the two as the latest. Versions PEP 440 cannot parse are skipped, since nothing can rank them.
- repomatic.pypi.get_trusted_publishers(package, version, filename)[source]¶
Fetch PEP 740 provenance for a file and extract publisher entries.
Calls
PYPI_PROVENANCE_URLand parses theattestation_bundlesarray. Each bundle’spublisherobject names the OIDC identity that uploaded the file.- Parameters:
- Return type:
- Returns:
List of
TrustedPublisherentries (possibly empty when provenance exists but no bundles are present), orNonewhen the endpoint returns 404 or any network/parse error occurs (signal that no provenance is available rather than that none was registered).
- class repomatic.pypi.ReleaseProvenance(known, attested=False, publisher='')[source]¶
Bases:
objectWhat PyPI records about how one release was published.
A release uploaded through trusted publishing carries PEP 740 provenance: attestations, signed through Sigstore, naming the repository and the workflow that uploaded each file. A release uploaded with an API token, by hand or by a token thief, carries none.
- repomatic.pypi.release_provenance(package, version)[source]¶
Look up the PEP 740 provenance of one release of package.
Reads the first file of the release, preferring a wheel: trusted publishing uploads every file of a release from one workflow run, so one file speaks for all of them. Tells a release with no provenance (the integrity API answers 404) from a failed lookup, which a caller must not read as an absence.
- Parameters:
- Return type:
- Returns:
The provenance, or an unknown one when PyPI could not be read.
- repomatic.pypi.release_wheel(package, version)[source]¶
Locate the wheel of one release of package on PyPI.
- repomatic.pypi.get_changelog_url(package)[source]¶
Discover the changelog URL for a PyPI package.
Queries the PyPI JSON API and scans
project_urlsfor keys that typically point to a changelog or release notes page. Keys are matched case-insensitively, for the reason spelled out on_SOURCE_URL_KEYS: PyPI preserves whatever spelling the project wrote, soChangelog,changelogandCHANGELOGall occur in the wild.
- repomatic.pypi.sdist_name_version(dist_dir)[source]¶
Read the project name and version off the sdist in dist_dir.
An sdist is named
{name}-{version}.tar.gz, with a name normalized to hold no hyphen, so the last hyphen of the stem splits the two.- Parameters:
dist_dir (
Path) – Directory holding the distributions of one release.- Return type:
- Returns:
The normalized project name and the version.
- Raises:
ValueError – When dist_dir holds no sdist, or one whose name does not split.
- repomatic.pypi.wait_for_release(package, version, *, attempts=20, delay=15)[source]¶
Poll PyPI until version of package answers on its JSON API.
uv publishreturns once PyPI accepts the upload, but its index and CDN can take minutes to serve the release everywhere. Automation that reacts to the release at once (a downstream repository bumping its pin, or this project syncing its own workflow references against itself) would race that window and fail to resolve the version. The release lane waits here instead, so nothing after it inherits the race.Each lookup reads the API afresh: the cached reads of this module would serve the snapshot taken before the upload.
- Parameters:
- Return type:
- Returns:
The number of the lookup that found the version, or
Nonewhen none did.