Skip to main content

Get your Hydro Quebec electiricty data

Project description

hydroq-api

PyPI Tests Changelog License

Get your Hydro Quebec electiricty data

The project is influenced by hydroqc package. You should use that library if you need more detailed implementation of the HQ API.

Installation

Install this library using pip:

pip install hydroq-api

Usage

The hydroq-api library provides a simple interface to authenticate and interact with Hydro Quebec’s electricity data API. At its core, the library offers the HydroQuebec class which handles the login flow, token refreshing, and session management for accessing additional web-based endpoints.

Notes

  • The library supports retrieving electricity usage data from Hydro Quebec
  • Daily usage can be retrieved for approximately 2 years of historical data plus one additional year worth of daily data as "same day" last data reference
  • Hourly usage can be retrieved for 24 hours
  • Monthly usage can be retrieved for approximately 1 year of historical data plus one additional year worth of monthly data as "same month" last data reference
  • Authentication is required before retrieving usage data
  • Ensure you have a valid Hydro Quebec account to use this library

Below are some examples demonstrating how to use the library.

Basic Authentication and Data Retrieval

First, install the library using pip:

pip install hydroq-api

Then in your Python code, you can authenticate and use the client as follows:

from hydroq_api import HydroQuebec

# Replace with your actual Hydro Quebec credentials
email = "YOUR_EMAIL@example.com"
password = "YOUR_PASSWORD"

# Initialize the HydroQuebec client
client = HydroQuebec(email, password)

# Login to obtain access tokens and set up your session
client.login()

# Now you can access the access token and other properties
print("Access Token:", client.access_token)

Refreshing Tokens

The library handles token refreshes under the hood. If you need to manually refresh the token (for example, if you detect it is about to expire), you can call the refresh method:

from hydroq_api import HydroQuebec

client = HydroQuebec("YOUR_EMAIL@example.com", "YOUR_PASSWORD")
client.login()

# Suppose you want to refresh the token proactively:
if client.refresh_token:
    # This is an internal call to refresh the token.
    # In typical usage, token refreshing happens automatically as needed.
    success = client._refresh_token()
    if success:
        print("New Access Token:", client.access_token)

Retrieving Consumption Data

The main functionality of the hydroq-api package is to retrieve your electricity consumption data at different granularities: hourly, daily, and monthly. After authenticating and setting up your client, you can call the relevant methods to fetch the desired data.

from hydroq_api import HydroQuebec

# Initialize and login to the HydroQuebec client
client = HydroQuebec("YOUR_EMAIL@example.com", "YOUR_PASSWORD")
client.login()

# Retrieve hourly consumption data
hourly_data = client.get_hourly_usage(date="2023-09-01")
print("Hourly Data:", hourly_data)

# Retrieve daily consumption data
daily_data = client.get_daily_usage(start_date="2023-09-01", end_daet="2023-09-30")
print("Daily Data:", daily_data)

# Retrieve monthly consumption data for a particular year
monthly_data = client.get_monthly_usage()
print("Monthly Data:", monthly_data)

Those mehtods will return the data as python dictionaries. Here is an example of the data structure returned by the get_daily_usage method:

{'success': True,
 'results': [{'courant': {'dateJourConso': '2025-02-17',
    'zoneMessageHTMLQuot': None,
    'consoRegQuot': 122.05,
    'consoHautQuot': 0,
    'consoTotalQuot': 122.05,
    'codeConsoQuot': 'R',
    'tempMoyenneQuot': -12,
    'codeTarifQuot': 'D',
    'affichageTarifFlexQuot': False,
    'indTempTarifBiEnergieQuot': False,
    'codeEvenementQuot': ''},
   'compare': {'dateJourConso': '2024-02-19',
    'zoneMessageHTMLQuot': None,
    'consoRegQuot': 81.83,
    'consoHautQuot': 0,
    'consoTotalQuot': 81.83,
    'codeConsoQuot': 'R',
    'tempMoyenneQuot': -10,
    'codeTarifQuot': 'D',
    'affichageTarifFlexQuot': False,
    'indTempTarifBiEnergieQuot': False,
    'codeEvenementQuot': ''}},
    ...

Development

To contribute to this library, first checkout the code. Then create a new virtual environment:

cd hydroq-api
python -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

python -m pip install -e '.[test]'

To run the tests:

python -m pytest

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

hydroq_api-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hydroq_api-0.1.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file hydroq_api-0.1.1.tar.gz.

File metadata

  • Download URL: hydroq_api-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hydroq_api-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a1a79000f9bc50f54bdf26bee6dd5c3e5c872a1d162c4583320d62aaf3054294
MD5 aead347381bbf0886d32fac48b400f79
BLAKE2b-256 c3b8233ea1300b6bf986bb9d27a97c3d32131e9ae66d67fe8d560d2dc79c18f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydroq_api-0.1.1.tar.gz:

Publisher: publish.yml on LVG77/hydroq-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hydroq_api-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hydroq_api-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hydroq_api-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 076b92bd8f22030c9238758e809ce80a3605231fb02a5b2e84eb4e620653bc91
MD5 b4250eb0c312e5ac299980a8e5b01528
BLAKE2b-256 ec48def52c8e354c9ef68558b7711dc6bd4d9dd1b5de37a4a8ffaf7d91ea93a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydroq_api-0.1.1-py3-none-any.whl:

Publisher: publish.yml on LVG77/hydroq-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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