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.

Testing

To run all tests:

uv run python tests/run_tests.py

This will run both the PriceFetcher integration tests and the PriceUtils unit tests.

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.1.tar.gz (36.3 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.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ote_cr_price_fetcher-0.1.1.tar.gz
  • Upload date:
  • Size: 36.3 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.1.tar.gz
Algorithm Hash digest
SHA256 92af3eb7baf3667e63d82108df8b0f3711e778f32039b9e377beb322e57e5336
MD5 7b4f2aa1d58fcfc84c6e680e126d8363
BLAKE2b-256 f339efa82624ac548d5092c5c0b4b21e6f766678c72055acf5ba823b73899e5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ote_cr_price_fetcher-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af2ae37802189556c23e42ef0788d55881c95b8a57e7cb33c25b1b3122dd6e16
MD5 22776abf3ce15e946a686ac8c3778962
BLAKE2b-256 3ea67aa43a03c61a46e504438b1b48afd4d7250d8f458239ef87a4d88c0569a7

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