Skip to main content

hatch-prebuilt

PyPI ci part of cpp-linter

Build Python wheels that install prebuilt executables unchanged, with hatchling. pip install or uv pip install puts the executable straight into the environment's bin/ (Scripts\ on Windows), with no Python wrapper in between, so starting it costs nothing extra.

A tool that finds its own files through the path of its executable, such as clang's builtin headers in ../lib/clang/<major>/include, sets package in its recipe instead. The wheel then keeps the executable and its files together in that Python package, and a small console script starts the executable (os.execv on Linux and macOS). That way the tool finds its files however it is installed, including uv tool install and pip install --user on Windows, which put the scripts away from the environment's other files. pyproject.toml then lists scripts in project.dynamic.

The cpp-linter wheel repositories use it: ccache-wheel (ccache-bin), clang-apply-replacements, clang-include-cleaner, llvm-cov-wheel (llvm-cov) and clangd-wheel (clangd-bin).

What it does

A wheel repository describes its tool in hatch_build.py: which platforms it has, and how to download and verify the files of one version for one platform. hatch-prebuilt does the rest:

  • picks the version (from a version file, or an environment variable so CI can build older versions) and the platform (from an environment variable, or the build machine);
  • checks that every executable is a binary for that platform: ELF machine and static linking, Mach-O architecture or universal slices, PE machine;
  • works out the wheel tag, including the minimum macOS version the binaries declare;
  • stages the license files where license-files finds them, and gives hatchling the executables as shared scripts and any other files (man pages, headers) as shared data.

It also has the download helpers the recipes share: retrying downloads, a download cache, SHA-512 pins, minisign signatures (hatch-prebuilt[minisign]) and archive extraction.

A recipe

# hatch_build.py
from pathlib import Path

from hatch_prebuilt import Platform, Recipe, Staged, cached_download, check_sha512

URL = "https://example.com/mytool-{version}-{platform}{exe}"
SHA512 = {...}


class MyTool(Recipe):
    name = "mytool"
    version_file = "mytool_version.txt"
    platform_variable = "MYTOOL_PLATFORM"
    platforms = (
        Platform(
            "linux-x86_64",
            "manylinux_2_17_x86_64.musllinux_1_1_x86_64",
            "elf-x86_64",
            "linux",
            "x86_64",
        ),
        Platform("macos-arm64", "macosx_{macos}_arm64", "macho-arm64", "macos", "arm64"),
        Platform("windows-x86_64", "win_amd64", "pe-x86_64", "windows", "x86_64"),
    )

    def stage(self, platform, version):
        url = URL.format(version=version, platform=platform.name, exe=platform.exe)
        binary = cached_download(url, self.cache / Path(url).name)
        check_sha512(binary, SHA512[platform.name], url)
        return Staged(scripts={f"mytool{platform.exe}": binary}, licenses={"LICENSE": ...})


RECIPE = MyTool(Path(__file__).parent)
get_metadata_hook, get_build_hook = RECIPE.hooks()

if __name__ == "__main__":
    raise SystemExit(RECIPE.main())
# pyproject.toml
[build-system]
requires = ["hatchling>=1.27", "hatch-prebuilt>=0.1,<1"]
build-backend = "hatchling.build"

[project]
name = "mytool-bin"
dynamic = ["version"]
license-files = ["upstream/LICENSE"]

[tool.hatch.metadata.hooks.custom]

[tool.hatch.build.targets.wheel]
bypass-selection = true

[tool.hatch.build.targets.wheel.hooks.custom]

Then python hatch_build.py platforms lists the platforms, and MYTOOL_PLATFORM=<platform> python -m build --wheel builds one wheel, for any platform, on Linux or macOS (Windows cannot give the executables their executable bit). The shared binary-wheels.yml workflow builds and tests all of them. To start a new wheel repository, copy clang-apply-replacements for a tool from the static binaries, or ccache-wheel for a tool with its own upstream releases.

Tools from the clang-tools-static-binaries releases need even less: hatch_prebuilt.static_binaries.StaticBinariesRecipe knows the platforms, the file names and the SHA-512 pins in sources.json, so the recipe only names the tools. With resource_headers = True (clangd, clang-include-cleaner) it adds clang's builtin headers and packages the tools as described above.

Contributing

See the contributing guide. uv run --group test pytest runs the tests.

License

MIT

Metadata

Release files for hatch-prebuilt 0.2.0

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

Source distribution (sdist)

Source distribution for hatch-prebuilt 0.2.0
File Size Uploaded Provenance Actions
hatch_prebuilt-0.2.0.tar.gz 22.8 kB With provenance Details for hatch_prebuilt-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hatch-prebuilt 0.2.0
File Interpreter ABI Platform Actions
hatch_prebuilt-0.2.0-py3-none-any.whl Python 3 none any Details for hatch_prebuilt-0.2.0-py3-none-any.whl

Total release size: 40.0 kB

Release files / hatch_prebuilt-0.2.0.tar.gz

Download URL hatch_prebuilt-0.2.0.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
be98a2b30183b35e3a076a23022754620dd66d098d528cf2822329388271292a
BLAKE2b-256 checksum
How to use checksums
fc1e1f6f0c534037437bc71a07aa7a09e113769ea82bd882fbbd0c3af9bb0e74
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 Dec 1, 2026.

Transparency log

Release files / hatch_prebuilt-0.2.0-py3-none-any.whl

Download URL hatch_prebuilt-0.2.0-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6207e279e24662cc9abdfb0ced4f953d5de25234a9c5b8a231a0ae1e77a90068
BLAKE2b-256 checksum
How to use checksums
1dd111d29f01ceaabe763ff258793ada147a7fcb4f2a85ea566a7bc78f6906ef
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 Dec 1, 2026.

Transparency log

Security for hatch-prebuilt 0.2.0

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 hatch_prebuilt-0.2.0.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 Dec 1, 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.

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