Metadata-Version: 2.4
Name: frequenz-client-weather
Version: 0.2.2
Summary: Weather API Client for Python
Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
License: MIT
Project-URL: Documentation, https://frequenz-floss.github.io/frequenz-client-weather-python/
Project-URL: Changelog, https://github.com/frequenz-floss/frequenz-client-weather-python/releases
Project-URL: Issues, https://github.com/frequenz-floss/frequenz-client-weather-python/issues
Project-URL: Repository, https://github.com/frequenz-floss/frequenz-client-weather-python
Project-URL: Support, https://github.com/frequenz-floss/frequenz-client-weather-python/discussions/categories/support
Keywords: frequenz,python,lib,library,client-weather
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: <4,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typing-extensions<5,>=4.12.2
Requires-Dist: numpy<3,>=1.26.4
Requires-Dist: frequenz-api-common<0.7.0,>=0.6.0
Requires-Dist: googleapis-common-protos<2,>=1.56.4
Requires-Dist: frequenz-channels<2,>=1.6.1
Requires-Dist: frequenz-client-base<0.12,>=0.9.0
Requires-Dist: frequenz-api-weather<0.13.0,>=0.12.0
Provides-Extra: dev-flake8
Requires-Dist: flake8==7.2.0; extra == "dev-flake8"
Requires-Dist: flake8-docstrings==1.7.0; extra == "dev-flake8"
Requires-Dist: flake8-pyproject==1.2.3; extra == "dev-flake8"
Requires-Dist: pydoclint==0.6.6; extra == "dev-flake8"
Requires-Dist: pydocstyle==6.3.0; extra == "dev-flake8"
Provides-Extra: dev-formatting
Requires-Dist: black==25.1.0; extra == "dev-formatting"
Requires-Dist: isort==6.0.0; extra == "dev-formatting"
Provides-Extra: dev-mkdocs
Requires-Dist: Markdown==3.8; extra == "dev-mkdocs"
Requires-Dist: black==25.1.0; extra == "dev-mkdocs"
Requires-Dist: mike==2.1.3; extra == "dev-mkdocs"
Requires-Dist: mkdocs-gen-files==0.5.0; extra == "dev-mkdocs"
Requires-Dist: mkdocs-literate-nav==0.6.1; extra == "dev-mkdocs"
Requires-Dist: mkdocs-macros-plugin==1.3.7; extra == "dev-mkdocs"
Requires-Dist: mkdocs-material==9.6.2; extra == "dev-mkdocs"
Requires-Dist: mkdocstrings[python]==0.29.1; extra == "dev-mkdocs"
Requires-Dist: mkdocstrings-python==1.16.10; extra == "dev-mkdocs"
Requires-Dist: frequenz-repo-config[lib]==0.13.2; extra == "dev-mkdocs"
Provides-Extra: dev-mypy
Requires-Dist: mypy==1.15.0; extra == "dev-mypy"
Requires-Dist: types-Markdown==3.8.0.20250415; extra == "dev-mypy"
Requires-Dist: types-protobuf==5.29.1.20250208; extra == "dev-mypy"
Requires-Dist: frequenz-client-weather[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-mypy"
Provides-Extra: dev-noxfile
Requires-Dist: nox==2025.5.1; extra == "dev-noxfile"
Requires-Dist: frequenz-repo-config[lib]==0.13.2; extra == "dev-noxfile"
Provides-Extra: dev-pylint
Requires-Dist: frequenz-client-weather[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-pylint"
Provides-Extra: dev-pytest
Requires-Dist: pytest==8.3.4; extra == "dev-pytest"
Requires-Dist: pylint==3.3.4; extra == "dev-pytest"
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.13.2; extra == "dev-pytest"
Requires-Dist: pytest-mock==3.14.0; extra == "dev-pytest"
Requires-Dist: pytest-asyncio==0.26.0; extra == "dev-pytest"
Requires-Dist: async-solipsism==0.7; extra == "dev-pytest"
Provides-Extra: dev
Requires-Dist: frequenz-client-weather[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]; extra == "dev"
Dynamic: license-file

# Frequenz Weather API Client

[![Build Status](https://github.com/frequenz-floss/frequenz-client-weather-python/actions/workflows/ci.yaml/badge.svg)](https://github.com/frequenz-floss/frequenz-client-weather-python/actions/workflows/ci.yaml)
[![PyPI Package](https://img.shields.io/pypi/v/frequenz-client-weather)](https://pypi.org/project/frequenz-client-weather/)
[![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-client-weather-python/)

## Introduction

Weather API Client for Python providing access to historical and live weather forecast data.

## Supported Platforms

The following platforms are officially supported (tested):

- **Python:** 3.11
- **Operating System:** Ubuntu Linux 20.04
- **Architectures:** amd64, arm64

## Contributing

If you want to know how to build this project and contribute to it, please
check out the [Contributing Guide](CONTRIBUTING.md).

## Usage

### Installation

```bash
pip install frequenz-client-weather
```

### Available Features

The available features are listed [here](https://github.com/frequenz-floss/frequenz-api-weather/blob/v0.x.x/proto/frequenz/api/weather/weather.proto#L42).

### Initialize the client

The Client can optionally be initialized with keep alive.

```python
from frequenz.client.weather import Client
from frequenz.client.base.channel import ChannelOptions, KeepAliveOptions, SslOptions
from datetime import timedelta

client = Client(
    service_address,
    channel_defaults=ChannelOptions(
        ssl=SslOptions(
            enabled=False,
        ),
        keep_alive=KeepAliveOptions(
            enabled=True,
            timeout=timedelta(minutes=5),
            interval=timedelta(seconds=20),
        ),
    ),
)
```

### Get historical weather forecast

```python
from datetime import datetime
import pandas as pd
from frequenz.client.weather._types import ForecastFeature, Location

# Define a list of locations, features and a time range to request historical forecasts for
locations = [Location(latitude=46.2276, longitude=15.2137, country_code="DE")]
features = [ForecastFeature.TEMPERATURE_2_METRE, ForecastFeature.V_WIND_COMPONENT_10_METRE]
start = datetime(2024, 1, 1)
end = datetime(2024, 1, 31)

forecast_iterator = client.hist_forecast_iterator(
    features=features, locations=locations, start=start, end=end
)

# Collect and flatten forecasts
flat_forecasts = [f.flatten() async for f in forecast_iterator]
forecast_records = [record for batch in flat_forecasts for record in batch]

# E.g. convert to DataFrame and sort
forecast_df = pd.DataFrame(forecast_records).sort_values(["creation_ts", "validity_ts", "latitude", "longitude"])
print(forecast_df)
```

### Get live weather forecast

```python
import pandas as pd
from frequenz.client.weather._types import ForecastFeature, Location

# Define a list of locations and features to request live forecasts for
locations = [Location(latitude=46.2276, longitude=15.2137, country_code="DE")]
features = [ForecastFeature.TEMPERATURE_2_METRE, ForecastFeature.V_WIND_COMPONENT_10_METRE]

# Returns a Receiver object that can be iterated over asynchronously
stream = await client.stream_live_forecast(
    locations=locations,
    features=features,
)

# Process incoming forecasts as they arrive
async for forecast in stream:
    # The to_ndarray_vlf method converts the forecast data to a 3D numpy array,
    # where the dimensions correspond to validity_ts, location, feature
    # The method can also take filters for validity_ts, locations and features
    # E.g. filter the forecast for wind features
    wind_forecast = forecast.to_ndarray_vlf(features=[ForecastFeature.V_WIND_COMPONENT_10_METRE])
    print(wind_forecast)

```
## Command Line Interface

The package also provides a command line interface to get weather forecast data.
Use `-h` to see the available options.

### Get historical weather forecast

```bash
weather-cli \
    --url <service-address> \
    --location "40,15" \
    --feature U_WIND_COMPONENT_100_METRE \
    --start 2024-03-14 \
    --end 2024-03-15 \
    --mode historical
```

### Get live weather forecast

```bash
weather-cli \
    --url <service-address> \
    --location "40, 15" \
    --feature TEMPERATURE_2_METRE \
    --mode live
```

