Skip to main content

OpenElectricity Python Client

Project description

OpenElectricity Python Client

logo

[!WARNING] This project and the v4 API are currently under active development.

A Python client for the OpenElectricity API, providing access to electricity and energy network data and metrics for Australia.

[!NOTE] API key signups are currently waitlisted and will be released gradually.

To obtain an API key visit platform.openelectricity.org.au

For documentation visit docs.openelectricity.org.au

Features

  • Synchronous and asynchronous API clients
  • Fully typed with comprehensive type annotations
  • Automatic request retries and error handling
  • Context manager support
  • Modern Python (3.10+) with full type annotations
  • Direct conversion to Pandas and Polars DataFrames

Installation

# Install base package
pip install openelectricity

# or with uv (recommended)
uv add openelectricity

# Install with data analysis support (Polars/Pandas)
uv add "openelectricity[analysis]"

Quick Start

First, set your API key in the environment:

# Set your API key
export OPENELECTRICITY_API_KEY=your-api-key

# Optional: Override API server (defaults to production)
export OPENELECTRICITY_API_URL=http://localhost:8000/v4

Then in your code:

from datetime import datetime, timedelta
from openelectricity import OEClient
from openelectricity.types import DataMetric, UnitFueltechType, UnitStatusType

# Calculate date range
end_date = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
start_date = end_date - timedelta(days=7)

# Using context manager (recommended)
with OEClient() as client:
    # Get operating solar and wind facilities
    facilities = client.get_facilities(
        network_id=["NEM"],
        status_id=[UnitStatusType.OPERATING],
        fueltech_id=[UnitFueltechType.SOLAR_UTILITY, UnitFueltechType.WIND],
    )

    # Get network data for NEM
    response = client.get_network_data(
        network_code="NEM",
        metrics=[DataMetric.POWER, DataMetric.ENERGY],
        interval="1d",
        date_start=start_date,
        date_end=end_date,
        secondary_grouping="fueltech_group",
    )

    # Print results
    for series in response.data:
        print(f"\nMetric: {series.metric}")
        print(f"Unit: {series.unit}")

        for result in series.results:
            print(f"\n  {result.name}:")
            print(f"  Fuel Tech Group: {result.columns.fueltech_group}")
            for point in result.data:
                print(f"    {point.timestamp}: {point.value:.2f} {series.unit}")

For async usage:

from openelectricity import AsyncOEClient
import asyncio

async def main():
    async with AsyncOEClient() as client:
        # Get operating solar and wind facilities
        facilities = await client.get_facilities(
            network_id=["NEM"],
            status_id=[UnitStatusType.OPERATING],
            fueltech_id=[UnitFueltechType.SOLAR_UTILITY, UnitFueltechType.WIND],
        )

        # Get network data
        response = await client.get_network_data(
            network_code="NEM",
            metrics=[DataMetric.POWER],
            interval="1d",
            secondary_grouping="fueltech_group",
        )
        # Process response...

asyncio.run(main())

Data Analysis

The client provides built-in support for converting API responses to popular data analysis formats.

Using with Polars

# Make sure you've installed with analysis extras
# uv add "openelectricity[analysis]"

from openelectricity import OEClient
from openelectricity.types import DataMetric

with OEClient() as client:
    response = client.get_network_data(
        network_code="NEM",
        metrics=[DataMetric.POWER, DataMetric.ENERGY],
        interval="1d",
        secondary_grouping="fueltech_group",
    )

    # Convert to Polars DataFrame
    df = response.to_polars()

    # Get metric units
    units = response.get_metric_units()

    # Analyze data
    energy_by_fueltech = (
        df.group_by("fueltech_group")
        .agg(
            pl.col("energy").sum().alias("total_energy_mwh"),
            pl.col("power").mean().alias("avg_power_mw"),
        )
        .sort("total_energy_mwh", descending=True)
    )

Using with Pandas

# Make sure you've installed with analysis extras
# uv add "openelectricity[analysis]"

from openelectricity import OEClient
from openelectricity.types import DataMetric

with OEClient() as client:
    response = client.get_network_data(
        network_code="NEM",
        metrics=[DataMetric.POWER, DataMetric.ENERGY],
        interval="1d",
        secondary_grouping="fueltech_group",
    )

    # Convert to Pandas DataFrame
    df = response.to_pandas()

    # Get metric units
    units = response.get_metric_units()

    # Analyze data
    energy_by_fueltech = (
        df.groupby("fueltech_group")
        .agg({
            "energy": "sum",
            "power": "mean",
        })
        .sort_values("energy", ascending=False)
    )

Development

  1. Clone the repository

  2. Install development dependencies:

    make install
    
  3. Run tests:

    make test
    
  4. Format code:

    make format
    
  5. Run linters:

    make lint
    

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

openelectricity-0.6.1.tar.gz (192.8 kB view details)

Uploaded Source

Built Distribution

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

openelectricity-0.6.1-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file openelectricity-0.6.1.tar.gz.

File metadata

  • Download URL: openelectricity-0.6.1.tar.gz
  • Upload date:
  • Size: 192.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for openelectricity-0.6.1.tar.gz
Algorithm Hash digest
SHA256 150209c3ad1eda2874251b5b1b6a11bf0b6668fc0f6b9a1453693e287278e30c
MD5 a791e4f425e6a6cc8a95b41623e8f6ba
BLAKE2b-256 4c50a2a67e0a4144662c839038330d08cadede9b4627c4f0d429f285462e0c1b

See more details on using hashes here.

File details

Details for the file openelectricity-0.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for openelectricity-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12058579fce4fc9cfaacfd9b56aa9d962b3a444dc27f37956ecad90114c42412
MD5 1d063304258f7f9b12eb9597831d0b0c
BLAKE2b-256 b4f9316d3bcb87f70223f46d64f23107e921a966d3cd725cfc5820f6b82e5904

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