Skip to main content

pyproject.toml → version

PyPI GitHub Release

Get version from pyproject.toml - static or dynamic, regardless of backend.

Usage

The whole point of this package - in one example:

from pyproject_toml_version import pyproject_version
# Or just wildcard import, since this ^ is the only public member of the package:
from pyproject_toml_version import *

version: str = pyproject_version('pyproject.toml')

# Or the first argument could be omitted,
# if the path is literally just 'pyproject.toml':
version = pyproject_version()

# And to use dynamic versions with not-yet-supported backends (see below):
version = pyproject_version(dynamic_field='tool.unknown.version.file-path')

Fallback mode

Assume you have the following file structure:

Your project root
 ├─ pyproject.toml
 └─📂src
    └─📂my_module
       ├─ __init__.py
       ├─ ...
       └─ __version_meta.py

And you use a dynamic version, AND your build-backend is anything but Hatchling - so you have pyproject.toml like this:

[build-system]
build-backend = "not-yet-explicitly-supported-backend.build"

[project]
dynamic = ["version"]

[tool.some-unknown-build.version]
dyn_ver_path = "src/my_module/__version_meta.py"

Very likely (almost guaranteed), that pyproject-toml-version would still work for you just fine - try it:

version = pyproject_version(dynamic_field='tool.some-unknown-build.version.dyn_ver_path')

pyproject-toml-version does some heuristics to attempt extracting the version regardless of the specific backend:

Fallback mode in detail

  • You do need to explicitly pass the dynamic_field arg to pyproject_version(): it tells what field in the pyproject.toml contains the path to a dynamic-version file.
    • For this example, it would be tool.some-unknown-build.version.dyn_ver_path
    • For Hatchling, there's no harm in passing it, but its value would simply be ignored.
  • Then, pyproject_version() reads the field from pyproject.toml and tries to determine the actual path to this dyn-ver-file:
    • The file must exist, must be a file (not a dir), and be a *.py type.
    • The path is treated as relative to the dir where pyproject.toml itself lives.
    • First, the path from this field is attempted to be interpreted literally - expecting slashes there (and a lack of them meaning the file is in the same dir).
    • On fail, the same field is interpreted as a pythonic module path - i.e., src.my_module.__version_meta for this example.
    • Early-error if a proper python file can't be found.
  • The version is attempted to be extracted - by trying to actually import the file as an isolated module (unaware of the rest of your project) and look for a matching variable:
    • The variable name must be __version__ or VERSION (case is ignored, so __VERSION__, version, VERsion etc. all match).
    • The variable must hold a string value.
    • __version__ takes precedence over VERSION.
  • If import fails (e.g., the module itself does some relative imports), a more "standard" regex-based search for the same variable names is performed, line by line.
    • The first match wins.
    • Like with real backends, pyproject-toml-version doesn't exclude the lines inside triple-quote multiline strings. So avoid having "version examples" in the module-level docstring.
  • v prefix is preserved (it's not for Hatchling, unless you specify a custom regex pattern).

Metadata

Release files for pyproject-toml-version 1.0.1

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

Source distribution (sdist)

Source distribution for pyproject-toml-version 1.0.1
File Size Uploaded Provenance Actions
pyproject_toml_version-1.0.1.tar.gz 30.2 kB With provenance Details for pyproject_toml_version-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyproject-toml-version 1.0.1
File Interpreter ABI Platform Actions
pyproject_toml_version-1.0.1-py3-none-any.whl Python 3 none any Details for pyproject_toml_version-1.0.1-py3-none-any.whl

Total release size: 52.0 kB

Release files / pyproject_toml_version-1.0.1.tar.gz

Download URL pyproject_toml_version-1.0.1.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b466aad856217e3a2b310503bdb4aed2a874a273f5e8679ea91f3115c2e6e434
BLAKE2b-256 checksum
How to use checksums
77329c368eeca48b05877c3d52680059abdf40caa7a842733156d65c259d8e30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 21, 2026.

Transparency log

Release files / pyproject_toml_version-1.0.1-py3-none-any.whl

Download URL pyproject_toml_version-1.0.1-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f32abb38a75d0119fa4339df0c4eca5eb7cae925b4469795740b25009b4ed28
BLAKE2b-256 checksum
How to use checksums
84fac1e1556a3076a76fbe14f1720ba0e27c6977df207e3ca5b40d9159aa88d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 21, 2026.

Transparency log

Security for pyproject-toml-version 1.0.1

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyproject_toml_version-1.0.1.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 Nov 21, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files Full provenance

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