Deterministic calendar versioning from git history
Project description
gitcalver
A Python implementation of GitCalVer, which derives calendar-based version numbers from git history.
Each commit on the default branch gets a unique, strictly increasing version of
the form YYYYMMDD.N, where N is the number of commits on that UTC date.
See the GitCalVer specification for full details.
Installation
uv add gitcalver
# or
pip install gitcalver
See Requirements below.
CLI usage
gitcalver [OPTIONS] [REVISION | VERSION]
With no arguments, prints the version for HEAD:
$ gitcalver
20260411.3
Pass a revision to compute its version:
$ gitcalver HEAD~1
20260411.2
Version prefix
Use --prefix to prepend a literal string:
| Use case | Command | Example output |
|---|---|---|
| Default | gitcalver |
20260411.3 |
| SemVer | gitcalver --prefix "0." |
0.20260411.3 |
| Go | gitcalver --prefix "v0." |
v0.20260411.3 |
Dirty workspace
By default, gitcalver exits with status 2 if the workspace has uncommitted
changes. Use --dirty STRING to produce a version instead; the output will
include the given string and a short commit hash
(e.g. --dirty "-dirty" produces 20260411.3-dirty.abc1234).
Use --no-dirty-hash with --dirty to suppress the hash suffix.
Use --no-dirty to explicitly refuse dirty versions (overrides --dirty).
Dirty versions are a convenience and are not necessarily unique.
Reverse lookup
Pass a version number to get the corresponding commit hash:
$ gitcalver 20260411.3
a1b2c3d4e5f6...
$ gitcalver --short --prefix "0." 0.20260411.3
a1b2c3d
If the version was generated with --prefix, pass the same --prefix for
reverse lookup. Dirty versions cannot be reversed.
Options
| Option | Description |
|---|---|
--prefix PREFIX |
Literal string prepended to version |
--dirty STRING |
Enable dirty versions; append STRING.HASH |
--no-dirty |
Refuse dirty versions (overrides --dirty) |
--no-dirty-hash |
Suppress .HASH suffix (requires --dirty) |
--branch BRANCH |
Base branch name; overrides auto-detection. This is the branch versions are minted on, not the branch you are working on. |
--short |
Output short commit hash (reverse lookup mode) |
--help |
Show help |
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (not a git repo, no commits, non-monotonic dates, shallow clone) |
| 2 | Dirty workspace or off default branch (without --dirty) |
| 3 | Cannot trace to default branch |
Python API
import gitcalver
# Forward: compute a version for HEAD (or a specific revision).
version = gitcalver.get_version(repo="/path/to/repo")
# e.g. "20260411.3"
version = gitcalver.get_version(
repo="/path/to/repo",
revision="HEAD~1",
prefix="v0.",
dirty="-dirty",
)
# Reverse: resolve a version back to a commit hash.
commit = gitcalver.find_commit("20260411.3", repo="/path/to/repo")
# If the version was generated with --prefix, pass the same prefix:
commit = gitcalver.find_commit(
"v0.20260411.3", prefix="v0.", repo="/path/to/repo"
)
Errors are raised as gitcalver.ExitError, which carries a code attribute
matching the CLI exit codes above.
Hatch plugin
gitcalver ships a Hatch version source plugin. To
use it in pyproject.toml:
[build-system]
requires = ["hatchling", "gitcalver"]
build-backend = "hatchling.build"
[tool.hatch.version]
source = "gitcalver"
# Optional:
# prefix = "0."
# dirty = "-dirty"
# no-dirty-hash = true
# branch = "main"
Requirements
- Python 3.10+
giton$PATH- Full commit history (shallow clones made with
--depthare rejected; partial clones made with--filter=blob:noneare fine)
License
MIT
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 gitcalver-20260418.5.tar.gz.
File metadata
- Download URL: gitcalver-20260418.5.tar.gz
- Upload date:
- Size: 38.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e793405be6adbb67217c8905a7197fb93cdfeb317d8d53cf2dfc716e5b3952e
|
|
| MD5 |
187902f2cc7b2fa5db0187b3de55d5ae
|
|
| BLAKE2b-256 |
c3f7a06528147858acf96143f1e114011541c36c125698a954368da01d44a0e4
|
Provenance
The following attestation bundles were made for gitcalver-20260418.5.tar.gz:
Publisher:
ci.yml on gitcalver/python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gitcalver-20260418.5.tar.gz -
Subject digest:
3e793405be6adbb67217c8905a7197fb93cdfeb317d8d53cf2dfc716e5b3952e - Sigstore transparency entry: 1334880707
- Sigstore integration time:
-
Permalink:
gitcalver/python@679d3bc7520e7f32b9cb22689bc4d854eafe88bb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gitcalver
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@679d3bc7520e7f32b9cb22689bc4d854eafe88bb -
Trigger Event:
push
-
Statement type:
File details
Details for the file gitcalver-20260418.5-py3-none-any.whl.
File metadata
- Download URL: gitcalver-20260418.5-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
902dd09bd41f9a6dc1af3b768d76a385cea5dc8229ba4757a4b3cc26ff3bb043
|
|
| MD5 |
93c69805813245a8c0bee59afa9fe390
|
|
| BLAKE2b-256 |
cb3a0d2c128470f5a306df0951a96da85f61276285c4800ff22f3fc5b29d0282
|
Provenance
The following attestation bundles were made for gitcalver-20260418.5-py3-none-any.whl:
Publisher:
ci.yml on gitcalver/python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gitcalver-20260418.5-py3-none-any.whl -
Subject digest:
902dd09bd41f9a6dc1af3b768d76a385cea5dc8229ba4757a4b3cc26ff3bb043 - Sigstore transparency entry: 1334880890
- Sigstore integration time:
-
Permalink:
gitcalver/python@679d3bc7520e7f32b9cb22689bc4d854eafe88bb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gitcalver
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@679d3bc7520e7f32b9cb22689bc4d854eafe88bb -
Trigger Event:
push
-
Statement type: