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 keyed by service point, then by date, then by time. For
an account with one meter for a utility, the service-point key is the utility
name (for example, "electricity"). When an account has multiple meters of the
same utility, the key is <utility>_<service-point-id> (for example,
"electricity_12345").
{
"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 the available service-point keys.
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
Release files for kub 0.8.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 | |
|---|---|---|---|
| kub-0.8.0.tar.gz | 13.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kub-0.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.7 kB
Release files / kub-0.8.0.tar.gz
| Download URL | kub-0.8.0.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd5deabdd5f1099ce7fd3cc929459d5658bde50e6c8c90ff268d138136d4f0ac
|
|
BLAKE2b-256 checksum How to use checksums |
a3fd74e4a460d1049dbef6393c90feb73985e6f0f68a80d3eac76e372d245ce0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / kub-0.8.0-py3-none-any.whl
| Download URL | kub-0.8.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09273c4d9c3b7395d41deaa02a0f606fcb53103a3336c7edca39c9f581e2091c
|
|
BLAKE2b-256 checksum How to use checksums |
a303666d1de3244ecfb39bc137e7317effde8c1578de82e9d2b14ff3385adaa5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency log