Skip to main content

hydopt-client

Python client for the HydOpt hydropower optimization API.

Install

uv add hydopt-client

Authentication

Every provider implements TokenProvider and plugs into the client via Client(token_provider=...). The default is ServiceAccountTokenProvider targeting WEB_CLIENT_ID, the OAuth client id the HydOpt API accepts as token audience.

Local development — mint an ID token from a service account key:

from hydopt_client.auth import WEB_CLIENT_ID, ServiceAccountTokenProvider
from hydopt_client.client import Client

client = Client(
    token_provider=ServiceAccountTokenProvider(
        audience=WEB_CLIENT_ID,
        key_path="/path/to/sa-key.json",
    )
)

Create the key in Google Cloud Console (IAM & Admin → Service Accounts → Keys, project hydopt) or with:

gcloud iam service-accounts keys create ~/.config/gcloud/hydopt-sa.json \
    --iam-account <SA_EMAIL> --project hydopt

If key_path is omitted, credentials are resolved through Application Default Credentials. Locally, point GOOGLE_APPLICATION_CREDENTIALS at your key file before running:

export GOOGLE_APPLICATION_CREDENTIALS=$HOME/.config/gcloud/hydopt-sa.json
uv run streamlit run examples/streamlit_app.py

Note: end-user credentials from gcloud auth application-default login do not work for this flow — use a service account key. Keep the key file outside any git repository.

Deployed on Cloud Run — mints a service-to-service ID token for WEB_CLIENT_ID via the metadata server (no key file needed). Only without a configured audience does it forward the IAP JWT injected into the incoming request — such forwarded tokens carry this app's own IAP client id as audience and are only accepted by APIs that explicitly trust it:

from hydopt_client.auth import WEB_CLIENT_ID
from hydopt_client.auth.iap import CloudRunIAPTokenProvider  # requires streamlit

client = Client(token_provider=CloudRunIAPTokenProvider(audience=WEB_CLIENT_ID))

The bundled example app picks automatically: CloudRunIAPTokenProvider when it detects it runs on Cloud Run (K_SERVICE env var), ServiceAccountTokenProvider otherwise.

Quick Start

from hydopt_client.client import Client

client = Client()

# List available partition dates
dates = client.list_partitions()
print(dates)  # ["2026-01-01", "2026-01-02", ...]

# Fetch a time series
records = client.series(dates[0], "production")
for record in records:
    print(record.name, record.x[0], record.y[0])

# Filter and group results
from hydopt_client.client import Filters, GroupBy

filtered = client.series(
    dates[0],
    "production",
    filters=Filters(country=["norway"]),
    group_by=[GroupBy.region],
)

Available Methods

Method Description
list_partitions() List available partition dates
series(asof, category1, ...) Query time-series data
diff(category1, from, to, ...) Compare two partitions
static(category1, ...) Query static dataset
realized(category1, ...) Query realized dataset
anomaly(asof, category1, ...) Subtract Normal from Forecast, History, Actual, and/or Actual region. Filter with Filters(value_type=["Forecast"]) (repeat values for several); omit value_type to get all four.
hierarchy_layers(asof, graph=...) Owners, regions, and other graph layers
catchments(asof) Fetch catchment geometries
orders(asof) Fetch energy orders
object_report(source, target) Compare two partition objects

Metadata

Release files for hydopt-client 0.5.0

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

Source distribution (sdist)

Source distribution for hydopt-client 0.5.0
File Size Uploaded
hydopt_client-0.5.0.tar.gz 116.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hydopt-client 0.5.0
File Interpreter ABI Platform
hydopt_client-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 127.7 kB

Release files / hydopt_client-0.5.0.tar.gz

Download URL hydopt_client-0.5.0.tar.gz
Size 116.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ac6f992c7e48108c87d0e2d7ee5cac8aa2ba7f4ac47f409b44d37a77a6e79cd8
BLAKE2b-256 checksum
How to use checksums
90fe01ca63d264ea0248eaeb0429dcfd9fa06593df138f9f5318792e7ffb2546
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / hydopt_client-0.5.0-py3-none-any.whl

Download URL hydopt_client-0.5.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72457213c8aa7d672b5277d8a8c84a1c894f4cb0a1d300459bae9ce9685140b6
BLAKE2b-256 checksum
How to use checksums
608f6b0890d6591578326a9a796d547b9f17a6f5ba95da2957765f603d3b5bd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

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