Skip to main content

sversion

PyPI version Python 3.14+ License: MIT

Zero-config version retrieval for Python packages. Pass __file__ and get your package version back — no hard-coding, no import tricks, no build-time templating.

Supports pyproject.toml (PEP 621 and Poetry layouts) and plain VERSION.txt files.

Install

pip install sversion

Quick start

The most common use is exposing __version__ from a package __init__.py:

# my_package/__init__.py
from sversion.pyproject_toml_based import get_version

__version__ = get_version(__file__)

get_version walks up from my_package/ until it finds pyproject.toml and reads the version from it. No path configuration needed.

How the search works

Starting at the path you pass, both strategies walk up the directory tree level by level until the target file is found or the filesystem root is reached:

my_repo/
├── my_package/
│   └── __init__.py   ← pass __file__ here
├── tests/
└── pyproject.toml    ← found here, version returned

Both file paths and directory paths are accepted. When a file is passed, the search starts in its parent directory.


From pyproject.toml

Reads project.version (PEP 621) or tool.poetry.version:

from sversion.pyproject_toml_based import get_version

version = get_version(__file__)             # "1.2.3"
version = get_version("/path/to/project")  # directory path also works

Use project_file_name to look for a non-standard filename:

version = get_version(__file__, project_file_name="my_project.toml")

From a version file

Reads the trimmed contents of a VERSION.txt file:

from sversion.version_file_based import get_version

version = get_version(__file__)
version = get_version(__file__, version_file_name="RELEASE")  # custom filename

Error handling

Both functions raise VersionNotFoundException when no matching file is found before reaching the filesystem root:

from sversion.pyproject_toml_based import get_version
from sversion.error_handling import VersionNotFoundException

try:
    version = get_version(__file__)
except VersionNotFoundException as e:
    version = "unknown"

API

# pyproject_toml_based
get_version(start_search_path: str, project_file_name: str = "pyproject.toml") -> str

# version_file_based
get_version(start_search_path: str, version_file_name: str = "VERSION.txt") -> str

Both raise sversion.error_handling.VersionNotFoundException on failure.


License

MIT

Metadata

Release files for sversion 2.5.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 sversion 2.5.0
File Size Uploaded Provenance Actions
sversion-2.5.0.tar.gz 8.0 kB Without provenance Details for sversion-2.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 14.1 kB

Release files / sversion-2.5.0.tar.gz

Download URL sversion-2.5.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
18b9e129197bc53cba2670908501192307b7ce20424b7ec2bbeb229911587781
BLAKE2b-256 checksum
How to use checksums
ae929b103fdcc331b3171812b1684e5bf902b6d411d010e651996d5f9fe39ae3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / sversion-2.5.0-py3-none-any.whl

Download URL sversion-2.5.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12e57c4d476b842aeb4e13574ca69dc7a30f01197f9012ced19d1d9d2a9e4023
BLAKE2b-256 checksum
How to use checksums
16d28313b197823574250af66b8c5bb2846f76e07a6a585ab9ef0751206542a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for sversion 2.5.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