Home > other >  Get the current version of the current package in Python
Get the current version of the current package in Python

Time:11-30

I am building a Python library and I have the requirement inside one of the modules to get the current version of this same library and make decisions based on the current version. Is this possible in Python? What do you think is the best approach?

CodePudding user response:

You should use dir(package) to see all the possible options for that package. If there is __version__, you can use that.

CodePudding user response:

I found that the version of my library is being pulled from Github upon every release by setuptools_scm The developers of setuptools_scm provides some tips on retrieving package version at runtime:

https://github.com/pypa/setuptools_scm#retrieving-package-version-at-runtime

Looks like using importlib.metadata is the way to go.

  • Related