Skip to main content

Async Python client for Yorkshire Water's customer self-service API. Unofficial and not affiliated with Yorkshire Water.

Project description

pyyorkshirewater

Async Python client for the Yorkshire Water customer self-service API.

This library is unofficial and not affiliated with Yorkshire Water. It exists so that customers can read their own smart meter consumption data from the same backend that powers my.yorkshirewater.com.

Status

Early alpha. The smart meter rollout is in progress across the Yorkshire Water region between 2025 and 2030, so most accounts will not yet have a live meter. Until a meter is live the client will report a MeterStatus of NO_METER or PENDING_ACTIVATION, and the consumption endpoints (get_your_usage, get_daily_consumption, get_yearly_consumption) will raise YorkshireWaterMeterNotReadyError. The readiness probes (get_meter_details, get_current_consumption) work in every state.

Why cookies, not email and password

Yorkshire Water's portal SPA uses Duende IdentityServer with authorization code plus PKCE only. The SPA OAuth client (css-onlineaccount-fe) is not permitted to use the password grant, the device flow or offline_access, and the login form is protected by invisible Google reCAPTCHA v3 which a non-browser HTTP client cannot pass.

The workable architecture is therefore: the user logs in to my.yorkshirewater.com once in their own browser, where reCAPTCHA succeeds naturally, and exports the IdentityServer session cookie. This library uses that cookie to drive /connect/authorize?prompt=none for silent renewal, mints fresh access tokens on demand and never sees the user's password.

The companion Chrome extension (separate repository) makes cookie export a single click.

Install

pip install pyyorkshirewater

Python 3.11 or newer.

Quick start

import asyncio
from pyyorkshirewater import YorkshireWaterClient, MeterStatus

cookies = {
    "idsrv": "<value from a logged-in browser session>",
    "idsrv.session": "<value from a logged-in browser session>",
    # any other login.yorkshirewater.com cookies your browser holds
}

async def main():
    async with YorkshireWaterClient(cookies=cookies) as client:
        await client.login()

        if client.meter_status is MeterStatus.LIVE:
            daily = await client.get_daily_consumption()
            print(daily)
        else:
            print(f"Meter is {client.meter_status.value}, no data yet.")

asyncio.run(main())

Cookie lifetime

The IdentityServer session cookie typically lives between several hours and several weeks depending on the provider's configuration. Each silent renewal call may extend it (sliding expiration) on servers configured for that. When the cookie eventually expires, the library raises CookieSessionExpiredError (a subclass of YorkshireWaterAuthError) with error="login_required". Callers should catch this and prompt the user for fresh cookies. The Home Assistant integration handles this via a reauth flow.

Meter readiness states

Yorkshire Water's portal exposes a three-state model. The library mirrors it through the MeterStatus enum:

  • NO_METER: the account has no smart meter on it.
  • PENDING_ACTIVATION: a meter is registered but is awaiting network setup by Yorkshire Water.
  • LIVE: the meter is reporting data and the consumption endpoints will return real values.

Application code should check client.meter_status before requesting consumption data.

Logging

The library logs to a named logger called pyyorkshirewater at the DEBUG level. Configure it in the usual way:

import logging
logging.getLogger("pyyorkshirewater").setLevel(logging.DEBUG)

Errors

All errors raised by the library inherit from YorkshireWaterError. The specific subclasses are:

  • YorkshireWaterAuthError: silent renewal failed for a reason that is not cookie expiry. The original IdentityServer error and error_description are exposed on the exception.
  • CookieSessionExpiredError (subclass of YorkshireWaterAuthError): the IdP session cookie is expired or invalid. Re-export from a fresh browser session.
  • YorkshireWaterAPIError: a non-auth HTTP error from the customer API.
  • YorkshireWaterMeterNotReadyError: raised when a consumption endpoint is called against a meter that is not yet LIVE.
  • YorkshireWaterRateLimitError: 429 response with optional retry_after.

Related projects

  • dan-simms1/ha-yorkshire-water: Home Assistant integration that uses this library.
  • (forthcoming) Chrome extension that extracts the cookies needed by this library and the integration with one click.

Disclaimer

This project is unofficial and not affiliated with, endorsed by or supported by Yorkshire Water Services Limited. Trademarks are the property of their respective owners. Use this software at your own risk and only against accounts that you own.

Licence

MIT. See LICENSE.

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

pyyorkshirewater-1.4.0.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

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

pyyorkshirewater-1.4.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file pyyorkshirewater-1.4.0.tar.gz.

File metadata

  • Download URL: pyyorkshirewater-1.4.0.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyyorkshirewater-1.4.0.tar.gz
Algorithm Hash digest
SHA256 a2b0401fa499559d27554cc6e708a4942402266dd83d82be4127801d56cbb4ae
MD5 b30a5f85a38d5d41e8b12f06b32d88b0
BLAKE2b-256 4bc85abfc6303982a00db3af1e7fb82090f5d5293f67967b6b04fb63cc6e638d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyyorkshirewater-1.4.0.tar.gz:

Publisher: publish.yml on dan-simms1/pyyorkshirewater

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

File details

Details for the file pyyorkshirewater-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyyorkshirewater-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 660ec66c7a9630f0b8181768a58b4b2df85310c3c99b0c949aaf6319dd9a03c3
MD5 cdfbea5a34e4f4a73e3312ca4b014886
BLAKE2b-256 bb9ee2fc51c9de9eeced79f1e9935a0db0d2354e2f8f3199de07b7904f0052ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyyorkshirewater-1.4.0-py3-none-any.whl:

Publisher: publish.yml on dan-simms1/pyyorkshirewater

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