aioecosmart
Async Python client for the Ecosmart price API — live New Zealand wholesale electricity spot prices, forecasts and settled prices for the connection points an API key carries.
Ecosmart is a New Zealand electricity retailer that passes wholesale spot prices through to customers. Account holders mint their own API key in the Ecosmart app under More → Settings → Advanced → API keys.
This library backs the Home Assistant ecosmart integration. Nothing in it depends on
Home Assistant, so it is equally usable from a script, a battery controller, or a
dashboard.
Install
pip install aioecosmart
Requires Python 3.13 or newer.
Usage
import asyncio
from aioecosmart import EcosmartClient
async def main() -> None:
async with EcosmartClient("ecos_live_your_key_here") as client:
me = await client.me()
poc = me.allowed_icps[0].poc # the grid exit point for your ICP
now = await client.spot(poc)
if not now.is_stale and now.price_cents_per_kwh_incl_gst is not None:
print(f"{now.price_cents_per_kwh_incl_gst:.2f} c/kWh incl GST")
ahead = await client.forecast(poc, hours=48)
print(f"{ahead.count} half-hours, covering {ahead.covered_hours} h")
asyncio.run(main())
Pass your own aiohttp.ClientSession as the second argument and the client will use
it without ever closing it; omit it and the client makes and closes its own.
What it covers
All seven published endpoints:
| Method | Endpoint | Returns |
|---|---|---|
me() |
GET /me |
Identity — the key, its ICPs, its rate limit |
spot(poc) |
GET /gxps/{poc}/spot |
Spot — current 5-minute dispatch price |
spot_history(poc, hours=24) |
GET /gxps/{poc}/spot/history |
SpotHistory |
forecast(poc, hours=48) |
GET /gxps/{poc}/forecast |
Forecast — forward WITS prices |
final_prices(poc, from_date, to_date) |
GET /gxps/{poc}/final-prices |
FinalPrices — settled half-hours |
icp(icp) |
GET /icps/{icp} |
Icp |
windows(icp, n=6) |
GET /windows |
Windows — tomorrow's cheapest and dearest half-hours |
Things worth knowing before you build on it
- Prices are wholesale energy at the grid exit point, not a retail rate. Lines charges, metering, levies and retailer margin are not included.
- GST. Everything the market publishes is GST-exclusive. Use
price_cents_per_kwh_incl_gstto compare with a power bill. - Negative prices are real, especially overnight in the South Island. They pass through untouched.
- Stale is not an error. A
Spotwithis_staletrue, or with null prices, is a valid200. Treat it as unavailable rather than as a failure — a price more than about 15 minutes old must never drive a battery. - Empty is not an error either. A
Forecastwith no points, orWindowswith emptycheap/dear, is a valid200withunavailable_reasonset. - Read
covered_hours, nothorizon_hours. The latter is only your request echoed back after clamping; the former is how far the published schedules reach. - Use
trading_dateandtrading_periodverbatim. Two days a year have 46 or 50 trading periods instead of 48; never recompute half-hours locally. - Timestamps are UTC (
Z) and arrive as timezone-awaredatetimeobjects. - The library never retries and never throttles. The API allows a documented
minimum of 12 requests per minute per key, with
X-RateLimit-*on every response andRetry-Afteron a429; scheduling and backoff belong to the caller. The most recent budget is on therate_limitproperty. - Minting a new key revokes the previous one. A rotated key shows up as
EcosmartAuthError, indistinguishable from an unknown or revoked one.
Errors
Everything inherits EcosmartError.
| Exception | Cause |
|---|---|
EcosmartConnectionError |
Network failure, timeout, or a non-JSON body |
EcosmartAuthError |
401 — key missing, unknown, or revoked |
EcosmartIcpNotInScopeError |
403 — this key does not carry that ICP |
EcosmartUnknownPocError |
404 — no such grid exit point |
EcosmartInvalidRangeError |
400 — range backwards or longer than 62 days |
EcosmartRateLimitError |
429 — budget spent; .retry_after holds the seconds |
Documentation
- Human documentation: https://www.ecosmart.co.nz/electricity/api/
- Machine contract: https://www.ecosmart.co.nz/electricity/openapi.yaml
Licence
MIT. See LICENSE.
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 aioecosmart-0.1.0.tar.gz.
File metadata
- Download URL: aioecosmart-0.1.0.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d65704afa1c879725417ffdc17907d73c5c404d91a8f8515d610753e5e6285a9
|
|
| MD5 |
fd935be2e67f4973bdd562b279778a56
|
|
| BLAKE2b-256 |
751ab3ab5819893fb9b29366125d4facf5e2dba9cf0a6b60e6e2085a6849ccea
|
Provenance
The following attestation bundles were made for aioecosmart-0.1.0.tar.gz:
Publisher:
release.yml on ecosmart-nz/aioecosmart
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aioecosmart-0.1.0.tar.gz -
Subject digest:
d65704afa1c879725417ffdc17907d73c5c404d91a8f8515d610753e5e6285a9 - Sigstore transparency entry: 2581904675
- Sigstore integration time:
-
Permalink:
ecosmart-nz/aioecosmart@88d1eff8ee075a4ae537a454880c23fcf2b6c571 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ecosmart-nz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@88d1eff8ee075a4ae537a454880c23fcf2b6c571 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aioecosmart-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aioecosmart-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
806836dd02b97882880630a3d97d6e4e7c32731b1f57c65d344db99aec8fcb91
|
|
| MD5 |
4702d22d645b6a1941c8a727c1fea642
|
|
| BLAKE2b-256 |
c2f2457191ba79dbcc2d11d20e6c449f7b32039c1935e85424a2b123ce119f41
|
Provenance
The following attestation bundles were made for aioecosmart-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ecosmart-nz/aioecosmart
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aioecosmart-0.1.0-py3-none-any.whl -
Subject digest:
806836dd02b97882880630a3d97d6e4e7c32731b1f57c65d344db99aec8fcb91 - Sigstore transparency entry: 2581904678
- Sigstore integration time:
-
Permalink:
ecosmart-nz/aioecosmart@88d1eff8ee075a4ae537a454880c23fcf2b6c571 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ecosmart-nz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@88d1eff8ee075a4ae537a454880c23fcf2b6c571 -
Trigger Event:
release
-
Statement type: