A python library to interface with the KUB api
Project description
KUB
An async Python library for retrieving utility usage data from the Knoxville Utilities Board (KUB) API.
Features
- Authenticates via Azure AD B2C using PKCE OAuth2, mirroring the KUB web app flow
- Supports electricity, gas, water, and wastewater services
- Retrieves hourly usage and cost data for any date range
- Session management with automatic token refresh
- Compatible with Home Assistant custom components
Requirements
- Python 3.12 or higher
- aiohttp 3.9 or higher
Installation
pip install kub
Usage
Basic setup
import asyncio
from kub import KubUtility
async def main():
utility = KubUtility("your@email.com", "yourpassword")
# Retrieve usage for the last 31 days
usage = await utility.retrieve_last_31_days()
print(usage)
asyncio.run(main())
Available methods
| Method | Description |
|---|---|
retrieve_last_31_days() |
Fetches hourly usage for the past 31 days across all services |
retrieve_monthly_usage() |
Fetches hourly usage from the first of the current month to today |
retrieve_usage_by_range(start_date, end_date) |
Fetches usage for a custom range; dates are YYYY-MM-DD strings |
retrieve_account_info() |
Fetches account metadata (account ID, person ID, service list) without pulling usage data |
Usage data structure
The usage attribute is a dictionary keyed by utility type, then by date, then by time:
{
"electricity": {
"2026-05-01": {
"08:00:00": {
"id": "...",
"readDateTime": "2026-05-01T08:00:00",
"utilityUsed": 0.42,
"uom": "kWh",
"cost": 0.06
},
...
},
...
},
"gas": { ... },
"water": { ... },
"wastewater": { ... }
}
Monthly totals (for the current calendar month) are available via monthly_total:
utility.monthly_total["electricity"]
# {"usage": 312.5, "cost": 42.18}
Supported utility types
The KUBUtilityTypes enum represents the services KUB provides:
from kub import KUBUtilityTypes
KUBUtilityTypes.ELECTRICITY
KUBUtilityTypes.GAS
KUBUtilityTypes.WATER
KUBUtilityTypes.WASTEWATER
Only the services active on your account are populated. Check utility.service_list after calling any retrieval method to see which types are present.
Home Assistant
This library is designed to work as a dependency for a Home Assistant custom component. Place the kub directory inside custom_components/ and import from it using standard relative imports.
Development
Install development dependencies:
pip install -e ".[dev]"
Run the test suite:
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kub-0.6.5.tar.gz.
File metadata
- Download URL: kub-0.6.5.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac5fb17d0df739d2954aee75a28c1084d97b8055290b45d9e06af77dbb46e0b1
|
|
| MD5 |
8765ef8ad73201bc7fd9c5797b4c351c
|
|
| BLAKE2b-256 |
00bf80cada82e8307f268a4b560e9018e23976ca984cab1a0271bc31ee0f4030
|
Provenance
The following attestation bundles were made for kub-0.6.5.tar.gz:
Publisher:
release.yml on JackJPowell/KUB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kub-0.6.5.tar.gz -
Subject digest:
ac5fb17d0df739d2954aee75a28c1084d97b8055290b45d9e06af77dbb46e0b1 - Sigstore transparency entry: 1625688941
- Sigstore integration time:
-
Permalink:
JackJPowell/KUB@7e768278dad1001296bb4e1d855f9039f6db82e5 -
Branch / Tag:
refs/tags/v0.6.5 - Owner: https://github.com/JackJPowell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e768278dad1001296bb4e1d855f9039f6db82e5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kub-0.6.5-py3-none-any.whl.
File metadata
- Download URL: kub-0.6.5-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ff2cbb88d19bbade9b953ef1089f0e1d419f9ca1cf1b9b8e6d4cadb3180282f
|
|
| MD5 |
56476f3a51d9ee6a13ace0489daa2191
|
|
| BLAKE2b-256 |
92cb5ccb0fdbe67791f8f85169114adf85723684df226aa5dcaf906728bac7d8
|
Provenance
The following attestation bundles were made for kub-0.6.5-py3-none-any.whl:
Publisher:
release.yml on JackJPowell/KUB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kub-0.6.5-py3-none-any.whl -
Subject digest:
2ff2cbb88d19bbade9b953ef1089f0e1d419f9ca1cf1b9b8e6d4cadb3180282f - Sigstore transparency entry: 1625688979
- Sigstore integration time:
-
Permalink:
JackJPowell/KUB@7e768278dad1001296bb4e1d855f9039f6db82e5 -
Branch / Tag:
refs/tags/v0.6.5 - Owner: https://github.com/JackJPowell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e768278dad1001296bb4e1d855f9039f6db82e5 -
Trigger Event:
push
-
Statement type: