eclipse / paho.mqtt.python

paho.mqtt.python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding __version__ so it can be queried

mmattel opened this issue · comments

Feature Description

It would be great to add a __version__ attribute based on semver which can be queried in the code like:

import paho.mqtt.client as mqtt
print(mqtt.__version__)

Note: The __version__ attribute is recommended by Python Enhancement Proposals (PEP) and is commonly implemented across many packages.

Additional Information

This would definitely help when upgrading the package when there are breaking changes as one could query the min/max version in the code and behave accordingly.

Which PEP recommend this, I don't find it ?
My search of PEP say that we should REMOVE the existing __version__: https://peps.python.org/pep-0396/#pep-rejection

This PEP say that we should do:

importlib.metadata.version("paho-mqtt")

I am in sorry, you are right, I misunderstood it... 🤦‍♂️

>>> from importlib.metadata import distribution
>>> dist = distribution('paho-mqtt')
>>> dist.version
'2.0.0'