ocx-mirror-sdk
Python SDK for authoring ocx-mirror generator scripts.
ocx-mirror is OCX's tool for ingesting upstream tool releases (e.g. CPython, Bun, shellcheck) and republishing them as OCI artifacts. When upstream releases live somewhere ocx-mirror cannot crawl directly, a small Python generator emits a url_index JSON document. This SDK provides the typed building blocks for those generators.
📖 Full documentation: https://docs.ocx.sh/sdk/mirror/
Install
Published on PyPI. In a PEP 723 inline-metadata script (recommended for one-file generators):
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["ocx-mirror-sdk~=0.6.0"]
# ///
from ocx_mirror_sdk import IndexBuilder, github
Or in a project:
uv add ocx-mirror-sdk
Pre-1.0, minor releases may break — ~= pins the patch series. Git-tag and
wheel-asset installs remain available; see the
install guide.
Quickstart
from ocx_mirror_sdk import IndexBuilder, github
# Fetch releases (REST default; switch to GraphQL on big repos)
releases = github.list_releases("shellcheck/shellcheck")
# Or explicitly:
releases = github.list_releases("indygreg/python-build-standalone", backend=github.Backend.GRAPHQL)
# Build a url_index document
builder = IndexBuilder()
for r in releases:
if r.prerelease or r.draft:
continue
builder.add_version(
r.tag_name.lstrip("v"),
assets={a.name: a.browser_download_url for a in r.assets},
)
builder.emit() # writes JSON to stdout
Releases hosted on GitLab use the sibling gitlab namespace — same Release
objects, same IndexBuilder:
from ocx_mirror_sdk import gitlab
# gitlab.com (default); pass host="https://gitlab.example.com" for self-hosted
releases = gitlab.list_releases("gitlab-org/gitlab-runner")
More worked examples live under examples/ and at https://docs.ocx.sh/sdk/mirror/recipes/.
Public API
| Symbol | Purpose |
|---|---|
IndexBuilder |
Typed builder for the url_index JSON manifest |
github.list_releases |
Iterate GitHub releases — single router over REST and GraphQL; takes a "owner/repo" slug |
gitlab.list_releases |
Iterate GitLab releases — REST; gitlab.com or self-hosted via host=; takes a "namespace/project" slug |
github.Backend |
StrEnum: REST / GRAPHQL backend selector (GitHub) |
Asset, Release |
Source-agnostic typed views of release assets and releases |
extract_urls |
Pull download URLs from release notes |
FileCache, configure |
Disk-backed HTTP response cache; SDK-wide root override |
Error hierarchy
Catch OcxMirrorError to recover from any SDK failure, or pick a subclass:
| Class | Raised when |
|---|---|
ConfigurationError |
GITHUB_TOKEN missing, client init failed |
TransportError |
Base for network errors |
HttpStatusError |
HTTP 4xx/5xx (carries .status_code, .url, .response_text) |
HttpTimeoutError |
Request timed out |
ApiResponseError |
Malformed JSON, GraphQL errors array, repo not found |
SchemaError |
Release payload missing or wrongly-typed field |
CacheError |
On-disk cache IO or corruption (NOT cache miss) |
Original lower-layer exceptions are preserved on __cause__.
Schema
The url_index format is owned by the ocx-mirror Rust binary. Its JSON Schema is published at https://ocx.sh/schemas/url-index/v1.json. This SDK ships a generated _schema.py (under src/ocx_mirror_sdk/) regenerated via task codegen.
Development
This repo dogfoods OCX. Install OCX once:
curl -sSL https://setup.ocx.sh | sh
Then everything runs through ocx run:
ocx run -- task verify # format + lint + types + tests
ocx run -- task test
ocx run -- task codegen # regenerate _schema.py from the published schema
ocx run -- task docs:serve # live-preview the docs site at localhost:8000
OCX bootstraps task and uv; uv pulls Python linters (ruff, pyright) from [project.optional-dependencies] dev, and docs tooling from [project.optional-dependencies] docs.
Stability
Pre-1.0. Breaking changes ship without migration shims. When the upstream url_index schema bumps to /v2.json, this SDK ships a new major version.
Coverage
task verify enforces ≥80% line + branch coverage on src/ocx_mirror_sdk (generated _schema.py excluded). Run task cov:html and open htmlcov/index.html to inspect uncovered lines locally. The threshold lives in [tool.coverage.report] fail_under in pyproject.toml.
License
Apache-2.0 — see LICENSE.
Metadata
Release files for ocx-mirror-sdk 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ocx_mirror_sdk-0.6.0.tar.gz | 160.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ocx_mirror_sdk-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 192.5 kB
Release files / ocx_mirror_sdk-0.6.0.tar.gz
| Download URL | ocx_mirror_sdk-0.6.0.tar.gz |
|---|---|
| Size | 160.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65c8a565086b07c4b241e0f0e8ff0e0b3ac9b6798e01ceeff69e2f61297434c2
|
|
BLAKE2b-256 checksum How to use checksums |
f2a76e7619edbb9cc5dff11d9e8953c527b2d4ad317759d513a3afce5b9b30be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 2, 2026.
Transparency logRelease files / ocx_mirror_sdk-0.6.0-py3-none-any.whl
| Download URL | ocx_mirror_sdk-0.6.0-py3-none-any.whl |
|---|---|
| Size | 32.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab21c48e83a94ef09ed38b500913ef2807e93c9521077678a35bd40a348d8dcb
|
|
BLAKE2b-256 checksum How to use checksums |
ed2354bbf5191ea46aac10f4fae073f9720087f5151bbd6be688b76f9bf072c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 2, 2026.
Transparency log