Get started with python-esios and make your first query
This guide will help you make your first query to the ESIOS API using python-esios. We’ll fetch historical electricity price data and display it as a pandas DataFrame.
Let’s fetch PVPC electricity prices (indicator 600) for a specific date range:
from esios import ESIOSClientclient = ESIOSClient()# Get indicator data as DataFramehandle = client.indicators.get(600) # PVPC pricedf = handle.historical("2025-01-01", "2025-01-31")print(df.head())
This code:
Creates an ESIOSClient instance (automatically uses your configured token)
from esios import ESIOSClientclient = ESIOSClient()# Download archive type 1 for a date rangeclient.archives.download( archive_id=1, start="2025-01-01", end="2025-01-31", output_dir="./data")
Customize the client behavior with additional parameters:
from esios import ESIOSClientclient = ESIOSClient( token="YOUR_TOKEN", # Optional if using env var or config file timeout=30.0, # Request timeout in seconds (default: 30) cache=True, # Enable caching (default: True) cache_dir="./my_cache", # Custom cache directory cache_recent_ttl=48 # TTL for recent data in hours (default: 48))
The client automatically caches historical data to reduce API calls. Recent data (within cache_recent_ttl hours) is refreshed on each request, while older data is cached indefinitely.