Skip to main content

calver-scm is a setuptools-scm plugin that generates CalVer version strings directly from your Git tags and commit history. No __version__ files to maintain, no manual bumping; just tag and go.

Versions look like this:

2026.4.0          -> clean tag, April 2026, patch 0
2026.4.1.dev3     -> 3 commits after that tag, still April, patch incremented
2026.5.0.dev3     -> 3 commits after an old tag, month rolled over, patch reset
2026.4.15.0       -> day mode: clean tag on the 15th
2026.4.15.1.dev2  -> day mode: 2 commits after a tag on the same day
2026.4.0.dev12    -> no tag yet, 12 commits in
0.2026.4.0        -> same release line, but marked unstable/pre-1.0

Installation

pip install calver-scm

Then wire it into your pyproject.toml. Pick the setup that matches your build backend:

If you use Hatchling, this is the shortest working setup:

[build-system]
requires = ["hatchling", "hatch-vcs", "calver-scm"]
build-backend = "hatchling.build"

[project]
dynamic = ["version"]

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
version_scheme = "calver-scm"
local_scheme   = "dirty-tag"

dynamic = ["version"] is required so Hatch knows the version is resolved from VCS at build time.

With setuptools

[build-system]
requires = ["setuptools", "setuptools-scm", "calver-scm"]
build-backend = "setuptools.build_meta"

[project]
dynamic = ["version"]

[tool.setuptools_scm]
version_scheme = "calver-scm"
local_scheme   = "dirty-tag"

dynamic = ["version"] is required when using PEP 621 metadata in pyproject.toml.

hatch-vcs extras (optional)

The quickstart config above is enough for most projects. If you want a runtime __version__ file, hatch-vcs can write one during builds:

[tool.hatch.build.hooks.vcs]
version-file = "src/your_package/_version.py"

Then in your __init__.py:

from ._version import __version__

This hook runs only inside a hatch build. To write the same kind of file without a build, for example in a project that has no pyproject.toml, see Writing the version to a file.

That's it. Your project will now version itself automatically on every build.

CI note

This plugin derives versions from Git history and tags. In CI, make sure your checkout includes tags and enough history to resolve the latest version tag.


How versions are generated

The generated version shape is config-driven. In general, it looks like:

[0.]<DATE_BASE>.PATCH[.devN][+local]
  • <DATE_BASE> comes from mode/scheme (for example YYYY, YYYY.MM, YYYY.WW, or YYYY.MM.DD).
  • 0. is included only when stable = false.
  • .devN appears for non-tag builds (and in no-tag fallback when fallback = "dev").
  • +local (including +dirty) depends on your setuptools-scm local_scheme.

If stable = false, calver-scm prefixes the generated public version with 0. to indicate an explicitly unstable release line:

2026.4.0      -> stable output (default)
0.2026.4.0    -> unstable output
0.2026.4.1.dev3
Situation Example
Clean tag, month mode 2026.4.0
Commits after tag, same month 2026.4.1.dev3
Commits after tag, previous month's tag 2026.5.0.dev3
Clean tag, day mode 2026.4.15.0
Dirty working tree 2026.4.0+dirty
No tag yet 2026.4.0.dev12

The patch segment increments automatically from your last tag within the current period, and resets to 0 whenever the month (or day, in day mode) rolls over.

The date segment is derived from the build/runtime date, not from commit timestamps.

Pre-release, post-release, and local tags

If your Git tag carries any PEP 440 suffix, calver-scm preserves it in the generated version and normalises it to its PEP 440 canonical form.

Pre-release suffixes (a, b, rc)

Tag any of the recognised PEP 440 aliases and it is normalised automatically:

Tag suffix Canonical output
alpha / a a
beta / b b
preview / pre / c / rc rc
v2026.4.0a1     -> 2026.4.0a1
v2026.4.0beta2  -> 2026.4.0b2
v2026.4.0pre1   -> 2026.4.0rc1
v2026.4.0rc1    -> 2026.4.0rc1

Post-release suffixes (post)

Tag suffix Canonical output
-rN / revN postN
post-N / postN postN
v2026.4.0-r1     -> 2026.4.0.post1
v2026.4.0.rev2   -> 2026.4.0.post2
v2026.4.0.post-3 -> 2026.4.0.post3
v2026.4.0.post3  -> 2026.4.0.post3

Dev suffixes (dev)

Tag suffix Canonical output
dev (bare) dev0
dev-N / devN devN
v2026.4.0.dev    -> 2026.4.0.dev0
v2026.4.0.dev-4  -> 2026.4.0.dev4
v2026.4.0.dev4   -> 2026.4.0.dev4

Local version segment (+)

A +local segment on a tag is preserved as-is. PEP 440 normalises underscores to dots within local identifiers:

v2026.4.0+abc            -> 2026.4.0+abc
v2026.4.0+linux.x86_64   -> 2026.4.0+linux.x86.64

Note: The +local segment on a tag is distinct from the +dirty suffix that setuptools-scm appends for uncommitted working-tree changes. See Local scheme for how to control that behaviour.

Combining suffixes

All segments can be combined and are each normalised independently:

v2026.4.0rc1.post2.dev3+local -> 2026.4.0rc1.post2.dev3+local

Configuration

Add a [tool.calver-scm] section to pyproject.toml to customise behaviour. All fields are optional, and the defaults shown below are sensible for most projects.

