Repository navigation
v0.5.0
First release of the py-nationalgrid fork (forked from the abandoned aionatgrid 0.4.0).
Added
- AMI 15-minute chunking (
get_ami_energy_usages_15min): automatically splits
date ranges exceeding 45 days into 45-day chunks to stay within the National
Grid API's ~10,000 record cap and the Azure Application Gateway backend timeout. - Newest-first chunk ordering: chunks are iterated from most-recent to oldest,
guaranteeing that data within the hot-storage window is always collected before
an older chunk may hit a 504. - Graceful 504 truncation: when a chunk returns a 504 Gateway Timeout (cold/
archive storage boundary), the method logs a warning and returns the records
already collected rather than raising an exception. Callers should not assume
the returned list covers the full requested date range. - 504 retry short-circuit:
_should_retry()immediately returnsFalsefor
GraphQLError(status=504)— cold-storage 504s are deterministic, so retrying
wastes time. - Daily-endpoint fallback: meters that don't support the 15-minute GraphQL
operation fall back transparently to the dailyamiEnergyUsagesendpoint. __version__attribute on the package (py_nationalgrid.__version__).- PEP 561
py.typedmarker so downstream projects using mypy strict mode
get inline type information.
Fixed
NationalGridConfig.with_overrides()bug: was usingdataclasses.asdict()
which flattened nested dataclasses (e.g.RetryConfig) into plain dicts,
causingAttributeErroron subsequent attribute access. Fixed with
dataclasses.replace().- JSON error boundary:
json.loads()calls inoidchelper.pynow raise
CannotConnectErroron malformed responses instead of an unhandled
json.JSONDecodeError. - Exception chaining:
CannotConnectErroris now raised withfrom errso
the originalaiohttp.ClientErroris preserved in the traceback. - JWKS client cache:
PyJWKClientinstances are cached at module level in
oidchelper.pyto avoid a redundant HTTPS round-trip to the JWKS endpoint on
every login. assert session is not Nonereplaced with an explicitRuntimeErrorin
oidchelper.pyfor a clear error message when the session is missing.
Changed
- Connection pool defaults reduced from 100/30 to 10/10
(connection_limit/connection_limit_per_host) — more appropriate for a
single-API consumer. - Logger naming unified to
logger(from_LOGGER) throughoutauth.py
andoidchelper.py - Removed unused
typing-extensionsdependency.