Back to SDKs
Py

Python SDK

energyoracle

Type hintsAsync supportPandas integrationCLI includedPython 3.8+

Installation

bash
pip install energyoracle

# Or with optional dependencies
pip install energyoracle[pandas]   # Include pandas support
pip install energyoracle[async]    # Include async support
pip install energyoracle[all]      # Include everything

Quick Start

python
from energyoracle import EnergyOracle

# Initialize client
oracle = EnergyOracle(api_key="your-api-key")

# Get latest UK system price
price = oracle.uk.prices.latest()
print(f"Current price: £{price.value}/MWh")

# Get carbon intensity
carbon = oracle.uk.carbon.current()
print(f"Carbon: {carbon.intensity} gCO2/kWh")

Async Support

Use AsyncEnergyOracle for async/await syntax and concurrent requests.

python
import asyncio
from energyoracle import AsyncEnergyOracle

async def main():
    async with AsyncEnergyOracle(api_key="your-api-key") as oracle:
        # Concurrent requests
        price, carbon = await asyncio.gather(
            oracle.uk.prices.latest(),
            oracle.uk.carbon.current()
        )
        print(f"Price: £{price.value}/MWh")
        print(f"Carbon: {carbon.intensity} gCO2/kWh")

asyncio.run(main())

API Reference

oracle.uk.prices

Access UK electricity system prices from Elexon BMRS.

python
# Latest system price
latest = oracle.uk.prices.latest()
# SystemPrice(settlement_date='2024-12-20', period=28, price=52.34)

# Price for specific date
date_prices = oracle.uk.prices.date("2024-12-20")
# Returns list of 48 half-hourly prices

# Price range
range_prices = oracle.uk.prices.range("2024-12-01", "2024-12-20")

# Monthly average
monthly = oracle.uk.prices.monthly_average(2024, 12)
# MonthlyAverage(month='2024-12', avg_price=48.72, min_price=12.50, max_price=95.20)

oracle.uk.carbon

Grid carbon intensity and fuel mix data.

python
# Current carbon intensity
current = oracle.uk.carbon.current()
# CarbonIntensity(intensity=142, index='moderate', forecast=[...])

# Current fuel mix
fuel_mix = oracle.uk.carbon.fuel_mix()
# FuelMix(wind=35.2, solar=8.1, gas=28.5, nuclear=15.0, ...)

# Regional carbon intensity (14 UK regions)
regional = oracle.uk.carbon.regional()

# Carbon by postcode
local = oracle.uk.carbon.by_postcode("SW1A 1AA")

oracle.uk.analytics

Derived metrics for PPA settlement and trading.

python
# Calculate green premium
premium = oracle.uk.analytics.green_premium(2024, 12)
# GreenPremium(green_premium_pct=-8.5, high_renewable_avg=42.3, low_renewable_avg=46.2)

# Calculate capture price (PPA metric)
capture = oracle.uk.analytics.capture_price(
    technology="wind",
    year=2024,
    month=12
)
# CapturePrice(capture_price=44.20, baseload_price=48.50, shape_factor=0.91)

# Settlement calculation
settlement = oracle.uk.settlement.calculate(
    volume_mwh=1000,
    contract_price=50,
    from_date="2024-12-01",
    to_date="2024-12-31"
)

Pandas Integration

All data responses include a .to_dataframe() method for easy data analysis.

python
import pandas as pd
from energyoracle import EnergyOracle

oracle = EnergyOracle(api_key="your-api-key")

# Get price range and convert to DataFrame
prices = oracle.uk.prices.range("2024-12-01", "2024-12-20")
df = prices.to_dataframe()

# DataFrame with columns: settlement_date, period, price, ssp, sbp
print(df.head())

# Quick analysis
print(f"Average price: £{df['price'].mean():.2f}/MWh")
print(f"Peak price: £{df['price'].max():.2f}/MWh")

# Group by date
daily_avg = df.groupby('settlement_date')['price'].mean()

# Merge with carbon data
carbon = oracle.uk.carbon.range("2024-12-01", "2024-12-20")
carbon_df = carbon.to_dataframe()

merged = pd.merge(df, carbon_df, on=['settlement_date', 'period'])

Command Line Interface

The CLI is included with the package for quick data access and exports.

bash
# CLI is included with the package
$ energyoracle --help

# Get latest price
$ energyoracle prices latest
Current UK System Price: £52.34/MWh
Settlement Date: 2024-12-20
Settlement Period: 28

# Get carbon intensity
$ energyoracle carbon current
Carbon Intensity: 142 gCO2/kWh
Index: moderate

# Export to CSV
$ energyoracle prices range --from 2024-12-01 --to 2024-12-20 --output prices.csv

# Calculate capture price
$ energyoracle analytics capture-price --technology wind --year 2024 --month 12

Type Hints

Full type annotations for IDE autocompletion and type checking with mypy.

python
from energyoracle import EnergyOracle
from energyoracle.types import (
    SystemPrice,
    CarbonIntensity,
    FuelMix,
    GreenPremium,
    CapturePrice,
)

oracle = EnergyOracle(api_key="your-api-key")

# All methods have full type hints
price: SystemPrice = oracle.uk.prices.latest()
carbon: CarbonIntensity = oracle.uk.carbon.current()

# IDE autocompletion works out of the box
print(price.settlement_date)
print(carbon.intensity)

Error Handling

The SDK provides typed exceptions and automatic retry with exponential backoff.

python
from energyoracle import EnergyOracle
from energyoracle.exceptions import (
    OracleError,
    RateLimitError,
    AuthenticationError,
)

oracle = EnergyOracle(api_key="your-api-key")

try:
    price = oracle.uk.prices.latest()
except RateLimitError as e:
    print(f"Rate limited. Retry after: {e.retry_after}s")
except AuthenticationError:
    print("Invalid API key")
except OracleError as e:
    print(f"API Error: {e.message} (status: {e.status})")

# Configure automatic retry
oracle = EnergyOracle(
    api_key="your-api-key",
    retries=3,
    retry_delay=1.0,  # Exponential backoff starting at 1s
)

Next Steps