Skip to main content

Python client for the Meridian Energy (NZ) customer GraphQL API

Project description

meridian-energy

PyPI

Python client for the Meridian Energy (NZ) customer API.

Unofficial. Not affiliated with or endorsed by Meridian Energy.

Talks to the current MyMeridian stack:

  1. Email one-time code (auth.meridianenergy.nz)
  2. Firebase custom-token exchange
  3. GraphQL (“Kraken”) at api.meridianenergy.nz

Install

pip install meridian-energy
# or
uv add meridian-energy

Requires Python 3.11+.

CLI

uvx meridian login                 # emails a code, prompts for it
uvx meridian accounts
uvx meridian usage --days 14
uvx meridian usage --json
uvx meridian status
uvx meridian logout

Tokens are cached at ~/.cache/meridian-energy/tokens.json (mode 0600). Override with --token-cache or MERIDIAN_TOKEN_CACHE. Email can come from MERIDIAN_EMAIL.

Library

import asyncio
import httpx
from meridian_energy import MeridianEnergyApi, MeridianEnergyAuth

async def main() -> None:
    auth = MeridianEnergyAuth()
    async with httpx.AsyncClient(timeout=30) as http:
        journey = await auth.request_otp(http, "you@example.com")
        await auth.verify_otp(http, "you@example.com", "123456", journey)

    async with MeridianEnergyApi(auth) as api:
        for account in await api.get_accounts():
            print(account.number, account.primary_icp)
            usage = await api.get_usage(account.number, days=10)
            print(usage.import_kwh, usage.export_kwh, usage.cost_nzd)

asyncio.run(main())

Resume a session from stored tokens (refresh is transparent):

from meridian_energy import MeridianEnergyAuth, MeridianEnergyApi, TokenSet

async def save(tokens: TokenSet) -> None:
    store.write(tokens.to_dict())

auth = MeridianEnergyAuth(
    tokens=TokenSet.from_dict(store.read()),
    on_token_update=save,
)
api = MeridianEnergyApi(auth)

Development

uv sync --group dev
uv run ruff check src tests
uv run ruff format src tests
uv run ty check src
uv run pytest

Home Assistant

The companion integration is hardbyte/ha-meridian-energy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meridian_energy-0.1.4.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

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

meridian_energy-0.1.4-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file meridian_energy-0.1.4.tar.gz.

File metadata

  • Download URL: meridian_energy-0.1.4.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for meridian_energy-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b6d4a371b79a091698a13601bb9e8bba2bc7e865f498309ffd466b46507c4e24
MD5 2fa34636e8a413f9eaf4dd70e72b490a
BLAKE2b-256 01243a21498ea347c3e63da2003f9237431cb44f6c29333b6b031c08e461b41e

See more details on using hashes here.

File details

Details for the file meridian_energy-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for meridian_energy-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a423c922a10d075f3ae74ba536f34378ba0648d084dec1c3746f10dd66d3402
MD5 750b80896ba2fcebf06143ce242b2253
BLAKE2b-256 f9afa2200fb5ee97ffd51663662a1a66dd2a883bf981e00c1e50de2ba34ca2d0

See more details on using hashes here.

Supported by

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