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.5.tar.gz (42.1 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.5-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meridian_energy-0.1.5.tar.gz
  • Upload date:
  • Size: 42.1 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.5.tar.gz
Algorithm Hash digest
SHA256 bb49e16f58eb6caeefe106fd93ff86530f7d72ae8c500fe96a3cc08ca444eb28
MD5 d3fc7bc1d1d62a5ce0f5509045a2961c
BLAKE2b-256 58b4ba83ed229edb81549346691b40161895fcc8b49ac75dc10fa088347ece7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for meridian_energy-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bda1695bc154a08fa2c97b33bcd3afedf8a31910a445aff38a82c048b391d683
MD5 ebdd89da2d4a1af4f144c0d07df515b9
BLAKE2b-256 8ba7649f1a40c449712361a8dabd41c5d4e293cffc52baaef4c058f040885ddc

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