Skip to content

Conversation

@JrtPec
Copy link
Contributor

@JrtPec JrtPec commented Mar 21, 2024

As proposed in #315.

This PR introduces a method that Prepares the day-ahead prices request, without sending it. This allows you to defer the handling of that request to another system.
Next, I have isolated the parsing of the pricing response, so it can also be used in a stand-alone way.

Here's an example of how you could use this to request data using aiohttp:

import aiohttp
import pandas as pd

from entsoe import EntsoePandasClient
from entsoe.mappings import lookup_area
from entsoe.parsers import parse_prices

from settings import api_key

client = EntsoePandasClient(api_key=api_key)

start = pd.Timestamp('2024-01-01', tz='Europe/Brussels')
end = pd.Timestamp('2024-01-02', tz='Europe/Brussels')
area = lookup_area('BE')

prepared_request = client.prepare_query_day_ahead_prices(country_code=area, start=start, end=end)

async with aiohttp.ClientSession() as session:
    response = await session._request(
        method='GET',
        str_or_url=prepared_request.url
    )
    response.raise_for_status()
    text = await response.text()

series = parse_prices(
    xml_text=text,
    tz=area.tz,
    resolution='60min',
    start=start,
    end=end
)

@JrtPec JrtPec requested a review from fboerman March 21, 2024 14:30
@JrtPec JrtPec changed the title Issue 315 Prepared Day-ahead prices request for use in Async Frameworks Mar 21, 2024
@fleimgruber
Copy link
Contributor

fleimgruber commented Apr 18, 2024

How much context does the parse_prices need from the user in this scenario and what parts could be inferred? I am looking at resolution='60min' specifically. Would having a matching client.parse_query_day_ahead_prices(xml_plus_metadata_from_async) be an option? That would again introduce more API surface, but might be better if some of the query functions require different contexts?

In any case, I would be happy to contribute tests for this, following along #131.

@fboerman
Copy link
Collaborator

fboerman commented Jun 1, 2024

interesting idea! thanks for the work. I have added a design question to discuss

@fleimgruber
Copy link
Contributor

@fboerman I could not find the design question mentioned in #316 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants