Build-time version metadata injection for Python packages.
Project description
buildstamp
Build-time version metadata injection for Python packages. Every artifact is stamped with its version, quality tier, commit SHA, and build date — with no metadata drift between source and installed packages, and no git required at runtime.
How it works
| Environment | Version source |
|---|---|
| Git checkout / editable install | Live: git rev-parse + VERSION file |
Installed artifact (no .git) |
Baked: _build.json written at build time |
The quality tier (dev / rc / stable) is controlled by the RELEASE_TYPE
environment variable at build time, so no tag ceremony is needed and no branch
names leak into artifacts.
Quick start
1. Configure pyproject.toml:
[project]
dynamic = ["version"]
[tool.setuptools.dynamic]
version = {file = "VERSION"}
[tool.setuptools.package-data]
your_package = ["_build.json"]
[build-system]
requires = ["setuptools>=64.0", "wheel", "buildstamp"]
build-backend = "buildstamp.backend"
Optional buildstamp configuration:
[tool.buildstamp]
metadata-file = "your_package/_build.json"
version-file = "VERSION"
For dev artifact naming, use an environment variable instead of pyproject:
BUILDSTAMP_DEV_VERSION="{base}+g{sha}" RELEASE_TYPE=dev uv build
No _build_backend.py shim or extra backend-path is required.
3. Add _build.json to .gitignore:
your_package/_build.json
4. Use in your_package/__init__.py:
from buildstamp import load_metadata
_meta = load_metadata(__file__)
__version__ = _meta.version
__quality__ = _meta.quality
__commit__ = _meta.commit
__build_date__ = _meta.build_date
5. Create a VERSION file at the project root:
1.0.0
BuildMetadata fields
| Field | Type | Dev (checkout) | Artifact |
|---|---|---|---|
version |
str |
"1.0.0+g701e4ca" |
"1.0.0" |
quality |
str |
"dev" |
RELEASE_TYPE value |
commit |
str |
short SHA | short SHA baked at build time |
build_date |
datetime | None |
None |
UTC datetime |
build_date_local |
datetime | None |
None |
local timezone datetime |
Inspect built metadata
To verify the baked metadata in a release artifact without relying on runtime imports:
- Build the artifact:
RELEASE_TYPE=stable uv build --no-build-isolation
- List the wheel contents and confirm
_build.jsonis present:
unzip -l dist/buildstamp-*.whl | grep '_build.json'
- Extract and pretty-print
_build.jsonfrom the wheel:
unzip -p dist/buildstamp-*.whl buildstamp/_build.json | python -m json.tool
- Optionally inspect the source distribution as well:
tar -tzf dist/buildstamp-*.tar.gz | grep 'buildstamp/_build.json'
tar -xOzf dist/buildstamp-*.tar.gz buildstamp/_build.json | python -m json.tool
- Convert the stored UTC build timestamp to Amsterdam time:
python - <<'PY'
from datetime import datetime
from zoneinfo import ZoneInfo
utc_dt = datetime.fromisoformat('2026-04-11T21:43:17.362671+00:00')
print(utc_dt.astimezone(ZoneInfo('Europe/Amsterdam')).isoformat())
PY
- Verify the artifact format:
uv run twine check dist/*
That gives you a fully manual inspection path: the wheel is just a zip archive, _build.json is extracted directly, and the UTC build timestamp can be converted to local display time.
Optional in-repo runtime validation
If you want to exercise the baked metadata path from inside a git checkout, first generate _build.json and keep it in the repo:
BUILDSTAMP_FORCE_WRITE=1 uv build --no-build-isolation
Then run Python with the baked-metadata override:
BUILDSTAMP_USE_BUILD_JSON=1 python - <<'PY'
from buildstamp import load_metadata
import buildstamp
meta = load_metadata(buildstamp.__file__)
print(meta)
PY
BUILDSTAMP_USE_BUILD_JSON is the name to use for in-repo baked metadata testing.
That lets you verify the same _build.json-based runtime behavior without leaving the checkout.
Inspect the installed artifact in Python runtime
To verify the same baked metadata from an installed package, install the wheel into a fresh environment and use load_metadata():
pip install dist/buildstamp-*.whl
python - <<'PY'
from buildstamp import load_metadata
import buildstamp
meta = load_metadata(buildstamp.__file__)
print('version:', meta.version)
print('quality:', meta.quality)
print('commit:', meta.commit)
print('build_date:', meta.build_date)
print('local build_date:', meta.build_date_local)
PY
If you run this inside the source checkout with .git present, load_metadata() will use live git metadata instead of the baked _build.json. That is why installing the wheel into a clean environment is the right way to verify the shipped artifact.
Releasing artifacts
# stable release
RELEASE_TYPE=stable uv build
# release candidate
RELEASE_TYPE=rc uv build
If RELEASE_TYPE is unset, the baked quality defaults to "dev".
Installation
pip install buildstamp
While not yet on PyPI, install from source:
uv pip install setuptools
uv pip install -e /path/to/buildstamp
uv pip install -e . --no-build-isolation
Design rationale
See VERSIONING.md for the full rationale — including why this avoids git tags, dirty flags, and branch names as version sources.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file buildstamp-0.7.2.tar.gz.
File metadata
- Download URL: buildstamp-0.7.2.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed08534568404b41c85faac2602f5700f963c2501624855d36eff75825023a8e
|
|
| MD5 |
51ddfa3c4366698f40c3cacc613afcc9
|
|
| BLAKE2b-256 |
986a59aa31f9a2cfac7a9583a269cb359d8f095fc42f3303027398083c082db0
|
Provenance
The following attestation bundles were made for buildstamp-0.7.2.tar.gz:
Publisher:
release.yml on basvandriel/buildstamp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
buildstamp-0.7.2.tar.gz -
Subject digest:
ed08534568404b41c85faac2602f5700f963c2501624855d36eff75825023a8e - Sigstore transparency entry: 1280813669
- Sigstore integration time:
-
Permalink:
basvandriel/buildstamp@3d3031b4d971a4509f02adb28c13ab52ba07011e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/basvandriel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3d3031b4d971a4509f02adb28c13ab52ba07011e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file buildstamp-0.7.2-py3-none-any.whl.
File metadata
- Download URL: buildstamp-0.7.2-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
761442f648636bc6dc5e495a2722037a30b0ac1e4a2440fbae29f18d253c778b
|
|
| MD5 |
246de5d16569af1a65356e8b42927fd0
|
|
| BLAKE2b-256 |
8141b1c2f2c53e5df368db17c346bdd26be9ece20a600a252e160c3622d9bb5d
|
Provenance
The following attestation bundles were made for buildstamp-0.7.2-py3-none-any.whl:
Publisher:
release.yml on basvandriel/buildstamp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
buildstamp-0.7.2-py3-none-any.whl -
Subject digest:
761442f648636bc6dc5e495a2722037a30b0ac1e4a2440fbae29f18d253c778b - Sigstore transparency entry: 1280813674
- Sigstore integration time:
-
Permalink:
basvandriel/buildstamp@3d3031b4d971a4509f02adb28c13ab52ba07011e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/basvandriel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3d3031b4d971a4509f02adb28c13ab52ba07011e -
Trigger Event:
workflow_dispatch
-
Statement type: