Async Python client library for the Octopus Energy REST API
Project description
Octopy Energy API
An async Python client library for the Octopus Energy REST API
Features
- Async API Client - Full async/await support with
httpx - Comprehensive Data Models - Fully typed Pydantic models for all API responses
- Secure - Built-in API key authentication
- Type-Safe - Complete type hints for better IDE support
- Automatic Pagination - Seamlessly fetch all pages of data
Installation
pip install octopy-energy-api
Requirements
- An Octopus Energy account and API key (if using the Account and Consumption endpoints)
Configuration
Create a .env file in your project root:
OCTOPUS_API_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxx
OCTOPUS_ACCOUNT_NUMBER=A-XXXXXXXX
Or set environment variables directly:
export OCTOPUS_API_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxx
export OCTOPUS_ACCOUNT_NUMBER=A-XXXXXXXX
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
OCTOPUS_API_KEY |
Yes | - | Your Octopus Energy API key |
OCTOPUS_ACCOUNT_NUMBER |
Yes | - | Your account number (A-XXXXXXXX format) |
OCTOPUS_API_BASE_URL |
No | https://api.octopus.energy/v1 |
API base URL |
Quick Start
import asyncio
from octopy import Octopy
from octopy.config import get_settings
async def main():
# Load settings from environment variables or .env file
settings = get_settings()
# Use the client as an async context manager
async with Octopy(settings) as client:
# Get account information
account = await client.get_account()
print(f"Account Number: {account.number}")
# Get consumption data
property = account.properties[0]
meter_point = property.electricity_meter_points[0]
meter = meter_point.meters[0]
consumption = await client.get_consumption(
meter_point=meter_point.mpan,
serial_number=meter.serial_number,
fuel="electricity"
)
for interval in consumption.results[:5]:
print(f"{interval.interval_start}: {interval.consumption} kWh")
if __name__ == "__main__":
asyncio.run(main())
API Coverage
Account Management
get_account()- Get account details with properties and meter pointsget_grid_supply_point(postcode)- Get GSP region from postcode
Consumption Data
get_consumption()- Fetch electricity or gas consumption with filtering and grouping
Products & Tariffs
get_products()- List available products with filtersget_product(product_code)- Get detailed product information
Pricing
get_unit_rates()- Get electricity/gas unit rates with date filteringget_standing_charges()- Get daily standing charges for tariffs
All paginated endpoints support automatic pagination with auto_paginate=True (default).
Usage Examples
See the examples/ directory for complete working examples:
- fetch_account_info.py - Display account, properties, and meters
- fetch_consumption.py - Fetch consumption data with statistics
- compare_tariffs.py - Compare unit rates and standing charges across products
Data Models
All API responses are returned as fully typed Pydantic models:
Account- Account information with propertiesProperty- Property with address and meter pointsElectricityMeterPoint/GasMeterPoint- Meter point detailsMeter- Physical meter with serial numberAgreement- Tariff agreement with validity datesConsumptionInterval- Energy consumption for a time periodProduct/ProductDetail- Energy product informationUnitRate- Unit rate pricingStandingCharge- Daily standing chargeRegion- Grid Supply Point (GSP) region enum
License
This project is licensed under the MIT License - see LICENSE 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file octopy_energy_api-0.1.0.tar.gz.
File metadata
- Download URL: octopy_energy_api-0.1.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
241d9acd80e4fb8f699d509006f4134c2f2800f4e57da73f7dd06fb745fd5311
|
|
| MD5 |
1be3975e08f78feb71feb6f8bfd8e2ef
|
|
| BLAKE2b-256 |
3d55a4ce0e22c7aef180e6d534387bf8649bd9fb6a02d70e82a9275070ee1e27
|
File details
Details for the file octopy_energy_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: octopy_energy_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01939fa473b33ddb08d765c94033774fab3478c4666dabba39f1ffbd0721e745
|
|
| MD5 |
17c08c28871fe95dde0f4c185202a027
|
|
| BLAKE2b-256 |
da336746dd8d929ffb0ae0881615dacb58816c38abf62d47eee8c65d9943de47
|