Skip to content
/ verlat Public

Get info about the latest release of a package on PyPI.

License

Notifications You must be signed in to change notification settings

aahnik/verlat

Repository files navigation

verlat

Get info about the latest release of a package on PyPI.

Code Quality Tests codecov PyPI - Python Version

Installation

pip install --upgrade verlat

Usage

from verlat import latest_release

package = "verlat" # name of the package on PyPI
release = latest_release(package)
print(release.version)

Application

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 the version key exists under [tool.poetry] of your pyproject.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}"
    )