Skip to main content

BCHydro API

Project description

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!

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

bchydro-0.8.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

bchydro-0.8.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file bchydro-0.8.1.tar.gz.

File metadata

  • Download URL: bchydro-0.8.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for bchydro-0.8.1.tar.gz
Algorithm Hash digest
SHA256 563ccd109941d232552ea182bec9331ba0d7e76ef040b6c3fe74fedcc7e7689f
MD5 c09574d889ffe78cf7491c1e33b41e96
BLAKE2b-256 eaef77090a8a3190b4477e03b0c12ef1cc76fa3d944d9d2216d613b4f7aa06a7

See more details on using hashes here.

File details

Details for the file bchydro-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: bchydro-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for bchydro-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a96dce778c0a1eabb4a3c7f89cb43d59b080138474c1e0b5f9caaf6ec25bdc01
MD5 7add41eddae1431e58279b1fca7cb055
BLAKE2b-256 d8030eedabe285469585f7e069027f510ae0ac4ede4989576087fce2980f34cf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page