Skip to main content

Project-Version-Finder

Simple package to provide version informaion. The stratagy is

  • first look in pyproject.toml, if it is found. This is most accurate during develompent, but when running from an install it probably will not be found, so
  • second, use importlib.metadata (or importlib_metadata, if appropriate), which works if it is installed.

All you should need is

from project_version_finder import get_version
__version__ = get_version('project-name')

(and make project-version-finder a dependancy of your project).

If you do not want the search for pyproject.toml to start in the current working directory (which is often where you will automatically find your project in development in the python path), you can add a second argument specifying a file in the directory you wish to begin the search. Some suggestions (which may require all version tests during development to NOT have an installed version also available) are:

from project_version_finder import get_version
# start search in directory of the file that defines __version__
__version__ = get_version('project-name', __file__)

or

from project_version_finder import get_version
# start search in directory of the file that defines some function fn
__version__ = get_version('project-name', fn.__globals__['__file__'])

The key is to have a way to get the name of a file in the directory from which you wish the search to start. Bonus points if (like the default current working directory) this name will not follow the install files: then the result will work during development even if you have an older version installed.

It isn't fool proof, but since you provide the project name, if it finds the wrong pyproject.toml it should only fail if that happens to be for a different project with the same name.

Repository
PyPI

Metadata

Release files for project-version-finder 0.3.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 project-version-finder 0.3.0
File Size Uploaded
project_version_finder-0.3.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for project-version-finder 0.3.0
File Interpreter ABI Platform
project_version_finder-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / project_version_finder-0.3.0.tar.gz

Download URL project_version_finder-0.3.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
59a13e662d2f5f2fdd33dfdf501ba215543d2e456190364f42611196d5d5d5e3
BLAKE2b-256 checksum
How to use checksums
f055ca323737b30588ee49b9b6be3b295a7f91b438f835bb2492fd45c7e2ea53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.6

Release files / project_version_finder-0.3.0-py3-none-any.whl

Download URL project_version_finder-0.3.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe705c8b013ea57e90ff21fd020ff4b8fff1e0db3fe86c3fe205ce54582c42d1
BLAKE2b-256 checksum
How to use checksums
8a176b69a878e0dc104d8c59c06b6db2b0b474115114ddfbebb345a22ddf15aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.6

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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