uw-api 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uw_api/__init__.py +23 -0
- uw_api/auth.py +216 -0
- uw_api/client.py +148 -0
- uw_api/exceptions.py +25 -0
- uw_api/graphql/__init__.py +252 -0
- uw_api/graphql/queries.py +240 -0
- uw_api/models/__init__.py +21 -0
- uw_api/models/account.py +34 -0
- uw_api/models/bill.py +45 -0
- uw_api/models/energy.py +41 -0
- uw_api/models/meter.py +32 -0
- uw_api/pdf/__init__.py +0 -0
- uw_api/pdf/extractor.py +173 -0
- uw_api-0.2.0.dist-info/METADATA +171 -0
- uw_api-0.2.0.dist-info/RECORD +16 -0
- uw_api-0.2.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: uw-api
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Async Python client for the Utility Warehouse customer portal API
|
|
5
|
+
Author-email: Kieran <kieran@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: energy,home-assistant,utility-warehouse
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Requires-Dist: httpx>=0.28.1
|
|
17
|
+
Requires-Dist: pdfplumber>=0.11.10
|
|
18
|
+
Requires-Dist: pydantic>=2.13.4
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: mypy>=2.3.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest-asyncio>=1.4.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest-httpx>=0.36.2; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-xdist>=3.8.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest>=9.1.1; extra == 'dev'
|
|
26
|
+
Requires-Dist: ruff>=0.16.0; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# uw-api
|
|
30
|
+
|
|
31
|
+
Async Python client for the Utility Warehouse customer portal API.
|
|
32
|
+
|
|
33
|
+
Endpoints are hardcoded (discovered from `myaccount.uw.co.uk/`) and require no
|
|
34
|
+
configuration — just provide credentials.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install uw-api
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import asyncio
|
|
46
|
+
from uw_api import UWClient
|
|
47
|
+
|
|
48
|
+
async def main():
|
|
49
|
+
async with UWClient(email="user@example.com", password="secret") as client:
|
|
50
|
+
await client.login()
|
|
51
|
+
|
|
52
|
+
account = await client.gql.get_account()
|
|
53
|
+
print(f"Account: {account.account_number}")
|
|
54
|
+
|
|
55
|
+
bills = await client.gql.get_bills()
|
|
56
|
+
for bill in bills:
|
|
57
|
+
print(f"Bill {bill.bill_id}: £{bill.total_amount_gbp}")
|
|
58
|
+
|
|
59
|
+
consumption = await client.gql.get_consumption()
|
|
60
|
+
print(f"Electricity: {consumption.electricity_kwh} kWh")
|
|
61
|
+
print(f"Gas: {consumption.gas_kwh} kWh")
|
|
62
|
+
|
|
63
|
+
meters = await client.gql.get_meters()
|
|
64
|
+
for meter in meters:
|
|
65
|
+
print(f"{meter.meter_type}: {meter.meter_number} (smart={meter.is_smart})")
|
|
66
|
+
|
|
67
|
+
tariff = await client.gql.get_tariff()
|
|
68
|
+
if tariff:
|
|
69
|
+
print(f"Tariff: {tariff.tariff_name}")
|
|
70
|
+
|
|
71
|
+
asyncio.run(main())
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## API Reference
|
|
75
|
+
|
|
76
|
+
### Auth
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
client = UWClient(email="...", password="...")
|
|
80
|
+
await client.login()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Authenticates via OAuth2 PKCE at `account.uw.co.uk/v2/login`. Session cookies are
|
|
84
|
+
managed automatically. The library re-authenticates on 401 responses.
|
|
85
|
+
|
|
86
|
+
### Account
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
account = await client.gql.get_account()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Returns `UWAccount` with `account_id` and `account_number`.
|
|
93
|
+
|
|
94
|
+
### Energy
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
consumption = await client.gql.get_consumption()
|
|
98
|
+
services = await client.gql.get_energy_services()
|
|
99
|
+
usage = await client.gql.get_energy_usage()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- `get_consumption()` → `EnergyConsumption` (latest electricity/gas kWh)
|
|
103
|
+
- `get_energy_services()` → raw list of energy service dicts
|
|
104
|
+
- `get_energy_usage()` → list of `EnergyUsage` with per-meter readings
|
|
105
|
+
|
|
106
|
+
### Meters
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
meters = await client.gql.get_meters()
|
|
110
|
+
readings = await client.gql.get_meter_readings()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- `get_meters()` → list of `Meter` (type, serial, smart status, last reading date)
|
|
114
|
+
- `get_meter_readings()` → list of `MeterReading` (value, type, date, source)
|
|
115
|
+
|
|
116
|
+
### Bills
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
bills = await client.gql.get_bills()
|
|
120
|
+
pdf_url = await client.gql.get_pdf_url(month=1, year=2026)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- `get_bills()` → list of `Bill` (ID, date, amount, status, PDF URL)
|
|
124
|
+
- `get_pdf_url(month, year)` → str URL for the bill PDF
|
|
125
|
+
|
|
126
|
+
### Financial
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
balance = await client.gql.get_balance()
|
|
130
|
+
services = await client.gql.get_live_services()
|
|
131
|
+
tariff = await client.gql.get_tariff()
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- `get_balance()` → `{"due": float, "overdue": float}`
|
|
135
|
+
- `get_live_services()` → dict of service statuses
|
|
136
|
+
- `get_tariff()` → `EnergyTariff` (name, code, rates)
|
|
137
|
+
|
|
138
|
+
## Hardcoded Endpoints
|
|
139
|
+
|
|
140
|
+
| Purpose | URL |
|
|
141
|
+
|---------|-----|
|
|
142
|
+
| Login page | `https://account.uw.co.uk/v2/login` |
|
|
143
|
+
| GraphQL API | `https://myaccount.uw.co.uk/server/graphql` |
|
|
144
|
+
|
|
145
|
+
11 GraphQL operations are embedded in `uw_api/graphql/queries.py`.
|
|
146
|
+
|
|
147
|
+
## Discovery Script (optional)
|
|
148
|
+
|
|
149
|
+
A HAR-based discovery script is included for verifying or re-discovering endpoints:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
python scripts/discover_api.py parse-har capture.har
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This is **not required** for normal use — the library ships with hardcoded
|
|
156
|
+
endpoints discovered from `myaccount.uw.co.uk/` in July 2026.
|
|
157
|
+
|
|
158
|
+
## Architecture
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
UWClient → UWAuth (OAuth2 PKCE)
|
|
162
|
+
→ UWGraphQL → /server/graphql (POST)
|
|
163
|
+
→ Pydantic v2 models
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- **Auth**: CSRF token extraction from login page HTML, form-encoded POST with
|
|
167
|
+
Castle.io device token
|
|
168
|
+
- **GraphQL**: All data via `POST /server/graphql` with operation-oriented queries
|
|
169
|
+
- **Retry**: 3 attempts with exponential backoff on 429/5xx, re-auth on 401
|
|
170
|
+
- **Models**: `UWAccount`, `EnergyUsage`, `EnergyConsumption`, `EnergyTariff`,
|
|
171
|
+
`Meter`, `MeterReading`, `Bill`, `BillPDFMetadata`
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
uw_api/__init__.py,sha256=oSwKEaNL2a371kyKdSUPPJvKtzBotlqoeN4D_sgJcjM,443
|
|
2
|
+
uw_api/auth.py,sha256=S3zDEnGr8QhtoayDBQ_gpKcthuOF4Dif9SpyhImAlvQ,7435
|
|
3
|
+
uw_api/client.py,sha256=cImHbmA2h8kmdFwp2kvzf4uiX8tdZFBFJXwUvNS7RSg,5018
|
|
4
|
+
uw_api/exceptions.py,sha256=Cae57KyqH4CFIW0hMYlWLSkq6XNp1f9ePj1_8pm2AIw,311
|
|
5
|
+
uw_api/graphql/__init__.py,sha256=xExnU10cA9zR4RMLsnBL7ay8xz-ZXbe56jr-K9Q-gFw,9646
|
|
6
|
+
uw_api/graphql/queries.py,sha256=E5j00BMEBJZpxR7cFHeavmvce058_ZD6yMBKxgqoFyI,4269
|
|
7
|
+
uw_api/models/__init__.py,sha256=hgMWSI5LYRMEszeDoMfgJ6hKbO8-jImPKhCbz271-Ps,587
|
|
8
|
+
uw_api/models/account.py,sha256=MP0emFDjwHofRYTCeCOHkiGcRESlpwdhjbJVGhvZjFk,771
|
|
9
|
+
uw_api/models/bill.py,sha256=dBjwmQo4GoETtKjfHIqYLs2ZgrfWinCu4l5cFEqn91k,1105
|
|
10
|
+
uw_api/models/energy.py,sha256=LawvvEEXLgueyTAYKW0F6As5K5EkpvlHrKyRSRSVw-o,1002
|
|
11
|
+
uw_api/models/meter.py,sha256=X_ZKsRuDy3P-BZ4qlGE8q8SMYTXKUXvGtPn5MYn6aEc,653
|
|
12
|
+
uw_api/pdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
uw_api/pdf/extractor.py,sha256=jIaT1PmxhKVcic0dyN4F0tV_csuzFjcEFp7REGeHRwI,5155
|
|
14
|
+
uw_api-0.2.0.dist-info/METADATA,sha256=69SZJqov8DJevQWggO-y4tqAl-oEpLCj-rLM6iDLx4I,5020
|
|
15
|
+
uw_api-0.2.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
16
|
+
uw_api-0.2.0.dist-info/RECORD,,
|