Skip to main content

Python Wrapper for WeatherBit API

Latest PyPI version Supported Python

This module communicates with WeatherBit.io using their REST API. The module is only supporting the Free Tier API's, for which there is more information here.

For the Free Tier, data can be retrieved for the following:

  • Current Conditions
  • Forecast Data - Daily data.
  • Severe Weather Alerts

It will require an API Key to work, which can be retrieved for free at Weatherbit

The module is primarily written for the purpose of being used in Home Assistant for the Custom Integration called weatherbit but might be used for other purposes also.

Install

pyweatherbitdata is avaible on PyPi:

pip install pyweatherbitdata

Usage

This library is primarily designed to be used in an async context.

The main interface for the library is the pyweatherbitdata.WeatherBitApiClient. This interface takes 7 options:

  • api_key: (required) A Personal API Key retrieved from WeatherBit (See above).
  • latitude: (required) Latitude of the location needing data from.
  • longitude: (required) Longitude of the location needing data from.
  • units: (optional) Valid options here are metric or imperial. This module is set to always retrieve data in metric units, so conversion of values will only take place if if metric is not selected. Default value is metric
  • language: (optional) The language for all text values retrieved from WeatherBit. Default is en
  • homeassistant: (optional) Valid options are True or False. If set to True, there will be some unit types that will not be converted, as Home Assistant will take care of that. Default value is True

Example program

"""Test Program."""
from __future__ import annotations

import asyncio
import logging
import time

from pyweatherbitdata.api import WeatherBitApiClient
from pyweatherbitdata.data import (
    ObservationDescription,
    BaseDataDescription,
    ForecastDescription
)
from pyweatherbitdata.exceptions import (
    InvalidApiKey,
    RequestError,
    ResultError,
)

_LOGGER = logging.getLogger(__name__)

async def main() -> None:
    logging.basicConfig(level=logging.DEBUG)
    start = time.time()

    weatherbit = WeatherBitApiClient(
        "YOU_API_KEY",
        55.625053,
        12.136619,
        language="da",
    )
    try:
        await weatherbit.initialize()

    except InvalidApiKey as err:
        _LOGGER.debug(err)
    except RequestError as err:
        _LOGGER.debug(err)
    except ResultError as err:
        _LOGGER.debug(err)

    data: BaseDataDescription = weatherbit.station_data
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            print(field, "-", value)

    data: ObservationDescription = await weatherbit.update_sensors()
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            print(field, "-", value)

    data: ForecastDescription = await weatherbit.update_forecast()
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            print(field, "-", value)

    end = time.time()

    await weatherbit.req.close()

    _LOGGER.info("Execution time: %s seconds", end - start)

asyncio.run(main())

Metadata

Release files for pyweatherbitdata 1.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyweatherbitdata 1.0.15
File Size Uploaded
pyweatherbitdata-1.0.15.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyweatherbitdata 1.0.15
File Interpreter ABI Platform
pyweatherbitdata-1.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / pyweatherbitdata-1.0.15.tar.gz

Download URL pyweatherbitdata-1.0.15.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9d72bcd57b09ab71d39fe3310f49b89f8f322227a9b88d097ef82ed001393642
BLAKE2b-256 checksum
How to use checksums
81c791bf0fbcbe1d2c1aedfb3815ed88d5d0c6358bfe711d9b1c3ef621eacf2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / pyweatherbitdata-1.0.15-py3-none-any.whl

Download URL pyweatherbitdata-1.0.15-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
593b076b941d3dfac96a2d7fde55447c5a28287ada9eeeb41172bac98bf895c7
BLAKE2b-256 checksum
How to use checksums
e5cdb97d02b35494722f56ffc0d6241de360d71dcd51f0acfc8f04763931074e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release history Release notifications | RSS feed

This release

1.0.15 This release

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page