Get info about the latest release of a package on PyPI.
pip install --upgrade verlat
from verlat import latest_release
package = "verlat" # name of the package on PyPI
release = latest_release(package)
print(release.version)
Many CLI apps like
pip
or
gh
produce warnings if you are not using their latest release.
Using verlat
you can fetch information about the latest release
of your package on PyPI.
You can then compare the version strings of the latest release and
the currently running program.
Based on whether it is a major or minor release, or whatever logic you have,
you can log useful information for the user.
For dealing with version strings, you may use the
packaging
library.
Here is an example code that demonstrates practical application of verlat
.
NOTE Assuming that you have build your python package using
poetry
, and theversion
key exists under[tool.poetry]
of yourpyproject.toml
file.
# __init__.py
import logging
from importlib.metadata import version
from verlat import latest_release
__version__ = version(__package__)
latest = latest_release(__package__)
def major(string):
# based on semantic versioning
return int(string.split(".", 1)[0])
if major(__version__) < major(latest.version):
logging.warning(
f"A new major release for {__package__} is availaible.\
\nDownload it from {latest.release_url}"
)