single-source
Access to the project version in Python code for PEP 621-style projects
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-sourceuv
uv add single-sourcepoetry
poetry add single-sourceInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
read-versionExtracts a version string or other variable…
permissive · top 15,000 on PyPI
pyproject-dependenciesExtracts and prints the direct dependencies…
permissive · top 15,000 on PyPI
pyproject-tomlParses and validates Python project metadata…
permissive · top 15,000 on PyPI
pyproject-parserParses and extracts metadata from…
permissive · top 15,000 on PyPI
pyproject-apiProvides a programmatic API to read and…
permissive · top 5,000 on PyPI
pyproject2condaConverts Python project dependencies from…
unclear · top 15,000 on PyPI
sphinx-pyprojectLoads Sphinx documentation configuration from…
permissive · top 15,000 on PyPI
versionsParses, compares, and validates semantic…
permissive · top 15,000 on PyPI
Flake8-pyprojectFlake8-pyproject enables Flake8 to read its…
permissive · top 5,000 on PyPI
etelemetryEtelemetry is a lightweight Python client that…
permissive · top 15,000 on PyPI