ESIOSClient class provides a synchronous interface to the ESIOS API with built-in caching, retry logic, and resource management.
Constructor
ESIOS API token. If not provided, reads from
ESIOS_API_KEY environment variable.Raises: ESIOSError if no token is provided or found in environment.Request timeout in seconds for all HTTP operations.
Base URL for the ESIOS API. Override for testing or alternative endpoints.
Enable local parquet-based caching of time-series data. Caching is safe for historical electricity data since it’s immutable once published.
Custom cache directory path. If not specified, uses
$XDG_CACHE_HOME/esios or ~/.cache/esios.TTL in hours for recent data. Data newer than this is refetched to ensure accuracy, since recent values may be updated by ESIOS.
Example
Properties
indicators
Manager for querying electricity market indicators. See Indicators for details.
archives
offer_indicators
Manager for querying offer indicator data. See Offer Indicators for details.
catalog
Offline YAML-based catalog for searching and exploring indicators and archives without API calls.
cache
Direct access to the cache store for advanced operations like clearing cache or checking status.
Methods
get()
API endpoint path (without leading slash). Example:
"indicators/600"Query parameters to include in the request.
JSON response parsed as a Python dictionary.
- Retries up to 3 times on
APIResponseErrorandNetworkError - Uses exponential backoff: 2s to 10s between retries
- Does not retry on
AuthenticationError(401/403)
AuthenticationError– Invalid API token (401/403), not retriedAPIResponseError– HTTP errors (4xx/5xx), retriedNetworkError– Connection failures or timeouts, retried
Example
download()
Absolute URL to download from. Handles 307 redirects to S3 presigned URLs automatically.
Raw file content as bytes.
AuthenticationError– 401/403 errorsAPIResponseError– HTTP errorsNetworkError– Connection failures
Example
close()
Example
Context Manager
ESIOSClient implements the context manager protocol for automatic resource cleanup.
Example
Error Handling
All client methods may raise the following exceptions:ESIOSError– Base exception for all ESIOS errorsAuthenticationError– Invalid or missing API token (not retried)APIResponseError– HTTP errors from the API (retried)NetworkError– Connection failures or timeouts (retried)
Example
Related
- AsyncESIOSClient – Async version for concurrent operations
- Indicators Manager – Query electricity market indicators
- Archives Manager – Download archive files
