Getting Started

Fetch and display power generation by fuel type from the NEM

This guide walks through fetching a day of power generation data from Australia’s National Electricity Market (NEM), grouped by fuel technology, and displaying it as a table. By the end you’ll have a working script in either Python or TypeScript.

Prerequisites

You’ll need an API key from the Open Electricity Platform. See SDK configuration for how to set it up as an environment variable.

Install the SDK

uv
bash
uv add openelectricity
pip
bash
pip install openelectricity
npm
bash
npm install openelectricity
bun
bash
bun add openelectricity

Both SDKs read your OPENELECTRICITY_API_KEY environment variable automatically — no need to pass credentials in code.

    Initialise the client

    The client handles authentication, request retries and response parsing. See the SDK overview for more detail.

    Python
    python
    from openelectricity import OEClient
    
    client = OEClient()
    TypeScript
    typescript
    import { OpenElectricityClient } from "openelectricity"
    
    const client = new OpenElectricityClient()

    Build the date range

    We’ll query yesterday’s full 24-hour window so the data is complete.

    Python
    python
    from datetime import datetime, timedelta
    
    yesterday = (datetime.now() - timedelta(days=1)).replace(
        hour=0, minute=0, second=0, microsecond=0
    )
    today = yesterday + timedelta(days=1)
    TypeScript
    typescript
    const yesterday = new Date()
    yesterday.setDate(yesterday.getDate() - 1)
    yesterday.setHours(0, 0, 0, 0)
    
    const today = new Date(yesterday)
    today.setDate(today.getDate() + 1)
    
    const fmt = (d: Date) =>
      `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}T00:00:00`

    Request power data

    Call get_network_data / getNetworkData with these parameters:

    • network_code="NEM" — the National Electricity Market covering eastern Australia
    • metrics=[DataMetric.POWER] — instantaneous generation in MW. See the power guide
    • interval="1h" — hourly aggregation
    • secondary_grouping="fueltech_group" — break results down by fuel technology group (solar, wind, coal, etc.)
    Python
    python
    from openelectricity.types import DataMetric
    
    with OEClient() as client:
        response = client.get_network_data(
            network_code="NEM",
            metrics=[DataMetric.POWER],
            interval="1h",
            date_start=yesterday,
            date_end=today,
            secondary_grouping="fueltech_group",
        )
    TypeScript
    typescript
    const { datatable } = await client.getNetworkData("NEM", ["power"], {
      interval: "1h",
      dateStart: fmt(yesterday),
      dateEnd: fmt(today),
      secondaryGrouping: ["fueltech_group"],
    })

    Understand the response

    The API returns time series data grouped by your requested dimensions. Each series contains:

    FieldDescription
    metricThe metric name (power)
    unitUnit of measurement (MW)
    resultsArray of named series, one per fuel technology group

    Each result has a data array of { timestamp, value } pairs at the requested interval.

    Display as a table

    Python
    python
    # Option 1: Polars DataFrame
    df = response.to_polars()
    print(df)
    
    # Option 2: Console-friendly records
    for record in response.to_records():
        print(record)
    TypeScript
    typescript
    console.table(datatable.toConsole())

Complete example

Runnable end-to-end scripts you can copy and execute directly.

Python
python
from datetime import datetime, timedelta
from openelectricity import OEClient
from openelectricity.types import DataMetric

yesterday = (datetime.now() - timedelta(days=1)).replace(
    hour=0, minute=0, second=0, microsecond=0
)
today = yesterday + timedelta(days=1)

with OEClient() as client:
    response = client.get_network_data(
        network_code="NEM",
        metrics=[DataMetric.POWER],
        interval="1h",
        date_start=yesterday,
        date_end=today,
        secondary_grouping="fueltech_group",
    )
    df = response.to_polars()
    print(df)
TypeScript
typescript
import { OpenElectricityClient } from "openelectricity"

const yesterday = new Date()
yesterday.setDate(yesterday.getDate() - 1)
yesterday.setHours(0, 0, 0, 0)

const today = new Date(yesterday)
today.setDate(today.getDate() + 1)

const fmt = (d: Date) =>
  `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}T00:00:00`

const client = new OpenElectricityClient()
const { datatable } = await client.getNetworkData("NEM", ["power"], {
  interval: "1h",
  dateStart: fmt(yesterday),
  dateEnd: fmt(today),
  secondaryGrouping: ["fueltech_group"],
})

console.table(datatable.toConsole())

Next steps

↑↓ navigate open esc close