--- id: single-source version: "0.4.0" license: MIT license_treatment: permissive maintenance: dormant --- # single-source — Access to the project version in Python code for PEP 621-style projects License: permissive · Maintenance: dormant · Downloads: 401.7K/mo ## 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 above — 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 pip install single-source uv add single-source 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_current - Install friction: low - Maintenance: dormant - Downloads: 401.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags single source of truth version, pyproject.toml version in code, get package version python, avoid version duplication, dynamic version from config, poetry version access, __version__ from pyproject, version-management, pyproject-toml, build-tooling [View on SkillFed](https://skillfed.io/packages/single-source) · [View on PyPI](https://pypi.org/project/single-source/)