[tool.calver-scm]
mode       = "month"   # "year" | "month" | "week" | "day"
scheme     = "YYYY.MM" # optional token scheme; defaults from mode
patch      = true      # auto-increment patch within a period
stable     = true      # emit normal tags, or prefix versions with 0. when false
no_dev     = false     # suppress .devN suffix on non-exact versions
fallback   = "dev"     # "dev" | "date" (when no tag exists)
tag_prefix = "v"       # prefix stripped when reading tags
timezone   = "UTC"     # "UTC" (default), "local", or IANA tz name

If scheme is omitted, calver-scm uses sensible defaults:

  • mode = "year" -> YYYY
  • mode = "month" -> YYYY.MM
  • mode = "week" -> YYYY.WW
  • mode = "day" -> YYYY.MM.DD

Supported scheme tokens follow CalVer terminology: YYYY, YY, MM, WW, DD.

Week tokens (WW) cannot be combined with month/day tokens.

mode

Controls the time granularity of the version base.

  • "year": base is YYYY (e.g. 2026)
  • "month": base is YYYY.MM (e.g. 2026.4)
  • "week": base is YYYY.WW (e.g. 2026.16)
  • "day": base is YYYY.MM.DD (e.g. 2026.4.15)
# Year mode: annual cadence
[tool.calver-scm]
mode = "year"
# -> 2026.0, 2026.1.dev3 ...

# Month mode (default): good for most projects
[tool.calver-scm]
mode = "month"
# -> 2026.4.0, 2026.4.1.dev3, 2026.5.0.dev1 ...

# Week mode: weekly cadence
[tool.calver-scm]
mode = "week"
# -> 2026.16.0, 2026.16.1.dev2 ...

# Day mode: useful for projects that release frequently
[tool.calver-scm]
mode = "day"
# -> 2026.4.15.0, 2026.4.15.1.dev2, 2026.4.16.0.dev1 ...

scheme

Defines the date portion explicitly using CalVer tokens.

# Explicitly match the default month style
[tool.calver-scm]
scheme = "YYYY.MM"

# Short year + month
[tool.calver-scm]
scheme = "YY.MM"
# -> 26.4.0, 26.4.1.dev3

# Year + ISO week (week schemes are month/day-exclusive)
[tool.calver-scm]
scheme = "YYYY.WW"
# -> 2026.16.0, 2026.16.1.dev2

patch

When true, the patch number increments from the last tag within the same period. When false, patch is always 0 and only the .devN distance distinguishes pre-release builds.

# patch = true (default): each build within a period gets a unique patch number
[tool.calver-scm]
patch = true
# tag v2026.4.2, then 3 commits later -> 2026.4.3.dev3

# patch = false: patch stays 0, only devN changes
[tool.calver-scm]
patch = false
# tag v2026.4.2, then 3 commits later -> 2026.4.0.dev3

stable

Controls whether generated public versions are emitted as stable releases or explicitly marked as unstable with a leading 0. prefix.

# stable = true (default): emit standard CalVer versions
[tool.calver-scm]
stable = true
# tag v2026.4.2, then 3 commits later -> 2026.4.3.dev3

# stable = false: prefix generated output with 0.
[tool.calver-scm]
stable = false
# tag v2026.4.2, then 3 commits later -> 0.2026.4.3.dev3

While stable = false, both v0.2026.4.3 and legacy unprefixed tags like v2026.4.3 are accepted as parseable historical bases to ease migration. When you switch to stable = true, tags that still carry the unstable 0. prefix are treated as incompatible and the version scheme falls back until you create the first stable tag.

For a go-live cutover, the recommended flow is:

  1. develop and pre-release with stable = false
  2. flip to stable = true on the release commit
  3. create the first stable tag, for example v2026.4.0

That keeps the unstable 0. tag line distinct from the stable release line and avoids silently reinterpreting old unstable tags as stable ones.

no_dev

When true, suppresses the .devN suffix on generated versions, emitting a clean {base}.{patch} version even when commits exist after the latest tag or when falling back in an untagged repository.

# no_dev = false (default): normal development versions with distance suffix
[tool.calver-scm]
no_dev = false
# tag v2026.4.2, then 3 commits later -> 2026.4.3.dev3

# no_dev = true: suppress dev suffix for release workflows
[tool.calver-scm]
no_dev = true
# tag v2026.4.2, then 3 commits later -> 2026.4.3

This is especially useful in release CI workflows that compute the clean target release version, create the tag, and publish the release in one pass without requiring a separate bumping step.

Note: no_dev only suppresses the public .devN version segment. Setuptools-scm's local_scheme (such as the default node-and-date) can still append a +g... local segment on untagged commits. Pair no_dev = true / CALVER_SCM_NO_DEV=true with a distance-insensitive local scheme like dirty-tag or no-local-version (or CI overrides like no-local-version-strict) to ensure a clean version string.

fallback

Controls what happens when no tag exists yet in the repository.

  • "dev": emits YYYY.MM.0.devN where N is the total commit count (default)
  • "date": emits YYYY.MM.0 with no dev segment, useful for initial releases
# fallback = "dev" (default): makes it clear this is a pre-release build
[tool.calver-scm]
fallback = "dev"
# 12 commits, no tag yet -> 2026.4.0.dev12

# fallback = "date": emits a clean version even before the first tag
[tool.calver-scm]
fallback = "date"
# 12 commits, no tag yet -> 2026.4.0

tag_prefix

The string that must prefix a tag for it to be recognised as a CalVer tag. Set to "" if your tags have no prefix.

# tag_prefix = "v" (default): tags like v2026.4.0
[tool.calver-scm]
tag_prefix = "v"

# No prefix: tags like 2026.4.0
[tool.calver-scm]
tag_prefix = ""

# Custom prefix: tags like release-2026.4.0
[tool.calver-scm]
tag_prefix = "release-"

timezone

Controls which timezone is used to compute the date segment.

  • "UTC": default; deterministic across environments
  • "local": machine local timezone
  • Any valid IANA timezone, e.g. "Europe/London", "America/New_York"
# Default, recommended for CI/reproducibility
[tool.calver-scm]
timezone = "UTC"

# Use host local timezone
[tool.calver-scm]
timezone = "local"

# Explicit IANA timezone
[tool.calver-scm]
timezone = "Pacific/Auckland"

Without a pyproject.toml: calver-scm.toml

A project that does not build a Python package (for example an app installed from requirements.txt and deployed in a container) can still use calver-scm for its version. Put the same settings in a calver-scm.toml at the repository root, without the tool. nesting:

# calver-scm.toml, at the repository root; no pyproject.toml needed
tag_prefix   = "v"
local_scheme = "no-local-version"  # omit the +g<hash> suffix, for a clean version
$ git describe --tags   # two commits after v2026.11.0
v2026.11.0-2-g1a2b3c4
$ calver-scm --format plain version
2026.11.1.dev2

Without local_scheme, setuptools-scm's default (node-and-date) applies, as it does for a pyproject.toml that sets none, so the same commit gives 2026.11.1.dev2+g1a2b3c4. A project that passes the version to a build, for example as a Docker build argument, usually wants no-local-version.

  • The file is optional, and an empty one is valid. It takes every key from [tool.calver-scm], plus local_scheme (see Local scheme), which the CLI otherwise reads from [tool.setuptools_scm]. Unknown keys are ignored.
  • Settings are layered, lowest to highest: [tool.calver-scm] in pyproject.toml, then calver-scm.toml, then the CALVER_SCM_* variables. A project can use both files; calver-scm doctor warns when a key has a different value in each.
  • It is read by the calver-scm command (version, explain, doctor and the rest) and by setuptools-scm when it runs the version scheme. A real setuptools or Hatch-VCS build still takes its build options from pyproject.toml, so when the project has a [tool.setuptools_scm] or Hatch-VCS section the CLI uses that for local_scheme and the other build options, as the build does.
  • calver-scm explain shows which layer supplied each setting, and doctor names the files read.

Environment variable overrides

Every option can be overridden at build time without touching pyproject.toml or calver-scm.toml, which is handy for CI pipelines.

Variable Equivalent option
CALVER_SCM_MODE mode
CALVER_SCM_SCHEME scheme
CALVER_SCM_PATCH patch (true / false)
CALVER_SCM_STABLE stable (true / false)
CALVER_SCM_NO_DEV no_dev (true / false)
CALVER_SCM_FALLBACK fallback
CALVER_SCM_TAG_PREFIX tag_prefix
CALVER_SCM_TIMEZONE timezone

Environment variables take precedence over both pyproject.toml and calver-scm.toml.


Local scheme

calver-scm controls the public version segment only. The +dirty suffix is handled separately by setuptools-scm's built-in local schemes. Pick whichever suits you:

[tool.setuptools_scm]
version_scheme = "calver-scm"
local_scheme   = "dirty-tag"         # +dirty on uncommitted changes (recommended)
# local_scheme = "no-local-version"  # suppress the local segment entirely
# local_scheme = "node-and-date"     # +g1a2b3c4.d20260415 (setuptools-scm default)

Command line

An optional command line reports the version your project's build would produce, without building anything.

pip install 'calver-scm[cli]'
calver-scm version                  # 2026.4.3.dev3+g1a2b3c4
calver-scm version --root ./backend # a project in a subdirectory
calver-scm version --json           # {"version": "2026.4.3.dev3+g1a2b3c4"}

version reads the project's own [tool.setuptools_scm] or Hatch-VCS [tool.hatch.version] settings and asks setuptools-scm for the result, so it includes your local_scheme and honours CALVER_SCM_* overrides. It fails if the project does not use version_scheme = "calver-scm".

Writing the version to a file

calver-scm version --write src/app/_version.py   # a module with __version__ and version
calver-scm version --write VERSION               # just the version and a newline
calver-scm version --write VERSION --dry-run     # show what would be written

--write PATH also writes the version to a file, for when no build writes it for you, such as an application that needs the Git tag as its version at image build time. If you build with hatch-vcs, its version-file hook (see hatch-vcs extras) already writes the same kind of file during the build, and setuptools-scm has an equivalent version_file setting, so you do not need --write there. A .py file gets a small module (__version__ = version = '2026.4.3', with an __all__), in the shape setuptools-scm writes; any other file gets the version and a newline. Stdout is unchanged and --json still works. What was done is said on stderr: wrote PATH, or unchanged PATH when the file already held the version, in which case it is not touched and its timestamp does not change.

The write is safe to run in a build step:

  • The path is resolved, following symlinks, before it is checked, so it must be inside the project (--root); .. and a link pointing out are refused with exit 2, and an absolute path is allowed only when it is inside.
  • The file is written beside the target and renamed over it, so a reader never sees half a file and a failure leaves the old content.
  • The directory must already exist; it is not created.
  • Nothing is written when the version cannot be resolved.
  • --dry-run (needs --write) prints would write PATH: and the content on stderr and writes nothing.

If the file is tracked by Git, rewriting it makes the tree dirty, which some local_scheme settings turn into a +dirty suffix, so add a generated file to .gitignore.

calver-scm validate 2026.4.2                 # valid: 2026.4.2
calver-scm validate v2026.4.2 --tag          # check a Git tag, including its prefix
calver-scm validate "$GITHUB_REF_NAME" --tag --against-repo   # also check it against the repo
calver-scm validate 2026.13.1 --json         # {"valid": false, "input": ..., "errors": [...]}

validate checks that a version is valid PEP 440 and fits your configured scheme: the number of date components, calendar ranges (month 1-12, real days of the month, week 1-53), the stable setting's 0. prefix and, with --tag, the tag_prefix. Pre-release, post-release, dev and local suffixes are accepted. A valid input also reports its kind (final, prerelease, postrelease or dev, as tags does) and is_prerelease, which is true for pre-release and dev versions, so a release step can set its pre-release flag from the tag alone. It also reports the parts it parsed, so a script never has to re-parse the tag against the scheme: period (the date part as rendered, without an unstable scheme's 0.), date (the date values keyed by the scheme tokens as written, such as {"YYYY": 2026, "MM": 11}), patch (0 when the version has none), pre (the suffix as written, such as rc1), and the post and dev numbers; absent parts are null; and version (the normalised version without the tag prefix, so it keeps an unstable scheme's 0.), stable (the configured setting) and tag_prefix (the prefix removed from the input, empty when --tag is not given). It reads [tool.calver-scm] or calver-scm.toml (and CALVER_SCM_* overrides) from --root but needs no Git checkout. Week 53 is accepted in any year because YYYY.WW takes its year from the calendar date, not the ISO week-year.

parse takes the same input (calver-scm parse v2026.4.2 --tag) and applies the same checks, but is for reading the version rather than judging it. It prints one tab-separated line per part (kind, version, period, one date.<token> line per date component, patch, pre, post, dev, stable, tag_prefix), with an empty value for a part the version lacks. --json and --format github give the same fields as validate. An invalid input prints the findings as validate does and exits 1, so a script stops on a bad tag.

parse --against-repo (with --tag, on a full clone) also reports whether the tag is the newest release in each scope it belongs to, so a project can avoid moving a tag such as latest, 0.2026.11 or a docs "current" link backwards when it releases an older version later, such as a .post hotfix. Under newest (JSON) or as newest.<scope> lines (plain), the scopes are the tag's period (2026.11), each shorter date prefix (2026) and all. A scope is true when no other final or post-release tag in it sorts higher by PEP 440; pre-releases and dev releases do not count, as in tags. Equal versions are ignored, so a tag that already exists is not compared with itself. --format github leaves newest out, as its keys are not valid output names, so read it from --json. A shallow clone exits 3.

--against-repo (with --tag) also reads the local tags, as next-tag does, so validate can say whether the tag makes sense in this repository and not only whether it is well-formed. It judges the tag as a new release among the existing tags, on any branch, and every finding is an error (exit code 1), because the point is a release CI gate. A tag pointing at HEAD is the one being built, so on a tag-push build it does not count as already existing. Post-releases are only checked for existence and period, since they legitimately follow an older release. Without the flag validate is unchanged and needs no checkout. With it, a shallow clone exits 3, as for next-tag, because the tag list cannot be trusted. Rerunning a build for an old release tag fails the later-release checks, as the tag is judged as a new one.

Explaining a version

calver-scm explain

Shows how the build version was derived: the tag, commit distance and dirty flag that setuptools-scm supplied, the date and timezone used, which branch of the algorithm ran (exact_tag, patch_incremented, patch_reset, no_tag_fallback or incompatible_tag_fallback), the effective configuration with where each setting came from (default, pyproject.toml, calver-scm.toml or the CALVER_SCM_* variable), and any CALVER_SCM_* overrides in force. It separates the public_version that calver-scm produced from the local_segment that your local_scheme appended afterwards. It runs the same code path as a real build, and it never prints absolute paths.

--promote proposes the final tag for the latest pre-release (in PEP 440 order, across channels) of the release that would otherwise be proposed, so v2026.4.3rc2 gives v2026.4.3. It exits 3 with no_prerelease when there is nothing to promote, and with prerelease_not_ancestor when that pre-release is not an ancestor of HEAD, because the final tag would then not contain what was tested. If HEAD has moved on since the pre-release, it still succeeds but prints a warning to stderr.

--post proposes the next post-release of the latest release in the period, so with v2026.4.2 released it gives v2026.4.2.post1, then .post2. It is the one mode that adds to an existing release, so unlike a final tag it works with patch = false. It exits 3 with no_release when the period has no release. --pre, --promote and --post cannot be combined (exit code 2).

The reason is one of:

Reason Meaning
no_tag_fallback No tag, fallback. There is no tag at all, so the configured fallback applies.
incompatible_tag_fallback Incompatible tag, fallback. The tag does not fit the CalVer scheme (a repository with no tags is reported as 0.0), so the configured fallback applies.
exact_tag Exact tag. HEAD is exactly on a clean tag, so that tag's version is used as it is.
patch_incremented Patch incremented. There are commits since a tag from the current period, so the patch moves on by one.
patch_reset Patch reset. The tag is from an earlier period (or patch is turned off), so the patch starts again at 0.

Diagnosing problems

calver-scm doctor
calver-scm doctor --strict   # exit 1 on warnings too, for CI

Runs independent checks and carries on past failures: whether the build configuration uses the calver-scm scheme, whether [tool.calver-scm] and the environment overrides are valid, whether Git is available, whether the version resolves, and warnings for shallow clones, a missing compatible tag, and no_dev combined with a local segment. Each finding has a code, a severity (ok, info, warning or error) and, where useful, a suggested fix. Warnings never fail the command unless you pass --strict, which makes a warning exit 1 like an error (info findings never fail it); the report itself is the same either way. Errors always fail. Error details can include file paths.

Planning the next release tag

git tag "$(calver-scm next-tag)"     # prints e.g. v2026.4.3
calver-scm next-tag --date 2026-05-03  # plan for another date: v2026.5.0
calver-scm next-tag --pre rc           # next release candidate: v2026.4.3rc1
calver-scm next-tag --promote          # finalise the candidate: v2026.4.3rc2 -> v2026.4.3
calver-scm next-tag --post             # post-release of the latest: v2026.4.2.post1

next-tag is read-only: it proposes a tag and never creates or pushes one. It looks at every local tag, not only those reachable from HEAD, so a number used on another branch is not reused. Pre-releases and dev releases occupy no number, post-releases do, and tags that do not fit the scheme are ignored. It honours tag_prefix, stable and the timezone. With patch = false it refuses a second release in the same period. It also refuses a shallow clone, because the tag list cannot be trusted. Tags that exist only on the remote and have not been fetched cannot be seen, so run git fetch --tags first.

--date YYYY-MM-DD (-d) plans for that calendar date instead of today, which is useful for backfilling and for testing. The configured timezone does not apply to it, and anything that is not an ISO date is a usage error (exit code 2).

--pre a|b|rc proposes the next pre-release of the release that would otherwise be proposed, so with v2026.4.2 released it gives v2026.4.3rc1, then v2026.4.3rc2 once that exists. Numbers start at 1 and are counted per period, patch and channel, so an existing rc2 does not affect --pre b. Dev releases occupy no number. --pre follows the same refusals as a final tag, including patch = false with the period already released.

The reason is one of:

Reason Meaning
new_period New period. No release exists in this period yet, so numbering starts at 0.
next_patch Next patch. A release already exists in this period, so the patch moves on from it.
new_prerelease First pre-release. No pre-release of this channel exists for the next release yet, so numbering starts at 1.
next_prerelease Next pre-release. A pre-release of this channel already exists for the next release, so the number moves on from it.
promotion Promotion. A pre-release exists for the next release, so the final tag promotes it.
new_postrelease First post-release. The latest release has no post-release yet, so numbering starts at 1.
next_postrelease Next post-release. The latest release already has a post-release, so the number moves on from it.

How next-tag differs from version

calver-scm version describes the commit you are on; next-tag plans a release. They agree in a simple, linear history, so CALVER_SCM_NO_DEV=true calver-scm version and calver-scm next-tag give the same number there. They are not the same thing:

Situation version (with no_dev) next-tag
Commits past the latest release, linear history the next patch, e.g. 2026.11.1 v2026.11.1, the same number
HEAD is exactly on a release tag that tag, 2026.11.0 the next number, v2026.11.1
The nearest tag is a pre-release (rc1) moves on from the pre-release's number ignores pre-releases
A later tag exists only on another branch ignores it (not reachable from HEAD) counts it, so it never reuses a number
Uncommitted changes adds a local segment such as +g1a2b3c4.d20261101 unaffected
patch = false always patch 0, which can repeat a release refuses a second release in the period

Use version to see what a build will be called, and next-tag to decide what to tag.

Listing tags

calver-scm tags

The companion to next-tag: it lists the local tags and how each reads under your scheme, so when a tag is not counted you can see why. Read-only. Understood tags come first, oldest period first, then the ignored ones by name. A shallow clone prints a warning to stderr, because tags may be missing.

Kind Meaning
final A release. It occupies its patch number.
postrelease A post-release. It occupies its number too.
prerelease A pre-release (a, b, rc). Not counted when numbering finals.
dev A dev release. Not counted.
ignored Does not fit the scheme (not PEP 440, a stray 0. prefix with stable = true, or the wrong number of components). The reason is shown.

Plain output is one tab-separated line per tag: tag, kind, period, patch (- when ignored) and, for an ignored tag, the reason. JSON gives tag, kind, period, patch, counted and reason for each tag under a tags key.

A tag without the configured prefix is still read if it is a valid version, exactly as next-tag reads it.

Comparing and sorting versions

calver-scm compare 2026.4.2 2026.4.3          # less
calver-scm compare v2026.4.10 v2026.4.9 --tag # greater
git tag | calver-scm sort --tag --reverse | head -1   # the newest tag
calver-scm sort 2026.4.10 2026.4.2 2026.4.3rc1

compare A B prints less when A is older than B, equal, or greater. sort prints versions oldest first (--reverse for newest first), taking them from the command line or, with none given, from standard input one per line with blank lines skipped. Each version is printed as written, so tags keep their prefix. Both order as PEP 440 does, which sort -V does not: 2026.4.3.dev1 < 2026.4.3rc1 < 2026.4.3 < 2026.4.3.post1, and 2026.4.9 < 2026.4.10.

Every input is checked against the project's scheme first, exactly as validate checks it (pass --tag for Git tags, which must carry the configured prefix). The first invalid input prints its findings and exits 1, so a script stops on a bad tag instead of quietly dropping it. That also means a stable and an unstable (0.) version can never be mixed: under stable = false a version without the 0. is invalid. --json gives {"a": ..., "b": ..., "order": ...} for compare and {"versions": [...]} for sort. sort with nothing to sort exits 2.

Crossing from unstable to stable

When a project drops stable = false (or adds it), its older tags keep, or lack, the 0. prefix that the new setting rejects: v0.2026.11.1 is not valid under stable = true. calver-scm tags lists them as ignored and next-tag plans without them, so they never affect what the next release is. compare and sort check each input strictly, so one legacy tag in git tag output would stop sort with exit 1. Pass --skip-other-stability to leave those out:

git tag | calver-scm sort --tag --reverse --skip-other-stability | head -1   # the newest stable tag

It skips only an input whose sole problem is the 0. prefix disagreeing with stable, in either direction, and prints note: skipped N versions … on stderr so stdout stays the result. A malformed tag (a bad month, a missing v) still fails, so the flag cannot hide a typo. Skipping never changes which tag is newest, because PEP 440 puts 0.2026.11.1 below 2026.12.0. If every input is skipped, sort exits 2.

Short flags

Flag Short Applies to
--root -r every command
--reverse -R sort
--write none version
--dry-run none version
--skip-other-stability none sort
--tag -t validate, parse, compare, sort
--against-repo none validate, parse
--date -d next-tag
--pre none next-tag
--promote none next-tag
--post none next-tag
--format -f every command
--json -j every command

Output formats

Pick how results are written with the global --format option, before or after the command:

Format Output
auto (default) rich when stdout is a terminal, otherwise plain
rich Coloured, human-friendly output (honours NO_COLOR)
plain Unstyled text, one value per line, for scripts
json A single JSON object; --json (-j) is shorthand for --format json (-f json)
github For GitHub Actions: appends the result to $GITHUB_OUTPUT (see below)
calver-scm version                    # rich in a terminal
calver-scm version | cat              # plain: 2026.4.3.dev3+g1a2b3c4
calver-scm --format json version

Piping or redirecting therefore always gives plain text without needing a flag. Plain is the stable format for scripts: one value per line, or key: value lines, with no decoration. Run calver-scm --help, or calver-scm COMMAND --help, for the options, worked examples and exit codes of each command. calver-scm --version prints the installed calver-scm release.

GitHub Actions

--format github appends each top-level scalar value of the result to the file named by $GITHUB_OUTPUT, so later steps can read it as steps.<id>.outputs.<name>, with no parsing or hand-written echo >> "$GITHUB_OUTPUT". It works with version, next-tag, validate, parse and compare; explain, doctor, tags and sort have nested results and exit 2. Booleans are true or false, a missing value is empty, and a value spanning lines is written between a random delimiter so it cannot inject another output. The plain form is still printed so the step log shows the result. Outside Actions, with GITHUB_OUTPUT unset or empty, it exits 2 before doing any work. For validate the outputs are valid and input, plus kind, is_prerelease, period, patch, pre, post, dev, version, stable and tag_prefix when the input is valid (date is nested, so it is JSON only), and an invalid input still writes valid and input before exiting 1.

next-tag writes tag, version, patch, reason, latest_tag, is_prerelease and channel. An example release workflow that plans the tag, then tags and publishes it, marking pre-releases:

name: Release
on:
  workflow_dispatch:
    inputs:
      channel:
        description: Pre-release channel (a, b or rc), or blank for a final release
        default: ""

permissions:
  contents: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0 # next-tag refuses a shallow clone
      - uses: astral-sh/setup-uv@v10.3.3
      - name: Plan the tag
        id: plan
        env:
          CHANNEL: ${{ inputs.channel }}
        run: uvx calver-scm --format github next-tag ${CHANNEL:+--pre "$CHANNEL"}
      - name: Create the release
        env:
          GH_TOKEN: ${{ github.token }}
          TAG: ${{ steps.plan.outputs.tag }}
          PRERELEASE: ${{ steps.plan.outputs.is_prerelease }}
        run: |
          gh release create "$TAG" --target "$GITHUB_SHA" --generate-notes \
            --prerelease="$PRERELEASE"

To gate a tag-push workflow instead, check the tag against the repository first; the tag being built points at HEAD, so it does not count as already existing:

      - run: uvx calver-scm validate "$GITHUB_REF_NAME" --tag --against-repo
Job summary

--summary also appends a Markdown report of the result to the file named by $GITHUB_STEP_SUMMARY, which GitHub shows on the run page. Unlike --format github it works with every command, including explain, doctor, tags and sort, and with every format, so a step can export outputs and write its summary at once. Stdout and the exit code are unchanged, so the summary is written even when doctor or validate fails, which is when it is most useful. Each step's report is appended to the file, never overwriting what earlier steps wrote.

      - run: uvx calver-scm --summary doctor
      - run: uvx calver-scm --summary --format github next-tag

doctor gives a table of checks with their severity, detail and fix; explain the derivation and a table of each setting with where it came from; tags a table of tags; version, next-tag, validate, parse and compare a table of their fields, sort a numbered list of versions, with the findings listed for an invalid input. Anything that comes from the repository, such as a tag name or an error message, is escaped, so a crafted tag cannot add markup to the page. doctor error details can include file paths, as they do in the log. Outside Actions, with GITHUB_STEP_SUMMARY unset or empty, --summary exits 2 before doing any work.

Exit codes

Code Meaning
0 Success. For validate, the input is valid; for compare, whichever way they order. For doctor, no errors (warnings are allowed unless --strict).
1 validate, parse, compare and sort: an input is invalid. doctor: errors were found, or warnings with --strict.
2 Invalid usage, invalid configuration, or the version could not be resolved. --format github without GITHUB_OUTPUT, or on a command that does not support it, is invalid usage.
3 validate --against-repo and parse --against-repo: a shallow clone. next-tag: no safe tag can be proposed (a shallow clone, patch = false with the period already released, --promote with nothing to promote, or --post with no release in the period).

Errors and invalid configuration

Errors are always plain text on stderr, whatever the format, and leave stdout empty. If [tool.calver-scm], calver-scm.toml, a CALVER_SCM_* variable or pyproject.toml itself is invalid, every command stops with error: Invalid config: … and exit code 2. doctor is the exception: it reports the problem as an error check, carries on with the other checks, and exits 1. The build behaves the same way in spirit: setuptools-scm raises a RuntimeError with the same message, so the build fails instead of producing a wrong version.

validate is also an exception to "errors go to stderr": an invalid input is its answer, so the verdict goes to stdout, and with --json it stays parseable.

JSON output

--json (or --format json) prints a single JSON object on one line. A missing value is always null, never an omitted key. New keys may be added in a future release, so ignore keys you do not know. The reason, severity, status and error code values below are stable identifiers; the wording of messages and summaries is not.

// version
{"version": "2026.4.3.dev3+g1a2b3c4"}

// validate (exit code 1 when "valid" is false)
{"valid": false, "input": "2026.13.1",
 "errors": [{"code": "invalid_month", "message": "Month must be between 1 and 12, got 13"}]}
// validate, valid input: kind is final, prerelease, postrelease or dev
{"valid": true, "input": "2026.4.2rc1", "errors": [], "kind": "prerelease", "is_prerelease": true}

// tags
{"tags": [{"tag": "v2026.4.3rc1", "kind": "prerelease", "period": "2026.4", "patch": 3,
           "counted": false, "reason": null}]}       // reason is set only for "ignored"

// next-tag
{"tag": "v2026.4.3", "version": "2026.4.3", "patch": 3,
 "reason": "next_patch", "latest_tag": "v2026.4.2",   // latest_tag is null for a new period
 "is_prerelease": false, "channel": null}             // channel is "a", "b" or "rc" with --pre

// explain
{"version": "2026.4.3.dev3+g1a2b3c4", "public_version": "2026.4.3.dev3",
 "local_segment": "g1a2b3c4",                        // null when the local_scheme adds nothing
 "reason": "patch_incremented",
 "scm": {"tag": "2026.4.2", "distance": 3, "dirty": false},
 "calculation": {"date": "2026-04-15", "timezone": "UTC", "base": "2026.4",
                 "tag_base": "2026.4", "tag_patch": 2, "patch": 3},
 "config": {"mode": "month", "scheme": "YYYY.MM", "patch": true, "stable": true,
            "no_dev": false, "fallback": "dev", "tag_prefix": "v", "timezone": "UTC"},
 "config_sources": {"mode": "default", "scheme": "pyproject.toml",   // all eight settings; each is
                    "stable": "calver-scm.toml",                      // default, pyproject.toml,
                    "tag_prefix": "env CALVER_SCM_TAG_PREFIX"},       // calver-scm.toml or env CALVER_SCM_<NAME>
 "env_overrides": {"CALVER_SCM_NO_DEV": "true"}}      // {} when none are set

// doctor
{"status": "warning",                                // ok, warning or error
 "checks": [{"code": "no_compatible_tag", "severity": "warning",
             "summary": "No tag fits the configured CalVer scheme",
             "detail": "The fallback applied; the tag seen was '0.0'.",
             "remediation": "Tag a release, for example v2026.4.0, …"}]}

validate error codes

Code Meaning
missing_tag_prefix With --tag, the input does not start with the configured tag_prefix.
invalid_pep440 Not a valid PEP 440 version.
missing_stability_prefix stable = false, but the release does not start with 0..
unexpected_stability_prefix stable = true, but the release starts with 0..
invalid_release_shape The wrong number of components for your scheme.
invalid_year, invalid_month, invalid_week, invalid_day A date component is outside its calendar range.
tag_exists With --against-repo, the tag (or the same version spelled differently) already exists and is not the tag at HEAD.
past_period With --against-repo, the tag belongs to an earlier period than the current one.
skipped_patch With --against-repo, the patch is beyond the one next-tag would use for a final or pre-release tag.
lower_than_existing With --against-repo, a final tag is lower than an existing final tag.

doctor check codes

Code Severity Meaning
build_config ok or error The build is configured with version_scheme = "calver-scm" (setuptools or Hatch-VCS).
calver_config ok or error [tool.calver-scm], calver-scm.toml and the CALVER_SCM_* variables are valid.
settings_source info Which of pyproject.toml and calver-scm.toml supplied settings. Omitted when neither does.
settings_conflict warning A key has a different value in pyproject.toml and calver-scm.toml; calver-scm.toml wins.
env_overrides info CALVER_SCM_* variables are overriding the settings files.
git_available ok or error Git is installed and on PATH.
resolution ok or error The version resolves. Skipped when build_config fails.
shallow_checkout warning A shallow clone, so tags and commit distance may be missing.
no_compatible_tag warning No tag fits the scheme, so the fallback applied.
dirty_tree info There are uncommitted changes.
no_dev_local_segment warning no_dev does not remove the local version segment.

Without the cli extra the calver-scm command still exists but only prints how to install it.

Hooks and the GitHub Action

pre-commit hooks

For pre-commit or prek, the repository defines two hooks that run in the pre-push stage:

repos:
  - repo: https://github.com/samcorky/calver-scm
    rev: <a release that includes these hooks>
    hooks:
      - id: calver-scm-doctor
      - id: calver-scm-validate-tag
  • calver-scm-doctor runs calver-scm doctor before a push and also in the manual stage. Pass args: [--strict] to fail on warnings.
  • calver-scm-validate-tag checks the tag being pushed, as calver-scm validate --tag does, against the settings in the repository. A branch push is ignored. It runs the calver-scm-validate-pushed-tag command, which reads the pushed ref from PRE_COMMIT_REMOTE_BRANCH.

Both install calver-scm with its CLI extras into the hook's own environment, so nothing else needs installing.

calver-scm-validate-tag guards fewer tags than you might expect, because of how git and pre-commit run pre-push hooks:

  • git runs no pre-push hook at all for a tag on a commit the remote already has, which is the usual release flow (tag the commit on main, then push the tag). Such a tag is not checked.
  • It sees one ref per run, so a tag pushed in the same command as a branch is not checked.
  • It catches a tag on a new commit, for example git tag 2026.4.2 && git push origin 2026.4.2 with the prefix missing, which is stopped with the findings.

Use the GitHub Action below, or calver-scm validate "$GITHUB_REF_NAME" --tag --against-repo, as the check that cannot be skipped.

GitHub Action

The repository is also a GitHub Action that runs calver-scm in a workflow and passes the result on as step outputs and, by default, in the job summary:

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0 # the commands read the tags
      - id: plan
        uses: samcorky/calver-scm@<a release that includes the action>
        with:
          command: next-tag
          pre: rc
          calver-scm-version: "1.12.0" # pin it, see below
      - run: echo "Releasing ${{ steps.plan.outputs.tag }}"
Input Meaning
command Required: version, next-tag, validate, parse, doctor, explain or tags.
tag The tag to check, for validate and parse (required for them).
pre The channel (a, b or rc), for next-tag.
strict true to make doctor fail on warnings.
against-repo true to also check the tag against the repository's tags, for validate and parse.
root The project directory, if it is not the repository root. Default ..
summary true (the default) also writes the job summary, as --summary does.
calver-scm-version The release to install, such as 1.12.0. Empty installs the latest. installed runs the calver-scm already on PATH.

Outputs, from --format github: tag, version, is_prerelease and reason (next-tag), and valid, kind, period and is_prerelease (validate and parse). version also comes from version and parse. explain, doctor and tags have nested results, so they write the job summary only.

The action runs --summary and --format github, so it needs a calver-scm release that has them: the first release made after the action was added, not an older one. A pin to an older release fails with an unknown option.

Pin the version. With the input empty, each run installs the latest release, so a new release can change a build. Pin calver-scm-version, and let a dependency updater such as Renovate move the pin. A project that already locks calver-scm in its own environment can instead install that and use calver-scm-version: installed, so there is one version, not two.

The action passes its inputs to the script through environment variables, never by interpolating them into shell code, and rejects an unknown command, a missing tag, a tag that starts with a hyphen and a version that is not a version before anything is installed or run.


Requirements

  • Python >= 3.11
  • setuptools-scm >= 10.0.5
  • For the command line: the cli extra (installs Cyclopts, which also brings in Rich)

License

MIT

Metadata

Release files for calver-scm 1.12.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 calver-scm 1.12.0
File Size Uploaded Provenance Actions
calver_scm-1.12.0.tar.gz 189.1 kB Without provenance Details for calver_scm-1.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for calver-scm 1.12.0
File Interpreter ABI Platform Actions
calver_scm-1.12.0-py3-none-any.whl Python 3 none any Details for calver_scm-1.12.0-py3-none-any.whl

Total release size: 251.5 kB

Release files / calver_scm-1.12.0.tar.gz

Download URL calver_scm-1.12.0.tar.gz
Size 189.1 kB
Tags Source
SHA-256 checksum
How to use checksums
84d3f3161ed0f8a23f74f896ccb6b3c9a323237babf33e34f80319c1778502c6
BLAKE2b-256 checksum
How to use checksums
e01e8f363eb128f63b4a45c3b6ae5dddb6ca1f1b8da0bcfe7fc934448296bc6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / calver_scm-1.12.0-py3-none-any.whl

Download URL calver_scm-1.12.0-py3-none-any.whl
Size 62.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc7aa93cee85abd371b7f5af55982f0fe42360a2e18baf65fe4b7fee8f634490
BLAKE2b-256 checksum
How to use checksums
69121c2428bdc07d1905075256f3f75c62ea2fa5a639177a1e381f613d0e7351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for calver-scm 1.12.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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