skillfed

single-source

Access to the project version in Python code for PEP 621-style projects

single-source v0.4.0 401.7K downloads/30d#6,924 on PyPI53
Permissive license MIT DORMANT released

What it is and what it does

single-source solves the version duplication problem in modern Python projects. When you define your package version in pyproject.toml (or setup.py), you often need that same version string accessible in your Python code at runtime—typically in an `__version__` variable. Rather than manually copying the version into your source files and maintaining two copies, single-source reads the version from your config file on import, keeping a single source of truth.

The package exports a `get_version()` function that takes your package name and the path to your project root, then searches for a version string in pyproject.toml or other config files using a built-in regex pattern. You can customize the search with your own regex, set a default fallback value, or raise an exception if the version is not found. It supports Python 3.8 through 3.12 and has no runtime dependencies.

Use it for:

  • Keep version in pyproject.toml only and read it into `__version__` at runtime without manual duplication.
  • Migrate to PEP 621 pyproject.toml while still exposing version in your package code.
  • Extract version from custom config files using a regex pattern when the default parser does not match your format.
  • Raise an exception at import time if version metadata is missing, catching configuration errors early.
  • Support Poetry-managed projects that use version commands without needing to edit Python source files.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Extracts your package version from pyproject.toml or other config files and makes it available in Python code, eliminating the need to duplicate version strings.

Yes, if you are starting a new project or migrating to pyproject.toml and want to avoid version duplication. The package is lightweight, has no dependencies, and solves a real problem. However, maintenance is dormant, so consider whether you are comfortable with a stable-but-not-actively-maintained tool. For established projects already managing version duplication successfully, the benefit may not justify adding a dependency.

Install

single-source on PyPI

pip

pip install single-source

uv

uv add single-source

poetry

poetry add single-source

Installing single-source

Before you install

Low friction installation with no runtime dependencies. Maintenance is dormant—last release was in June 2024 and the repository remains active as of January 2025, but no recent development activity.

License in practice

MIT license is permissive; you may use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.

Quickstart

pip install single-source

# root_package/__init__.py
from pathlib import Path
from single_source import get_version

__version__ = get_version(__name__, Path(__file__).parent.parent)

Requires Python 3.8 or later; your project must have a pyproject.toml or similar config file containing a version string.

Verify before relying

  • Whether dormant maintenance status poses a risk for future Python compatibility or bug fixes.
  • Real-world success rate of the default regex pattern across diverse project structures and version formats.
  • Whether the package will receive updates for Python versions beyond 3.12.

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0,>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance dormant — 794 days since the last release
Last repo commit
First released
Downloads 401,720/month — #6,924 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: single_source-0.4.0-py3-none-any.whl

Keywords: pyproject, version, __version__, poetry, single source

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

single source of truth versionpyproject.toml version in codeget package version pythonavoid version duplicationdynamic version from configpoetry version access__version__ from pyproject
version-managementpyproject-tomlbuild-tooling

More Python Modules packages