Skip to main content

python-switch2

Async Python client library for the Switch2 energy portal.

Installation

pip install switch2

Usage

import asyncio
from switch2 import Switch2ApiClient


async def main():
    async with Switch2ApiClient("you@example.com", "your-password") as client:
        data = await client.fetch_data()
        print(f"Customer: {data.customer.name}")
        if data.account_balance is not None:
            print(f"Balance: £{data.account_balance.balance}")
        for reading in data.readings:
            print(f"  {reading.date}: {reading.amount} {reading.unit}")
        for bill in data.bills:
            print(f"  {bill.date}: £{bill.amount}")
            detail = await client.fetch_bill_detail(bill)
            print(f"    invoice {detail.invoice_number}, total £{detail.total}")


asyncio.run(main())

All exceptions derive from Switch2Error. Switch2AuthError means the portal rejected the credentials; Switch2ParseError means a page did not look the way the parser expects, which usually means the portal changed; Switch2UnavailableError means the portal failed to load data it normally has, which tends to pass if you try again later.

data.readings holds the readings of the register the portal selects by default; data.register_readings maps each register in data.registers to its readings.

Command line

SWITCH2_PASSWORD=... python -m switch2 you@example.com

prints what the portal reports. With --dump-html DIR it also saves every page it fetches, which is the easiest way to capture a page the parser gets wrong.

License

Apache-2.0

Metadata

Release files for switch2 0.2.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 switch2 0.2.1
File Size Uploaded Provenance Actions
switch2-0.2.1.tar.gz 13.6 kB Without provenance Details for switch2-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 23.5 kB

Release files / switch2-0.2.1.tar.gz

Download URL switch2-0.2.1.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cac49091875dd698956a2a7bf4fbac523d0cd467093e327e4483c2678ddb9779
BLAKE2b-256 checksum
How to use checksums
159d7b7df2ad70c3da0a35102fed8bf0cd9a4f8c925c2a93404b668a90b60a8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / switch2-0.2.1-py3-none-any.whl

Download URL switch2-0.2.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dafa2ae1414751b8763da3d747fdab35a355f1732184c30770f8b60e32bee7ad
BLAKE2b-256 checksum
How to use checksums
ee8d8ad4ecbabb6ef55c19012d7689588d692aa9c1815e956e3f7209234b513a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Security for switch2 0.2.1

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.

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