Skip to main content

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.
--remote REMOTE Remote used for cached branch detection (default: origin); never fetches
--short Output first seven object-ID characters (reverse lookup mode)
--help Show help

Exit codes

Code Meaning
0 Success
1 Error (not a git repo, no commits, non-monotonic dates, etc.)
2 Dirty workspace or off default branch (without --dirty)
3 Cannot trace to default branch
4 Local history is insufficient to prove the result

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",
    remote="upstream",
)

# 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. Insufficient local history raises the typed gitcalver.IncompleteHistoryError subclass.

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"
# remote = "origin"

Requirements

  • Python 3.10+
  • git on $PATH
  • Enough local commit history to prove the calculation. Shallow and partial clones work when the selected-chain relationship, anchor, and complete relevant UTC date block are available. GitCalVer never fetches missing history during a calculation.

License

MIT

Metadata

Release files for gitcalver 20261004.3

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

Source distribution (sdist)

Source distribution for gitcalver 20261004.3
File Size Uploaded Provenance
gitcalver-20261004.3.tar.gz 41.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gitcalver 20261004.3
File Interpreter ABI Platform
gitcalver-20261004.3-py3-none-any.whl Python 3 none any Details

Total release size: 56.9 kB

Release files / gitcalver-20261004.3.tar.gz

Download URL gitcalver-20261004.3.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
787599fa55c0f0a87ccca6eab2cfb4213c435778fe200e0d73a1d78f599743bb
BLAKE2b-256 checksum
How to use checksums
aaf7f58a4bc4a9bf4625a919e79efbfa9cbf1daf8e99803c8d9840a33728793a
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 Oct 4, 2026.

Transparency log

Release files / gitcalver-20261004.3-py3-none-any.whl

Download URL gitcalver-20261004.3-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c151a6d7eafc61cc47d1cb12caaff3933814ea22f0e9b07640c8a0c40e745e2a
BLAKE2b-256 checksum
How to use checksums
b1853e7a8d20771a64ba307dd49a70c9cb8f1ca157ca3107a65f9299c4bf99d2
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 Oct 4, 2026.

Transparency log

Security for gitcalver 20261004.3

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gitcalver-20261004.3.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 Oct 4, 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.

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