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.
Metadata
Release files for aioecosmart 0.1.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 | Provenance | Actions |
|---|---|---|---|---|
| aioecosmart-0.1.0.tar.gz | 29.4 kB | With provenance | Details for aioecosmart-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aioecosmart-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for aioecosmart-0.1.0-py3-none-any.whl |
Total release size: 45.6 kB
Release files / aioecosmart-0.1.0.tar.gz
| Download URL | aioecosmart-0.1.0.tar.gz |
|---|---|
| Size | 29.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d65704afa1c879725417ffdc17907d73c5c404d91a8f8515d610753e5e6285a9
|
|
BLAKE2b-256 checksum How to use checksums |
751ab3ab5819893fb9b29366125d4facf5e2dba9cf0a6b60e6e2085a6849ccea
|
| 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 Aug 24, 2026.
Transparency logRelease files / aioecosmart-0.1.0-py3-none-any.whl
| Download URL | aioecosmart-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
806836dd02b97882880630a3d97d6e4e7c32731b1f57c65d344db99aec8fcb91
|
|
BLAKE2b-256 checksum How to use checksums |
c2f2457191ba79dbcc2d11d20e6c449f7b32039c1935e85424a2b123ce119f41
|
| 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 Aug 24, 2026.
Transparency logSecurity for aioecosmart 0.1.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for aioecosmart-0.1.0.tar.gz
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 Aug 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.