Skip to main content

Python wrapper for IMGW-PIB API.

Project description

GitHub Release PyPI PyPI - Downloads Buy me a coffee PayPal_Me Revolut.Me

imgw-pib

Python async wrapper for IMGW-PIB API.

Installation

You can install the library with pip:

pip install imgw-pib

How to use the library

"""Example of usage IMGW-PIB."""

import asyncio
import logging

from aiohttp import ClientError, ClientSession

from imgw_pib import ApiError, ImgwPib

logging.basicConfig(level=logging.DEBUG)

WEATHER_STATION_ID = "12200"
HYDROLOGICAL_STATION_ID = "154190050"


async def main() -> None:
    """Run main function."""
    async with ClientSession() as websession:
        try:
            imgwpib = await ImgwPib.create(
                websession,
                weather_station_id=WEATHER_STATION_ID,
                hydrological_station_id=HYDROLOGICAL_STATION_ID,
            )
            weather_data = await imgwpib.get_weather_data()
            hydrological_data = await imgwpib.get_hydrological_data()
        except ApiError as error:
            print(f"API Error: {error.status}")
        except ClientError as error:
            print(f"ClientError: {error}")
        except TimeoutError as error:
            print(f"TimeoutError: {error}")
        else:
            print(f"Weather stations: {imgwpib.weather_stations}")
            print(f"Weather data: {weather_data}")
            print(f"Hydrological stations: {imgwpib.hydrological_stations}")
            print(f"Hydrological data: {hydrological_data}")


loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()

Error handling

The library raises ApiError when the IMGW-PIB API returns an error, ClientError for network-related errors, and TimeoutError when a request times out.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imgw_pib-1.0.10.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imgw_pib-1.0.10-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file imgw_pib-1.0.10.tar.gz.

File metadata

  • Download URL: imgw_pib-1.0.10.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for imgw_pib-1.0.10.tar.gz
Algorithm Hash digest
SHA256 2da4108aa577f30a16a832cd3274a59ba577e8e209d13295cf2ea7d49d00e5d5
MD5 3002ee14106ee0df530217fe10421a9a
BLAKE2b-256 d4ad288c98839af1bf05a5bd2e4b0eda410e1db3050b7ab0c7d6674fec02c953

See more details on using hashes here.

File details

Details for the file imgw_pib-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: imgw_pib-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for imgw_pib-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 7f9f6d948d0795683270129a316b2e44a6dd589279018b8a778852d2fc1da16d
MD5 51d04301f666ccec9a0042bdd9205018
BLAKE2b-256 d4c8d900360c5e46b96757b2451bf6be48bdf6f2c9d3d2d6b64302727ee210ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page