import requests


def get_latest_version(package_name: str) -> str:
    """Get the latest release version of a package on PyPi by using the PyPi
    API.

    Parameters
    ----------

    package_name: str
        Name of the package

    Returns
    -------

    str
        Latest version of the package"""

    response = requests.get(url=f"https://pypi.org/pypi/{package_name}/json")

    if response.ok:
        content = response.json()
        return content.get("info").get("version")
    else:
        raise requests.ConnectionError()