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 add openelectricitypip install openelectricitynpm install openelectricitybun add openelectricityBoth SDKs read your OPENELECTRICITY_API_KEY environment variable automatically — no need to pass credentials in code.
network_code="NEM"— the National Electricity Market covering eastern Australiametrics=[DataMetric.POWER]— instantaneous generation in MW. See the power guideinterval="1h"— hourly aggregationsecondary_grouping="fueltech_group"— break results down by fuel technology group (solar, wind, coal, etc.)
Initialise the client
The client handles authentication, request retries and response parsing. See the SDK overview for more detail.
from openelectricity import OEClient
client = OEClient()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.
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)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:
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",
)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:
| Field | Description |
|---|---|
| metric | The metric name (power) |
| unit | Unit of measurement (MW) |
| results | Array 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
# Option 1: Polars DataFrame
df = response.to_polars()
print(df)
# Option 2: Console-friendly records
for record in response.to_records():
print(record)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)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())