BCHydro Python API for extracting electricity usage statistics from your personal account.
Via PyPi:
pip install bchydro
Via Github:
# Fetch the code
git clone https://github.com/emcniece/bchydro.git
cd bchydro
# Set up environment
pip install -r requirements.txt
Running the example script:
pip install bchydro
export BCH_USER=your.email@domain.com
export BCH_PASS=your-bch-password
python test.py
Using in a project:
import asyncio
from bchydro import BCHydroApi
async def main():
bch = BCHydroApi("username", "password")
# Asynchronous usage:
print(await bch.get_usage())
print(await bch.get_latest_point())
print(await bch.get_latest_usage())
print(await bch.get_latest_interval())
print(await bch.get_latest_cost())
# Mostly synchronous usage:
await bch.refresh()
print(bch.usage)
print(bch.latest_point)
print(bch.latest_usage)
print(bch.latest_interval)
print(bch.latest_cost)
asyncio.run(main())
This project accesses your BCHydro account as would a human in a browser. It is recommended that a read-only account is set up for use with this project for more secure operation. Using this secondary account also enables backup access in the event of account lockout.
- Instructions for adding read-only accounts can be found here.
- Read-only accounts can be configured here after logging in.
This repo is automatically published to PyPi by means of a Github Workflow when a new release is created on Github.
Dependencies can be updated with pip-tools:
# Install pip-compile and pip-sync
pip install pip-tools
# Upgrade requirements
pip-compile --upgrade
- Publish on release, not tag
- Handle account locking (looks for HTML alert dialogs)
- Unit tests
- Automatic initial and re-authentication
- Rate limiting, auth retries
- Exception documentation
This package has been developed without the express permission of BC Hydro. It accesses data by submitting forms that end-users would typically use in a browser. I'd love to work with BC Hydro to find a better way to access this data, perhaps through an official API... if you know anyone that works there, pass this along!