uw-api 0.2.0__tar.gz
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-0.2.0/.github/CODEOWNERS +1 -0
- uw_api-0.2.0/.github/PULL_REQUEST_TEMPLATE.md +23 -0
- uw_api-0.2.0/.github/dependabot.yml +33 -0
- uw_api-0.2.0/.github/workflows/ci.yml +134 -0
- uw_api-0.2.0/.github/workflows/release-please.yml +69 -0
- uw_api-0.2.0/.gitignore +16 -0
- uw_api-0.2.0/.release-please-manifest.json +3 -0
- uw_api-0.2.0/CHANGELOG.md +20 -0
- uw_api-0.2.0/PKG-INFO +171 -0
- uw_api-0.2.0/README.md +143 -0
- uw_api-0.2.0/pyproject.toml +65 -0
- uw_api-0.2.0/release-please-config.json +19 -0
- uw_api-0.2.0/scripts/discover_api.py +382 -0
- uw_api-0.2.0/src/uw_api/__init__.py +23 -0
- uw_api-0.2.0/src/uw_api/auth.py +216 -0
- uw_api-0.2.0/src/uw_api/client.py +148 -0
- uw_api-0.2.0/src/uw_api/exceptions.py +25 -0
- uw_api-0.2.0/src/uw_api/graphql/__init__.py +252 -0
- uw_api-0.2.0/src/uw_api/graphql/queries.py +240 -0
- uw_api-0.2.0/src/uw_api/models/__init__.py +21 -0
- uw_api-0.2.0/src/uw_api/models/account.py +34 -0
- uw_api-0.2.0/src/uw_api/models/bill.py +45 -0
- uw_api-0.2.0/src/uw_api/models/energy.py +41 -0
- uw_api-0.2.0/src/uw_api/models/meter.py +32 -0
- uw_api-0.2.0/src/uw_api/pdf/__init__.py +0 -0
- uw_api-0.2.0/src/uw_api/pdf/extractor.py +173 -0
- uw_api-0.2.0/tests/__init__.py +0 -0
- uw_api-0.2.0/tests/conftest.py +14 -0
- uw_api-0.2.0/tests/test_bills.py +12 -0
- uw_api-0.2.0/tests/test_client.py +103 -0
- uw_api-0.2.0/tests/test_models.py +195 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @KRoperUK
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Thanks for contributing! Please use a Conventional Commit style PR title,
|
|
3
|
+
e.g. "fix: handle session expiry" or "feat: add tariff query".
|
|
4
|
+
This drives automated changelog and versioning.
|
|
5
|
+
-->
|
|
6
|
+
|
|
7
|
+
## Summary
|
|
8
|
+
|
|
9
|
+
<!-- What does this PR change and why? Link any related issues. -->
|
|
10
|
+
|
|
11
|
+
## Type of change
|
|
12
|
+
|
|
13
|
+
- [ ] Bug fix (non-breaking change which fixes an issue)
|
|
14
|
+
- [ ] New feature (non-breaking change which adds functionality)
|
|
15
|
+
- [ ] Breaking change
|
|
16
|
+
- [ ] Documentation / chore
|
|
17
|
+
|
|
18
|
+
## Checklist
|
|
19
|
+
|
|
20
|
+
- [ ] `ruff check src/ tests/ scripts/` passes
|
|
21
|
+
- [ ] `ruff format --check src/ tests/ scripts/` passes
|
|
22
|
+
- [ ] `mypy` passes
|
|
23
|
+
- [ ] `pytest` passes and new/changed behaviour is covered by tests
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: "github-actions"
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: "weekly"
|
|
7
|
+
open-pull-requests-limit: 5
|
|
8
|
+
commit-message:
|
|
9
|
+
prefix: "chore(deps)"
|
|
10
|
+
labels:
|
|
11
|
+
- "dependencies"
|
|
12
|
+
- "github-actions"
|
|
13
|
+
groups:
|
|
14
|
+
github-actions:
|
|
15
|
+
patterns:
|
|
16
|
+
- "*"
|
|
17
|
+
|
|
18
|
+
- package-ecosystem: "pip"
|
|
19
|
+
directory: "/"
|
|
20
|
+
schedule:
|
|
21
|
+
interval: "weekly"
|
|
22
|
+
open-pull-requests-limit: 5
|
|
23
|
+
versioning-strategy: increase
|
|
24
|
+
commit-message:
|
|
25
|
+
prefix: "chore(deps)"
|
|
26
|
+
prefix-development: "chore(deps-dev)"
|
|
27
|
+
labels:
|
|
28
|
+
- "dependencies"
|
|
29
|
+
- "python"
|
|
30
|
+
groups:
|
|
31
|
+
python:
|
|
32
|
+
patterns:
|
|
33
|
+
- "*"
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: ci-${{ github.ref }}
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
changes:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
timeout-minutes: 5
|
|
20
|
+
outputs:
|
|
21
|
+
component: ${{ steps.filter.outputs.component }}
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
24
|
+
with:
|
|
25
|
+
fetch-depth: 0
|
|
26
|
+
- uses: dorny/paths-filter@7b450fff21473bca461d4b92ce414b9d0420d706 # v4.0.2
|
|
27
|
+
id: filter
|
|
28
|
+
with:
|
|
29
|
+
filters: |
|
|
30
|
+
component:
|
|
31
|
+
- 'src/**'
|
|
32
|
+
- 'tests/**'
|
|
33
|
+
- 'scripts/**'
|
|
34
|
+
- 'pyproject.toml'
|
|
35
|
+
- '.github/workflows/ci.yml'
|
|
36
|
+
|
|
37
|
+
lint:
|
|
38
|
+
needs: changes
|
|
39
|
+
if: needs.changes.outputs.component == 'true'
|
|
40
|
+
runs-on: ubuntu-latest
|
|
41
|
+
timeout-minutes: 10
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
44
|
+
|
|
45
|
+
- name: Set up Python
|
|
46
|
+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
47
|
+
with:
|
|
48
|
+
python-version: "3.13"
|
|
49
|
+
cache: pip
|
|
50
|
+
cache-dependency-path: .github/workflows/ci.yml
|
|
51
|
+
|
|
52
|
+
- name: Install dependencies
|
|
53
|
+
run: pip install -e ".[dev]"
|
|
54
|
+
|
|
55
|
+
- name: Lint with ruff
|
|
56
|
+
run: ruff check --output-format=github src/ tests/ scripts/
|
|
57
|
+
|
|
58
|
+
- name: Check formatting
|
|
59
|
+
run: ruff format --check src/ tests/ scripts/
|
|
60
|
+
|
|
61
|
+
typecheck:
|
|
62
|
+
needs: changes
|
|
63
|
+
if: needs.changes.outputs.component == 'true'
|
|
64
|
+
runs-on: ubuntu-latest
|
|
65
|
+
timeout-minutes: 10
|
|
66
|
+
steps:
|
|
67
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
68
|
+
|
|
69
|
+
- name: Set up Python
|
|
70
|
+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
71
|
+
with:
|
|
72
|
+
python-version: "3.13"
|
|
73
|
+
cache: pip
|
|
74
|
+
cache-dependency-path: .github/workflows/ci.yml
|
|
75
|
+
|
|
76
|
+
- name: Install dependencies
|
|
77
|
+
run: pip install -e ".[dev]"
|
|
78
|
+
|
|
79
|
+
- name: Type check with mypy
|
|
80
|
+
run: |
|
|
81
|
+
set -o pipefail
|
|
82
|
+
mypy | sed -E \
|
|
83
|
+
-e 's/^([^:]+):([0-9]+): error: (.*)$/::error file=\1,line=\2::\3/' \
|
|
84
|
+
-e 's/^([^:]+):([0-9]+): note: (.*)$/::notice file=\1,line=\2::\3/'
|
|
85
|
+
|
|
86
|
+
test:
|
|
87
|
+
needs: changes
|
|
88
|
+
if: needs.changes.outputs.component == 'true'
|
|
89
|
+
runs-on: ubuntu-latest
|
|
90
|
+
timeout-minutes: 15
|
|
91
|
+
steps:
|
|
92
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
93
|
+
|
|
94
|
+
- name: Set up Python
|
|
95
|
+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
96
|
+
with:
|
|
97
|
+
python-version: "3.13"
|
|
98
|
+
cache: pip
|
|
99
|
+
cache-dependency-path: pyproject.toml
|
|
100
|
+
|
|
101
|
+
- name: Install dependencies
|
|
102
|
+
run: pip install -e ".[dev]"
|
|
103
|
+
|
|
104
|
+
- name: Run tests with coverage
|
|
105
|
+
run: >-
|
|
106
|
+
pytest tests/
|
|
107
|
+
--cov=src/uw_api --cov-branch
|
|
108
|
+
--cov-report=xml --cov-report=term-missing
|
|
109
|
+
--junitxml=junit.xml -o junit_family=legacy
|
|
110
|
+
-n auto --dist=loadscope
|
|
111
|
+
-v
|
|
112
|
+
|
|
113
|
+
- name: Upload coverage report
|
|
114
|
+
if: always()
|
|
115
|
+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
116
|
+
with:
|
|
117
|
+
name: coverage-report
|
|
118
|
+
path: coverage.xml
|
|
119
|
+
|
|
120
|
+
- name: Upload coverage to Codecov
|
|
121
|
+
if: always()
|
|
122
|
+
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
|
|
123
|
+
with:
|
|
124
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
125
|
+
files: coverage.xml
|
|
126
|
+
fail_ci_if_error: false
|
|
127
|
+
|
|
128
|
+
- name: Upload test results to Codecov
|
|
129
|
+
if: ${{ !cancelled() }}
|
|
130
|
+
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
|
|
131
|
+
with:
|
|
132
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
133
|
+
report_type: test_results
|
|
134
|
+
files: junit.xml
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
name: Release Please
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
pull-requests: write
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: release-please
|
|
13
|
+
cancel-in-progress: false
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
release-please:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
timeout-minutes: 10
|
|
19
|
+
outputs:
|
|
20
|
+
release_created: ${{ steps.release.outputs.release_created }}
|
|
21
|
+
tag_name: ${{ steps.release.outputs.tag_name }}
|
|
22
|
+
steps:
|
|
23
|
+
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
|
|
24
|
+
id: release
|
|
25
|
+
with:
|
|
26
|
+
token: ${{ secrets.RELEASE_PLEASE_TOKEN || github.token }}
|
|
27
|
+
config-file: release-please-config.json
|
|
28
|
+
manifest-file: .release-please-manifest.json
|
|
29
|
+
|
|
30
|
+
build:
|
|
31
|
+
needs: release-please
|
|
32
|
+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
timeout-minutes: 10
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
|
37
|
+
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
|
38
|
+
with:
|
|
39
|
+
python-version: "3.13"
|
|
40
|
+
- name: Install build tools
|
|
41
|
+
run: python -m pip install --upgrade pip build
|
|
42
|
+
- name: Build distributions
|
|
43
|
+
run: python -m build
|
|
44
|
+
- name: Upload distributions
|
|
45
|
+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
46
|
+
with:
|
|
47
|
+
name: release-dists
|
|
48
|
+
path: dist/
|
|
49
|
+
|
|
50
|
+
pypi-publish:
|
|
51
|
+
name: Publish release to PyPI
|
|
52
|
+
needs: build
|
|
53
|
+
runs-on: ubuntu-latest
|
|
54
|
+
timeout-minutes: 10
|
|
55
|
+
environment:
|
|
56
|
+
name: pypi
|
|
57
|
+
url: https://pypi.org/p/uw-api
|
|
58
|
+
permissions:
|
|
59
|
+
id-token: write
|
|
60
|
+
steps:
|
|
61
|
+
- name: Retrieve release distributions
|
|
62
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
63
|
+
with:
|
|
64
|
+
name: release-dists
|
|
65
|
+
path: dist/
|
|
66
|
+
- name: Publish release distributions to PyPI
|
|
67
|
+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
|
|
68
|
+
with:
|
|
69
|
+
packages-dir: dist/
|
uw_api-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.0](https://github.com/KRoperUK/uw-py/compare/v0.1.0...v0.2.0) (2026-07-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* initial uw-py library implementation ([5f36ca3](https://github.com/KRoperUK/uw-py/commit/5f36ca3b37e35da3d4949114cc7f212b5673c702))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* add mypy files directive to pyproject.toml ([76aab40](https://github.com/KRoperUK/uw-py/commit/76aab4071d0196af16628620a56ac6a179cf9384))
|
|
14
|
+
* add pytest-cov and pytest-xdist to dev dependencies ([59ed97f](https://github.com/KRoperUK/uw-py/commit/59ed97fd1dea1fa711b019d0e7a5e2910ceb9c66))
|
|
15
|
+
* drop test matrix so check name matches branch protection ([bb04962](https://github.com/KRoperUK/uw-py/commit/bb0496250368e767779c5a9ca599744601a0938f))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Documentation
|
|
19
|
+
|
|
20
|
+
* update README with hardcoded endpoints, API reference ([2e567bc](https://github.com/KRoperUK/uw-py/commit/2e567bca9d407f75dbc0987df6212cc2c74ae30e))
|
uw_api-0.2.0/PKG-INFO
ADDED
|
@@ -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`
|
uw_api-0.2.0/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# uw-api
|
|
2
|
+
|
|
3
|
+
Async Python client for the Utility Warehouse customer portal API.
|
|
4
|
+
|
|
5
|
+
Endpoints are hardcoded (discovered from `myaccount.uw.co.uk/`) and require no
|
|
6
|
+
configuration — just provide credentials.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install uw-api
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import asyncio
|
|
18
|
+
from uw_api import UWClient
|
|
19
|
+
|
|
20
|
+
async def main():
|
|
21
|
+
async with UWClient(email="user@example.com", password="secret") as client:
|
|
22
|
+
await client.login()
|
|
23
|
+
|
|
24
|
+
account = await client.gql.get_account()
|
|
25
|
+
print(f"Account: {account.account_number}")
|
|
26
|
+
|
|
27
|
+
bills = await client.gql.get_bills()
|
|
28
|
+
for bill in bills:
|
|
29
|
+
print(f"Bill {bill.bill_id}: £{bill.total_amount_gbp}")
|
|
30
|
+
|
|
31
|
+
consumption = await client.gql.get_consumption()
|
|
32
|
+
print(f"Electricity: {consumption.electricity_kwh} kWh")
|
|
33
|
+
print(f"Gas: {consumption.gas_kwh} kWh")
|
|
34
|
+
|
|
35
|
+
meters = await client.gql.get_meters()
|
|
36
|
+
for meter in meters:
|
|
37
|
+
print(f"{meter.meter_type}: {meter.meter_number} (smart={meter.is_smart})")
|
|
38
|
+
|
|
39
|
+
tariff = await client.gql.get_tariff()
|
|
40
|
+
if tariff:
|
|
41
|
+
print(f"Tariff: {tariff.tariff_name}")
|
|
42
|
+
|
|
43
|
+
asyncio.run(main())
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API Reference
|
|
47
|
+
|
|
48
|
+
### Auth
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
client = UWClient(email="...", password="...")
|
|
52
|
+
await client.login()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Authenticates via OAuth2 PKCE at `account.uw.co.uk/v2/login`. Session cookies are
|
|
56
|
+
managed automatically. The library re-authenticates on 401 responses.
|
|
57
|
+
|
|
58
|
+
### Account
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
account = await client.gql.get_account()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Returns `UWAccount` with `account_id` and `account_number`.
|
|
65
|
+
|
|
66
|
+
### Energy
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
consumption = await client.gql.get_consumption()
|
|
70
|
+
services = await client.gql.get_energy_services()
|
|
71
|
+
usage = await client.gql.get_energy_usage()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- `get_consumption()` → `EnergyConsumption` (latest electricity/gas kWh)
|
|
75
|
+
- `get_energy_services()` → raw list of energy service dicts
|
|
76
|
+
- `get_energy_usage()` → list of `EnergyUsage` with per-meter readings
|
|
77
|
+
|
|
78
|
+
### Meters
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
meters = await client.gql.get_meters()
|
|
82
|
+
readings = await client.gql.get_meter_readings()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- `get_meters()` → list of `Meter` (type, serial, smart status, last reading date)
|
|
86
|
+
- `get_meter_readings()` → list of `MeterReading` (value, type, date, source)
|
|
87
|
+
|
|
88
|
+
### Bills
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
bills = await client.gql.get_bills()
|
|
92
|
+
pdf_url = await client.gql.get_pdf_url(month=1, year=2026)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- `get_bills()` → list of `Bill` (ID, date, amount, status, PDF URL)
|
|
96
|
+
- `get_pdf_url(month, year)` → str URL for the bill PDF
|
|
97
|
+
|
|
98
|
+
### Financial
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
balance = await client.gql.get_balance()
|
|
102
|
+
services = await client.gql.get_live_services()
|
|
103
|
+
tariff = await client.gql.get_tariff()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- `get_balance()` → `{"due": float, "overdue": float}`
|
|
107
|
+
- `get_live_services()` → dict of service statuses
|
|
108
|
+
- `get_tariff()` → `EnergyTariff` (name, code, rates)
|
|
109
|
+
|
|
110
|
+
## Hardcoded Endpoints
|
|
111
|
+
|
|
112
|
+
| Purpose | URL |
|
|
113
|
+
|---------|-----|
|
|
114
|
+
| Login page | `https://account.uw.co.uk/v2/login` |
|
|
115
|
+
| GraphQL API | `https://myaccount.uw.co.uk/server/graphql` |
|
|
116
|
+
|
|
117
|
+
11 GraphQL operations are embedded in `uw_api/graphql/queries.py`.
|
|
118
|
+
|
|
119
|
+
## Discovery Script (optional)
|
|
120
|
+
|
|
121
|
+
A HAR-based discovery script is included for verifying or re-discovering endpoints:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
python scripts/discover_api.py parse-har capture.har
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
This is **not required** for normal use — the library ships with hardcoded
|
|
128
|
+
endpoints discovered from `myaccount.uw.co.uk/` in July 2026.
|
|
129
|
+
|
|
130
|
+
## Architecture
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
UWClient → UWAuth (OAuth2 PKCE)
|
|
134
|
+
→ UWGraphQL → /server/graphql (POST)
|
|
135
|
+
→ Pydantic v2 models
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- **Auth**: CSRF token extraction from login page HTML, form-encoded POST with
|
|
139
|
+
Castle.io device token
|
|
140
|
+
- **GraphQL**: All data via `POST /server/graphql` with operation-oriented queries
|
|
141
|
+
- **Retry**: 3 attempts with exponential backoff on 429/5xx, re-auth on 401
|
|
142
|
+
- **Models**: `UWAccount`, `EnergyUsage`, `EnergyConsumption`, `EnergyTariff`,
|
|
143
|
+
`Meter`, `MeterReading`, `Bill`, `BillPDFMetadata`
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "uw-api"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Async Python client for the Utility Warehouse customer portal API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Kieran", email = "kieran@example.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["utility-warehouse", "energy", "home-assistant"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
dependencies = [
|
|
27
|
+
"httpx>=0.28.1",
|
|
28
|
+
"pydantic>=2.13.4",
|
|
29
|
+
"pdfplumber>=0.11.10",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"pytest>=9.1.1",
|
|
35
|
+
"pytest-asyncio>=1.4.0",
|
|
36
|
+
"pytest-cov>=7.1.0",
|
|
37
|
+
"pytest-httpx>=0.36.2",
|
|
38
|
+
"pytest-xdist>=3.8.0",
|
|
39
|
+
"ruff>=0.16.0",
|
|
40
|
+
"mypy>=2.3.0",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[tool.ruff]
|
|
44
|
+
target-version = "py311"
|
|
45
|
+
line-length = 100
|
|
46
|
+
|
|
47
|
+
[tool.ruff.lint]
|
|
48
|
+
select = [
|
|
49
|
+
"E", "W", "F", "I", "N", "UP",
|
|
50
|
+
"B", "C4", "SIM", "RUF",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[tool.ruff.format]
|
|
54
|
+
quote-style = "double"
|
|
55
|
+
|
|
56
|
+
[tool.mypy]
|
|
57
|
+
python_version = "3.11"
|
|
58
|
+
strict = true
|
|
59
|
+
warn_return_any = true
|
|
60
|
+
warn_unused_configs = true
|
|
61
|
+
files = ["src/uw_api"]
|
|
62
|
+
|
|
63
|
+
[tool.pytest.ini_options]
|
|
64
|
+
asyncio_mode = "auto"
|
|
65
|
+
testpaths = ["tests"]
|