Skip to main content

A Python package to fetch electricity prices from OTE-CR (Czech electricity market operator)

Project description

OTE-CR Price Fetcher

A Python package to fetch electricity prices from OTE-CR (Czech electricity market operator). This package provides an async interface to retrieve day-ahead electricity prices with automatic retry logic and proper error handling.

Installation

Using UV (Recommended)

UV is an extremely fast Python package installer. Install the package with:

uv add ote-cr-price-fetcher

Or add it to an existing project:

uv pip install ote-cr-price-fetcher

Using pip

pip install ote-cr-price-fetcher

Installing from Source

If you want to install from source for development:

Using UV:

git clone https://github.com/michaelkrasa/ote-cr-price-fetcher.git
cd ote-cr-price-fetcher
uv sync

Using pip:

git clone https://github.com/michaelkrasa/ote-cr-price-fetcher.git
cd ote-cr-price-fetcher
pip install -e .

Requirements

  • Python 3.10 or higher
  • httpx >= 0.25.0
  • backoff >= 2.2.0

Usage

Basic Usage

import asyncio
import datetime
from ote_cr_price_fetcher import PriceFetcher, PriceDataNotAvailableError

async def main():
    # Create a fetcher instance
    fetcher = PriceFetcher()
    
    # Fetch prices for today (15-minute intervals, default)
    try:
        prices = await fetcher.fetch_prices_for_date(datetime.date.today())
        print(f"Found {len(prices)} price points (15-minute intervals)")
        # Prices are in 15-minute intervals (96 values per day)
        for i, price in enumerate(prices):
            hour = i // 4  # Convert 15-min index to hour
            minute = (i % 4) * 15
            print(f"{hour:02d}:{minute:02d} - {price:.2f} EUR/kWh")
    except PriceDataNotAvailableError as e:
        print(f"Prices not available: {e}")
    
    # Fetch prices in hourly format
    try:
        hourly_prices = await fetcher.fetch_prices_for_date(datetime.date.today(), hourly=True)
        print(f"Found {len(hourly_prices)} hourly price points")
        for hour, price in enumerate(hourly_prices):
            print(f"{hour:02d}:00 - {price:.2f} EUR/kWh")
    except PriceDataNotAvailableError as e:
        print(f"Prices not available: {e}")

asyncio.run(main())

Configuration

You can customize the fetcher behavior by passing configuration parameters:

fetcher = PriceFetcher(
    price_url="https://custom-url.com/api?date=",  # Custom API URL
    timeout=15.0,                                  # Request timeout in seconds
    connect_timeout=90.0,                          # Connection timeout in seconds
    max_retry_time=180,                            # Max retry time in seconds
)

Error Handling

The package raises PriceDataNotAvailableError when price data is not yet available (e.g., for future dates or when prices haven't been published yet):

from ote_cr_price_fetcher import PriceDataNotAvailableError

try:
    prices = await fetcher.fetch_prices_for_date(datetime.date.today() + datetime.timedelta(days=1))
except PriceDataNotAvailableError as e:
    print(f"Prices not yet published: {e}")
    # Prices are typically available around 3 PM

API Reference

PriceFetcher

Initialize the PriceFetcher with optional configuration.

Parameters:

  • price_url (str, optional): Base URL for fetching prices. Defaults to OTE-CR URL.
  • timeout (float, optional): Request timeout in seconds. Defaults to 10.0.
  • connect_timeout (float, optional): Connection timeout in seconds. Defaults to 60.0.
  • max_retry_time (int, optional): Maximum time in seconds for retry attempts. Defaults to 120.

fetch_prices_for_date(date: datetime.date, hourly: bool = False) -> list[float]

Fetch electricity prices for a specific date.

Parameters:

  • date (datetime.date): The date to fetch prices for.
  • hourly (bool): If True, return hourly averages (24 values). If False, return 15-minute intervals (96 values). Defaults to False.

Returns:

  • list[float]: A list of electricity prices. 96 values for 15-minute intervals, 24 for hourly averages.

Raises:

  • PriceDataNotAvailableError: If price data is not yet available for the date.
  • httpx.RequestError: If the HTTP request fails.
  • httpx.HTTPStatusError: If the HTTP response indicates an error.

PriceDataNotAvailableError

Exception raised when price data is not yet available for the requested date.

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

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

ote_cr_price_fetcher-0.1.0.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

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

ote_cr_price_fetcher-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file ote_cr_price_fetcher-0.1.0.tar.gz.

File metadata

  • Download URL: ote_cr_price_fetcher-0.1.0.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for ote_cr_price_fetcher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f25cfb31e0b76a6e1e4e5e7f2b702bbec9fac338b4419590d9521b4a8a9fa13
MD5 beae53c7e61b814b4dd33090dd94bc48
BLAKE2b-256 982a455a0e92fb44c75f8fda1c85e9d6299817538479fa5f3f0657ae42432ecb

See more details on using hashes here.

File details

Details for the file ote_cr_price_fetcher-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ote_cr_price_fetcher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db44667ff88d98215ce39b2d732a523d266e6ce2aa0dd74f8343ce9412f8a8d5
MD5 8620eb64bdb8ff81f250b88b3ffb3bf0
BLAKE2b-256 118a66a5beb2562370eccebf3669ae8ded635ea204e4e78dba7aa465d38fd1fb

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