Skip to main content

single-version

https://madewithlove.now.sh/vn?heart=true&colorA=%23ffcd00&colorB=%23da251d https://badgen.net/pypi/v/single-version

Utility to let you have a single source of version in your code base.

This utility targets modern Python projects which have layout generated by Poetry, with a pyproject.toml file in place of setup.py. With this layout, the project initially has two places to maintain version string: one in pyproject.toml file and one in some *.py file (normally __init__.py):

# pyproject.toml
[tool.poetry]
name = "your-package"
version = "0.1.0"
# your_package/__init__.py
__version__ = "0.1.0"

This duplicity often leads to inconsistency when you, the author, forget to update both.

single-version was born to solve that headache circumstance. By convention, it chooses the pyproject.toml file as original source of version string. Your project’s __version__ variable then is computed from it. When your package is already deployed and installed to some system, the version string will be retrieved from that Python environment (the pyproject.toml is not included in distribution file).

Years ago, to retrieve version for an installed package, people often used pkg_resources, which has well-known issue of causing slow import. Learning from that mistake, single-version use importlib.metadata, which becomes standard from Python 3.8, instead.

Usage

Add single_version as your project dependency:

poetry add single-version

Assume that your package source tree is like this:

.
├── awesome_name
│  └── __init__.py
├── pyproject.toml
├── README.rst
└── tests/

where the __version__ variable is defined in awesome_name/__init__.py file. The file content can be like this:

from pathlib import Path

from single_version import get_version


__version__ = get_version('awesome_name', Path(__file__).parent.parent)

API Reference

def get_version (package_name: str, looked_path: Path) -> str

  • package_name: Your package’s name (same as in pyproject.toml file).

  • looked_path (of pathlib.Path type): Folder where your project’s pyproject.toml resides.

Metadata

Release files for single-version 1.6.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 single-version 1.6.0
File Size Uploaded Provenance Actions
single_version-1.6.0.tar.gz 3.6 kB Without provenance Details for single_version-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for single-version 1.6.0
File Interpreter ABI Platform Actions
single_version-1.6.0-py3-none-any.whl Python 3 none any Details for single_version-1.6.0-py3-none-any.whl

Total release size: 7.8 kB

Release files / single_version-1.6.0.tar.gz

Download URL single_version-1.6.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3b1fb6e9bd2c88268948d9191c78b63ddd3c07554c1f07cd8a85aedf2486e4fc
BLAKE2b-256 checksum
How to use checksums
a659108dcfe49cde1f7f976445ae0e8c66dc2cdc6114dcfaf664afa8d5702f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.2 Linux/6.2.0-27-generic

Release files / single_version-1.6.0-py3-none-any.whl

Download URL single_version-1.6.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67a2734e728b9554750e867b33591f3ad9509ccb851bb3047ced7bfe68429ecd
BLAKE2b-256 checksum
How to use checksums
61b5ffbbc700075f6d07164dea524b81a495689d18a0f6dd44f07c8cdfeb9fb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.2 Linux/6.2.0-27-generic

Security for single-version 1.6.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