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.5.4.tar.gz (25.2 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.5.4-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: imgw_pib-1.5.4.tar.gz
  • Upload date:
  • Size: 25.2 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.5.4.tar.gz
Algorithm Hash digest
SHA256 531c775fdc00585b881e8cdce7e17b8ce0b70f86f14704a60a73d7b02343bc33
MD5 518f734c34f105b6062e8ae2d4aa8d01
BLAKE2b-256 f8dcb7ce835ae5f9e0b9cbf2241d77c8e64dc559033a3185755c897167942eb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: imgw_pib-1.5.4-py3-none-any.whl
  • Upload date:
  • Size: 22.3 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.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b340a4dc57d89f68c9bf42a8f8f225db68884fd0a0455354a5d205ad367ca0f5
MD5 30eda80acb34d82d4b2595d63920c778
BLAKE2b-256 793d319f6ee5c5972e653c50ba8a904814b7b60a7e974d6cce56d0201f0ab71d

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