Skip to main content
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 add openelectricity
Both SDKs read your OPENELECTRICITY_API_KEY environment variable automatically — no need to pass credentials in code.
1
Initialise the client
2
The client handles authentication, request retries and response parsing. See the SDK overview for more detail.
3
Python
from openelectricity import OEClient

client = OEClient()
TypeScript
import { OpenElectricityClient } from "openelectricity"

const client = new OpenElectricityClient()
4
Build the date range
5
We’ll query yesterday’s full 24-hour window so the data is complete.
6
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
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`
7
Using yesterday ensures you always get a full day of settled data. Today’s data may still be arriving.
8
Request power data
9
Call get_network_data / getNetworkData with these parameters:
10
  • 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.)
  • 11
    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
    const { datatable } = await client.getNetworkData("NEM", ["power"], {
      interval: "1h",
      dateStart: fmt(yesterday),
      dateEnd: fmt(today),
      secondaryGrouping: ["fueltech_group"],
    })
    
    12
    Understand the response
    13
    The API returns time series data grouped by your requested dimensions. Each series contains:
    14
    FieldDescriptionmetricThe metric name (power)unitUnit of measurement (MW)resultsArray of named series, one per fuel technology group
    15
    Each result has a data array of { timestamp, value } pairs at the requested interval.
    16
    Display as a table
    17
    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
    console.table(datatable.toConsole())
    

    Complete example

    Runnable end-to-end scripts you can copy and execute directly.
    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)
    

    Next steps