Skip to main content

Small utility to define version string for Poetry-style Python project.

Project description

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 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

# pyproject.toml
name = "your-package"
version = "0.1.0"
# your_package/
__version__ = "0.1.0"

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

single-version is 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, ones 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.


Add single_version as your project dependency:

poetry add single-version

Assume that you define __version__ variable in your_package/ file:

from pathlib import Path

from single_version import get_version

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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for single-version, version 1.1
Filename, size File type Python version Upload date Hashes
Filename, size single_version-1.1-py3-none-any.whl (3.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size single-version-1.1.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page