A Python API for retrieving Octopus Energy data
Project description
Octopus Energy
A Python API for retrieving Octopus Energy data.
See https://developer.octopus.energy/docs/api/ for more details of the Octopus API.
Installation
pip install octopus-energy-client
Features
- Retrieve information about electricity and gas meters.
- Retrieve tariff data, including half-hourly rates for the octopus agile electricity plan.
- Retrieve consumption data from electricity and gas meters, including up to half-hourly intervals.
Examples
import math
from octopus_energy_client import OctopusEnergy, ResourceType, ChargeType, Aggregate
# Account API Key, Serials, MPAN/MPRN and Product Codes can be found at https://octopus.energy/dashboard/developer/
octopus_client = OctopusEnergy(
api_key={octopus_api_key},
electricity_serial={octopus_electricity_serial},
electricity_mpan={octopus_electricity_mpan},
electricity_product_code={octopus_electricity_product_code},
electricity_region={octopus_electricity_region},
gas_serial={octopus_gas_serial},
gas_mprn={octopus_gas_mprn},
gas_product_code={octopus_gas_product_code},
gas_region={octopus_gas_region},
)
##############
# Meter Data #
##############
electricity_meter_info = octopus_client.get_meter_point(ResourceType.ELECTRICITY)
# {'gsp': '_C', 'mpan': '0123456789012', 'profile_class': 1}
grid_supply_points = octopus_client.get_grid_supply_points("SW1A 1AA")
# {'count': 1, 'next': None, 'previous': None, 'results': [{'group_id': '_C'}]}
###############
# Tariff Data #
###############
gas_standard_rates = octopus_client.get_tariff_data(ResourceType.GAS, ChargeType.STANDARD_UNIT_RATES)
gas_standing_charges = octopus_client.get_tariff_data(ResourceType.GAS, ChargeType.STANDING_CHARGES)
electricity_standing_charges = octopus_client.get_tariff_data(ResourceType.ELECTRICITY, ChargeType.STANDING_CHARGES)
# {'count': 1, 'next': None, 'previous': None, 'results': [{'value_exc_vat': 20.0, 'value_inc_vat': 21.0, 'valid_from': '2017-01-01T00:00:00Z', 'valid_to': None}]}
electricity_day_rates = octopus_client.get_tariff_data(ResourceType.ELECTRICITY, ChargeType.DAY_UNIT_RATES)
# {'detail': 'This tariff has standard rates, not day and night.'}
electricity_night_rates = octopus_client.get_tariff_data(ResourceType.ELECTRICITY, ChargeType.NIGHT_UNIT_RATES)
# {'detail': 'This tariff has standard rates, not day and night.'}
# Paginated results for a month of half-hourly electricity tariff data
page_size = 100
tariff_data = octopus_client.get_tariff_data(
ResourceType.ELECTRICITY,
ChargeType.STANDARD_UNIT_RATES,
period_from=datetime.datetime(2020, 1, 1, tzinfo=pytz.utc),
period_to=datetime.datetime(2020, 1, 31, tzinfo=pytz.utc),
page_size=page_size,
)
result_count = tariff_data['count']
pages = math.ceil(result_count / page_size)
for page in range(2, pages+1):
tariff_data = octopus_client.get_tariff_data(
ResourceType.ELECTRICITY,
ChargeType.STANDARD_UNIT_RATES,
period_from=datetime.datetime(2020, 1, 1, tzinfo=pytz.utc),
period_to=datetime.datetime(2020, 1, 31, tzinfo=pytz.utc),
page_size=100,
page=page
))
####################
# Consumption Data #
####################
electricity_consumption = octopus_client.get_consumption_for_date(ResourceType.ELECTRICITY, datetime.date(2022,1,1))
gas_consumption = octopus_client.get_consumption_for_date(ResourceType.GAS, datetime.date(2022,1,1))
consumption = octopus_client.get_consumption_for_period(
ResourceType.ELECTRICITY,
period_from=datetime.datetime(2022, 1, 1, tzinfo=pytz.utc),
period_to=datetime.datetime(2022, 1, 14, tzinfo=pytz.utc),
group_by=Aggregate.DAILY
)
consumption = octopus_client.get_consumption_for_period(
ResourceType.GAS,
period_from=datetime.datetime(2022, 1, 1, tzinfo=pytz.utc),
period_to=datetime.datetime(2022, 1, 14, tzinfo=pytz.utc),
group_by=Aggregate.DAILY
)
# Paginated results for 2 weeks of half-hourly gas consumption
consumption = octopus_client.get_consumption_for_period(
ResourceType.GAS,
period_from=datetime.datetime(2022, 1, 1, tzinfo=pytz.utc),
period_to=datetime.datetime(2022, 1, 14, tzinfo=pytz.utc),
page_size=100
)
while consumption.get('next'):
url = consumption.get('next')
consumption = octopus_client.get_data(consumption.get('next'))
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file octopus-energy-client-0.0.12.tar.gz
.
File metadata
- Download URL: octopus-energy-client-0.0.12.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c59cd78ca8f89c523f6e07d53b99c123b305a27a66bb848d0abb03888b15f3d |
|
MD5 | 7a10a5bce116645a381fac7a79619596 |
|
BLAKE2b-256 | 76561c61751719fa623167c6a7e1ccec420055c055ee0cd511fcd93a69be13ed |
File details
Details for the file octopus_energy_client-0.0.12-py3-none-any.whl
.
File metadata
- Download URL: octopus_energy_client-0.0.12-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b68e9faaf2f4a0d57e7fd6001d8602a28d4468216aabf592503c270b176123d |
|
MD5 | 4da24ab4a8bd9f768465c9070cd46791 |
|
BLAKE2b-256 | 3b5ffee7f6792c3689a93ba38299e2716ca08fbf891127ec1917ef51dcab00da |