Skip to main content

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_gst to 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 Spot with is_stale true, or with null prices, is a valid 200. 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 Forecast with no points, or Windows with empty cheap/dear, is a valid 200 with unavailable_reason set.
  • Read covered_hours, not horizon_hours. The latter is only your request echoed back after clamping; the former is how far the published schedules reach.
  • Use trading_date and trading_period verbatim. 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-aware datetime objects.
  • 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 and Retry-After on a 429; scheduling and backoff belong to the caller. The most recent budget is on the rate_limit property.
  • 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

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

aioecosmart-0.1.0.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioecosmart-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

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

Hashes for aioecosmart-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d65704afa1c879725417ffdc17907d73c5c404d91a8f8515d610753e5e6285a9
MD5 fd935be2e67f4973bdd562b279778a56
BLAKE2b-256 751ab3ab5819893fb9b29366125d4facf5e2dba9cf0a6b60e6e2085a6849ccea

See more details on using hashes here.

Provenance

The following attestation bundles were made for aioecosmart-0.1.0.tar.gz:

Publisher: release.yml on ecosmart-nz/aioecosmart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for aioecosmart-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 806836dd02b97882880630a3d97d6e4e7c32731b1f57c65d344db99aec8fcb91
MD5 4702d22d645b6a1941c8a727c1fea642
BLAKE2b-256 c2f2457191ba79dbcc2d11d20e6c449f7b32039c1935e85424a2b123ce119f41

See more details on using hashes here.

Provenance

The following attestation bundles were made for aioecosmart-0.1.0-py3-none-any.whl:

Publisher: release.yml on ecosmart-nz/aioecosmart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page