Registry / devops / setuptools-git-versioning

setuptools-git-versioning

JSON →
library3.1.0pypypi✓ verified 23d ago

setuptools-git-versioning is a Python library that automatically infers package versions from Git repository data, adhering to PEP 440. It allows configuration via `pyproject.toml` or `setup.py`/`setup.cfg` and supports tag-, file-, and callback-based versioning schemas with flexible templating. The library is actively maintained, with frequent patch releases and occasional major version bumps introducing breaking changes.

pip install setuptools-git-versioning
INSTALL
IMPORT
SIG · SETUPTOOLS-GIT-VER
S
setuptools-git-versioning
devopspythonv3.1.0
Install
1.9s avg
Import
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.9s · import 0.000s · 19MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

setuptools-git-versioning
python -m setuptools_git_versioning
Used as a command-line tool or via `python -m` to inspect the inferred version; direct internal Python imports are discouraged for application runtime use.

Configure `setuptools-git-versioning` in your `pyproject.toml` to dynamically set your package's version based on Git tags and repository state. Ensure `setuptools-git-versioning` is in `build-system.requires` and `project.dynamic = ["version"]` is set.

[build-system] requires = ["setuptools>=41", "wheel", "setuptools-git-versioning>=3.0,<4"] build-backend = "setuptools.build_meta" [project] name = "my_package" dynamic = ["version"] [tool.setuptools-git-versioning] enabled = true # Optional: Customize version format # template = "{tag}.post{ccount}+{gitsha}" # dev_template = "{tag}.dev{ccount}+{gitsha}" # dirty_template = "{tag}.dirty{ccount}+{gitsha}"
Debug
Known issues
breakingVersion 3.0.0 introduced breaking changes: most arguments in `version_from_git` became keyword-only, `version_from_git` and `infer_version` now return `packaging.version.Version` objects instead of strings, and timestamps in version templates are now timezone-aware.
fix
Review calls to `version_from_git` or `infer_version` (if used against recommendations), ensure keyword arguments are used, and adapt code expecting a string return type or naive timestamps.
affects: >=3.0.0
breakingVersion 2.0.0 removed the deprecated `get_branch_tags` function and the `version_config` keyword argument from `setup.py`. It also changed the precedence for the `version_file` option, which now takes priority over tags in the current branch.
fix
Remove usages of `get_branch_tags` and `version_config`. If relying on tag-based versioning, be aware `version_file` will override it if present.
affects: >=2.0.0
gotchaBuilding in environments without `git` installed or from shallow clones (e.g., GitHub tarballs or CI/CD without full `git` history) can cause `OSError` exceptions or incorrect version detection. The library relies on `git` executable and a full `.git` folder.
fix
Ensure `git` is installed and the repository has its full `.git` history. For CI/CD, use `git fetch --unshallow` or configure your CI to not use shallow clones. Alternatively, use the `version_file` option to store the version, or provide an environment variable to override it if the library supports it (though `setuptools-git-versioning` officially recommends `version_file` for this scenario).
affects: All versions
gotchaThe package can report a 'dirty' version (e.g., `1.2.3.post0+git.d2bc6516.dirty`) if there are untracked or uncommitted changes in the repository during the build. This is common in CI pipelines due to build artifacts.
fix
Add build artifacts and other temporary files to your `.gitignore` file to ensure the repository state is 'clean' during packaging.
affects: All versions
gotchaIf you define a static `version = "X.Y.Z"` in the `[project]` section of `pyproject.toml`, `setuptools-git-versioning` will be ignored.
fix
To enable dynamic versioning, remove the `version` field from `[project]` and instead add `dynamic = ["version"]` to the `[project]` section.
affects: All versions
gotchaDirectly calling internal functions like `setuptools_git_versioning.get_version()` or `get_tag()` from your application's runtime code is strongly discouraged and unsupported. These functions are not part of the public API and may change without backward compatibility. Furthermore, the `.git` folder is not included in the installed package.
fix
To retrieve the package version at runtime, use `importlib.metadata.version('your-package-name')` (Python 3.8+) or configure `version_file` to write the version to a file within your package during build, and then read that file at runtime.
affects: All versions
Upgrade
Version history
3.1.0latest on PyPI · released May 15, 2026
Audit
Dependencies
setuptoolsrequiredBuild-system requirement for package metadata and build backend.
wheelrequiredBuild-system requirement for building distribution archives.
Agent activity
9 hits · last 30 days
node
6
Amazon
1
Resources
setuptools-git-versioning — pip install setuptools-git-versioning · libregistry