HydroQC - Hydro Quebec API wrapper
This is a library to use if you want to build your own solution. If you want a user-friendly implementation for your home automation system please use hydroqc2mqtt which provide a MQTT publisher, docker image and HASS addon.
This is a package to access some functionalities of Hydro Quebec API that are not documented.
We started a discord server for the project where you can come to discuss and find help with the project on our #development channel
Donations
We put a lot of heart and effort in this project, any contribution is greatly appreciated!
Tested Rates
Each account, contracts and rates are different and we do our best to integrate all available options. Currently the account combinations listed below are supported and tested automaticaly by our CI/CD pipeline. If your account scenario is not currently tested and listed as Needed feel free to reach out to us on our discord #development channel if you want to volunter for testing. We provide a way to setup CI/CD tests in your own account in a way that keep your account info private to you (more details here). Keep in mind that this process is a bit involved technicaly so it is best if you have some working knowledge with Gitlab.
Rate D
| Base Rate | Rate Option | Tester | Test result | Last run | Comment |
|---|---|---|---|---|---|
| D | - | @weimdall | |||
| D | - | @mdallaire1 | |||
| D | - | @devzwf | Hilo | ||
| D | CPC | @titilambert |
Flex D (DPC)
| Base Rate | Rate Option | Tester | Test result | Last run | Comment |
|---|---|---|---|---|---|
| DPC | - | @mdallaire1 |
Dual Energy (DT)
| Base Rate | Rate Option | Tester | Test result | Last run | Comment |
|---|---|---|---|---|---|
| DT | - | @mdallaire1 |
Rate M
| Base Rate | Rate Option | Tester | Test result | Last run | Comment |
|---|---|---|---|---|---|
| M | - | @hdenergy | HD Énergie | ||
| M | GDP | @hdenergy | HD Énergie |
Thanks to HD Énergie for sponsoring developpement of the Rate M support.
Other plans
We don't have anyone to test with. Please reach out to us if you have this plan and want to help!
Documentation
Code documentation
https://hydroqc.readthedocs.io/
Architecture / concepts
If you need more information about the usage and current integrations of the library please see our website https://hydroqc.ca
E-mail verification (MFA)
Hydro-Québec can ask for a one-time code sent by e-mail after the password round
trip. login() returns a LoginStatus instead of a plain boolean:
from hydroqc.consts import LoginStatus
from hydroqc.error import HydroQcMFAInvalidCodeError
status = await webuser.login()
while status is LoginStatus.MFA_REQUIRED:
code = input("Verification code (empty = send a new one): ")
if not code.strip():
await webuser.request_mfa_code()
continue
try:
status = await webuser.submit_mfa_code(code)
except HydroQcMFAInvalidCodeError:
print("Code refused, try again.")
if status is not LoginStatus.SUCCESS:
raise RuntimeError("Login failed")
bool(status) is only true for LoginStatus.SUCCESS, so existing code using
if await webuser.login(): keeps working. The code is requested automatically
when the step is detected; request_mfa_code() sends a new one. The
verification step expires after a few minutes (3 minutes on the current
portal): HydroQcMFAExpiredError means the login has to be restarted.
A silent background login cannot ask for a code and raises
HydroQcMFARequiredError instead of failing quietly.
Reusing a session
export_session_state() returns the OAuth tokens plus the Azure AD B2C cookies;
import_session_state() restores them. Persisting that state lets a later run
skip the password (and a new verification code) while the refresh token or the
single sign-on cookie is still valid. The current portal issues 15-minute access
tokens and a 24-hour refresh token, so the stored session is normally reusable
for about a day; once the refresh token and the single sign-on cookie are both
refused, a new interactive login (and a new code) is required:
state = webuser.export_session_state() # store it somewhere safe
# ... next run ...
webuser = WebUser(username, password, verify_ssl=True)
webuser.import_session_state(state)
if await webuser.try_silent_login() is not LoginStatus.SUCCESS:
await webuser.login()
Goal
Make it easy to fetch and manipulate data from Hydro-Quebec, especially the winter credit periods
Example folder
An example script that extracts the data available from Hydro-Quebec is available in the examples folder.
Basic setup
This uses python 3.10
-
Clone the repo
git clone https://github.com/hydroqc/hydroqc.git
-
Create a virtual-env
python -m venv env . env/bin/activate pip install --editable .
-
Enter your hydro account credentials in the examples/hydro.py file (line 6)
-
Run
examples/hydro.py
TODO
https://gitlab.com/groups/hydroqc/-/issues
Targeted architecture (might change in the future)
classDiagram
WebUser <-- Customer
WebUser <-- HydroClient
Customer <-- Account
Account <-- Contract
Contract <-- HydroClient
Contract <-- Period
Contract <-- Event
Contract <-- WinterCreditHelper
WinterCreditHelper <-- HydroClient
HydroClient <-- Authenticator
class HydroClient{
}
class WinterCreditHelper{
}
class WebUser{
-HydroClient _hydro_client
+List~Customer~ customers
+get_contracts()
}
class Customer{
-HydroClient _hydro_client
+List~Account~ accounts
}
class Account{
-HydroClient _hydro_client
+List~Contract~ contracts
}
class Config{
-string config_file_path
}
class Contract{
-HydroClient _hydro_client
-int customer_id
-int webuser_id
+string subscription_type
+float balance
+list~Period~ periods
+list~Event~ events
+get_winter_credit()
+fetch_periods()
+fetch_summary()
}
class Period{
}
class Event{
}
Metadata
Release files for Hydro-Quebec-API-Wrapper 4.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hydro_quebec_api_wrapper-4.3.0.tar.gz | 420.4 kB | Without provenance | Details for hydro_quebec_api_wrapper-4.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hydro_quebec_api_wrapper-4.3.0-py3-none-any.whl | Python 3 | none | any | Details for hydro_quebec_api_wrapper-4.3.0-py3-none-any.whl |
Total release size: 495.4 kB
Release files / hydro_quebec_api_wrapper-4.3.0.tar.gz
| Download URL | hydro_quebec_api_wrapper-4.3.0.tar.gz |
|---|---|
| Size | 420.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6816aea547f76bc49d97b6f4ec61513853bfe854253f5e9686b92d60d21132c0
|
|
BLAKE2b-256 checksum How to use checksums |
0db1193b4df853d20b94f13e8a85dd1c8e8bd92a31979f5042185974bc22043e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / hydro_quebec_api_wrapper-4.3.0-py3-none-any.whl
| Download URL | hydro_quebec_api_wrapper-4.3.0-py3-none-any.whl |
|---|---|
| Size | 75.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b086041731778b8d93bf9e2e11fe1c7fea7b038752540973c676a3a95305d60
|
|
BLAKE2b-256 checksum How to use checksums |
488ee04f80121a4edc22cbff014bcfedfeb3ccb0015f21fe25baf24da2e90bc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for Hydro-Quebec-API-Wrapper 4.3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.