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.
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| switch2-0.2.0.tar.gz | 13.3 kB | Without provenance | Details for switch2-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| switch2-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for switch2-0.2.0-py3-none-any.whl |
Total release size: 23.0 kB
Release files / switch2-0.2.0.tar.gz
| Download URL | switch2-0.2.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6566b5e9e6f71cf2aac00adf468dc61a037c80af1516175041d6556a571cfc12
|
|
BLAKE2b-256 checksum How to use checksums |
9d998f99bce0c81bce5535408b4d24bb9c677c8b606db63f5942b46ba3c3d7e1
|
| 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.0-py3-none-any.whl
| Download URL | switch2-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
855e031d217dd737a6089e27695c3c179c0bdcdd7794ca0b779c4cda4d18b0c5
|
|
BLAKE2b-256 checksum How to use checksums |
7944e347996fada56450b4d7eb932dd002b931fdd5099bfef050c5c3ad4e018e
|
| 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.0
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.