Skip to main content

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.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kub 0.7.0
File Size Uploaded
kub-0.7.0.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kub 0.7.0
File Interpreter ABI Platform
kub-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.6 kB

Release files / kub-0.7.0.tar.gz

Download URL kub-0.7.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c2b562f2ce0509345f1a0ec887fcb8745f6bf9f6139864ea9afd7cf00af7426a
BLAKE2b-256 checksum
How to use checksums
381c49e8e1d6fb0e91f485f90c45a4981bec3549450edf77fe34163738485d00
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 5, 2026.

Transparency log

Release files / kub-0.7.0-py3-none-any.whl

Download URL kub-0.7.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfc029f28ff090d9bad5b40773f48b44f6bb213c13fbe1ce28b0bcf1fa9b6c2a
BLAKE2b-256 checksum
How to use checksums
b84ff239b532bc3d0a81440dafe3a6a3212b7ce9fdb0cf1d54083e5b02df2535
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 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

2 release files

This release

0.7.0 This release

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page