Python wrapper around the Nerdbank.GitVersioning CLI
Project description
post_title: nbgv-python Package Overview author1: Shuai Zhang post_slug: nbgv-python microsoft_alias: shuzhang featured_image: "https://devblogs.microsoft.com/azuremigrate/wp-content/uploads/sites/113/2023/01/microsoft-logo.png" categories:
- Architecture tags:
- nbgv
- hatch
- versioning ai_note: This document was prepared with AI assistance. summary: Guidance for using the nbgv-python package to integrate Nerdbank.GitVersioning with hatchling projects. post_date: 2025-11-08
Overview
nbgv-pythonwraps the Nerdbank.GitVersioning CLI so Python projects can reuse the same versioning semantics.- The package discovers the CLI via
NBGV_PYTHON_COMMAND, a directnbgvexecutable, ordotnet tool run nbgvas a fallback. - A Hatch version source plugin is provided, allowing projects to declare
dynamic = ["version"]and resolve their version at build time.
Installation
- Install the package into your monorepo environment using
uv add --package nbgv-python nbgv-python. - Ensure the
nbgvCLI is available either as a global .NET tool (dotnet tool install -g nbgv) or via a local tool manifest. - Optionally set
NBGV_PYTHON_COMMANDwhen the executable lives outside ofPATHor requires additional arguments.
Hatch Integration
Add the plugin to your project configuration:
[project]
dynamic = ["version"]
[tool.hatch.version]
source = "nbgv"
[tool.hatch.version.nbgv]
version-field = "simple_version"
During builds Hatch invokes nbgv get-version --format json in the project root and uses the selected field for the package version.
Additional configuration keys include command (override CLI invocation) and working-directory (relative path for the repository root).
The plugin normalizes the chosen value to a PEP 440 compliant version, so SemVer pre-release tags such as -beta.1 are mapped to b1 automatically.
Python API
Retrieve version metadata directly from Python code:
from nbgv_python import get_version
version = get_version()
print(version["simple_version"]) # -> 1.2.3
Forward arbitrary commands to the CLI:
from nbgv_python import forward
forward(["cloud", "--ci"])
All helpers raise NbgvNotFoundError when the CLI cannot be resolved and NbgvCommandError for non-zero exit codes.
Command-Line Usage
The console script nbgv-python proxies all arguments to the real CLI:
nbgv-python get-version --format json
The wrapper surfaces the same exit codes as the underlying tool and prints diagnostic guidance when the command cannot be located.
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 nbgv_python-1.0.0b1.tar.gz.
File metadata
- Download URL: nbgv_python-1.0.0b1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d119a8d28c599364354ca3cc8d8a87bb7e7b5150cb66ea97545252f74d50f0fb
|
|
| MD5 |
f5135530527312230565fcc48fab2363
|
|
| BLAKE2b-256 |
8bcc2583d3c75fdad593e5f7f26d381983abd4494da4a8c2a51d6e6cded98acd
|
File details
Details for the file nbgv_python-1.0.0b1-py3-none-any.whl.
File metadata
- Download URL: nbgv_python-1.0.0b1-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34e2eae5ee903e22647c63e179989683e31a41f95a90599fd8c1ad8e887bc74a
|
|
| MD5 |
93159a4ce089e223679f752169d51dcd
|
|
| BLAKE2b-256 |
a588613716372a78d40488c1aaf8025d466879cd8236c87ddf6814560eb4583e
|