Skip to main content

hydropeak-opendata

Async Python client for Hydro-Québec's public peak events (pointes hivernales) open data. No account, no login — just the open data feed.

Powers the Hydro-Québec Peak Events integration in Home Assistant.

Data sources

Data comes from Hydro-Québec's open data portal.

During Quebec winters (December 1 to March 31), Hydro-Québec triggers peak demand events (événements de pointe) when electricity demand is high due to cold weather and operational constraints. Customers enrolled in participating offers (e.g. Winter Credit, Flex, Hilo) are asked to reduce their consumption during these events — typically in the morning (AM) or evening (PM) — and receive bill credits in return. The dataset is updated as events are scheduled, and covers both residential and business customers.

  • Peak events — scheduled peak demand events with start/end times, time period (AM/PM), duration, applicable offer, and customer sector.
  • Available offers — the list of programs available each season, with descriptions and validity dates (rate limited; intended for occasional use such as setup flows).

Usage

import aiohttp
from hydropeak_opendata import OpenDataClient

async def main():
    async with aiohttp.ClientSession() as session:
        client = OpenDataClient(session)

        offers = await client.get_available_offers()
        # ('Credit hivernal Residentiel (CPC-D)', 'Flex Residentiel (TPC-DPC)', ...)

        events = await client.get_events(offers[0])
        for event in events:
            print(event.start, event.end, event.period, event.duration)

Example output:

2026-01-22 06:00:00-05:00  2026-01-22 09:00:00-05:00  AM  3:00:00
2026-01-22 16:00:00-05:00  2026-01-22 20:00:00-05:00  PM  4:00:00

Check if a peak event is happening right now:

from datetime import datetime, timezone

events = await client.get_events()
now = datetime.now(timezone.utc)
active = [e for e in events if e.is_active(now)]

List the offers of one sector, e.g. for a setup form:

from datetime import date
from hydropeak_opendata import Sector

offers = await client.get_sector_offers(Sector.RESIDENTIAL, date.today())
# ('Credit hivernal Residentiel (CPC-D)', 'Flex Residentiel (TPC-DPC)')

Check that a configured offer is still published:

if not await client.is_offer_available(saved_offer, date.today()):
    ...  # Hydro-Québec no longer lists this offer

Notes:

  • Offer identifiers are the strings published in offresDisponibles, returned verbatim.
  • Hydro-Québec names the same offer differently across sources: the feed uses display names (Flex Residentiel (TPC-DPC)) while the offers and historical events datasets use bare codes (TPC-DPC). get_events(offer) matches on the normalized code, ignoring accents, letter case and extra whitespace, so TPC-DPC, tpc-dpc and Flex Résidentiel (TPC-DPC) all select the same events. normalize_offer_code() exposes that mapping (its known aliases live in OFFER_CODE_ALIASES in const.py), and PeakEvent.offer_code gives the code for an event.
  • build_events_table_url(offer) returns a link to the peak events table on the open data portal, refined to that offer. When the offer differs from its code (Flex Residentiel (TPC-DPC)), both spellings are refined; a bare code refines on the code alone.
  • get_offer_labels() maps each canonical offer identifier to a display label for UIs. Labels currently equal the identifiers; once Hydro-Québec publishes display titles in its open data, a library update will source labels from there without any change to the method's contract — persist the keys, show the values.
  • get_sector_offers(sector, today) lists the feed's offers plus offers from the offer descriptions dataset that have not ended by today, merged across spellings with the feed's spelling kept. CPC-D and TPC-DPC are residential; any other offer is residential only if its description says so, and business otherwise. If the descriptions endpoint fails, the feed alone is used.
  • is_offer_available(offer, today) tells whether an offer is still published: listed in the feed in any spelling, or in an offer description that ended at most 60 days before today. Descriptions are only fetched when the feed does not list the offer; if that fails, the feed alone decides.
  • Both methods take today from the caller, so the date follows the caller's timezone and tests can pin it.
  • The client sends conditional requests (If-None-Match) and serves its cached parse on 304 Not Modified, so frequent polling is cheap for both sides. Concurrent refreshes are serialized on a lock.
  • All datetimes from the feed are timezone-aware. PeakEventsFeed.last_execution is naive (the feed publishes it without an offset).
  • Errors raise typed exceptions: OpenDataConnectionError, OpenDataRateLimitError, OpenDataResponseError, OpenDataParseError — all subclasses of OpenDataError. Failures never silently return empty data.

Development

pip install -e .[dev]
ruff check .
mypy
pytest

License

MIT

Metadata

Release files for hydropeak-opendata 0.4.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 hydropeak-opendata 0.4.0
File Size Uploaded Provenance Actions
hydropeak_opendata-0.4.0.tar.gz 16.6 kB With provenance Details for hydropeak_opendata-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hydropeak-opendata 0.4.0
File Interpreter ABI Platform Actions
hydropeak_opendata-0.4.0-py3-none-any.whl Python 3 none any Details for hydropeak_opendata-0.4.0-py3-none-any.whl

Total release size: 29.1 kB

Release files / hydropeak_opendata-0.4.0.tar.gz

Download URL hydropeak_opendata-0.4.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f61e5750f8e8463d077c9ea990446604c55687461ce5a4a71f6cad1588563947
BLAKE2b-256 checksum
How to use checksums
749d140f9e71fa7841079975603a9fe9325e4b6d21de7b837a82cc7d304039dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 25, 2026.

Transparency log

Release files / hydropeak_opendata-0.4.0-py3-none-any.whl

Download URL hydropeak_opendata-0.4.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3f247c38ca97ee715bbad1c534405a908ba92adc47a771e2289f79bbeb8663d
BLAKE2b-256 checksum
How to use checksums
05957ed0f828ce13e557b0760dfd1e0f5396688e7a9c7a59d392ba41a8bb0280
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 25, 2026.

Transparency log

Security for hydropeak-opendata 0.4.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hydropeak_opendata-0.4.0.tar.gz

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 Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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