Skip to main content

BCHydro API

PyPi version Tested Python versions PyPi publish PyPi downloads Dependency updates

BCHydro Python API for extracting electricity usage statistics from your personal account.

Installation

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

Usage

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())

⚠ Read-Only Account Sharing

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.

Version Publishing

This repo is automatically published to PyPi by means of a Github Workflow when a new release is created on Github.

Maintenance

Dependencies can be updated with pip-tools:

# Install pip-compile and pip-sync
pip install pip-tools

# Upgrade requirements
pip-compile --upgrade

Todo

  • 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

Disclaimer

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!

Release files for bchydro 0.8.1

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

Source distribution (sdist)

Source distribution for bchydro 0.8.1
File Size Uploaded
bchydro-0.8.1.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bchydro 0.8.1
File Interpreter ABI Platform
bchydro-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / bchydro-0.8.1.tar.gz

Download URL bchydro-0.8.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
563ccd109941d232552ea182bec9331ba0d7e76ef040b6c3fe74fedcc7e7689f
BLAKE2b-256 checksum
How to use checksums
eaef77090a8a3190b4477e03b0c12ef1cc76fa3d944d9d2216d613b4f7aa06a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

Release files / bchydro-0.8.1-py3-none-any.whl

Download URL bchydro-0.8.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a96dce778c0a1eabb4a3c7f89cb43d59b080138474c1e0b5f9caaf6ec25bdc01
BLAKE2b-256 checksum
How to use checksums
d8030eedabe285469585f7e069027f510ae0ac4ede4989576087fce2980f34cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

Release history Release notifications | RSS feed

This release

0.8.1 This release

2 release files

0.8.0

2 release files

0.7

2 release files

0.6

2 release files

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

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