11---
22name : esios
33description : Query Spanish electricity market data (ESIOS/REE). Use when the user asks about electricity prices, generation, demand, I90 files, or any ESIOS indicator.
4- version : 2 .0.0
4+ version : 3 .0.0
55---
66
77# ESIOS Data Assistant
88
9- You have access to the ` python-esios ` CLI and library for querying the Spanish electricity market (ESIOS/REE).
9+ You have access to the ` python-esios ` library and CLI for querying the Spanish electricity market (ESIOS/REE).
1010
11- ## CLI Reference
11+ ## When to use what
1212
13- ### Indicators
14-
15- ``` bash
16- # List all indicators
17- esios indicators list
13+ - ** Python scripts** (default): reproducible, composable, saveable. Use for any data work the user will want to keep or iterate on.
14+ - ** CLI** : quick one-shot lookups, exploration, sanity checks. Use when the user wants a fast answer they won't need again.
15+ - ** If unsure** : ask the user whether they want a script or a quick CLI check.
1816
19- # Search by name
20- esios indicators search " precio"
17+ ## Python Library (default)
2118
22- # Show metadata (unit, granularity, geographies)
23- esios indicators meta 600
19+ ``` python
20+ from esios import ESIOSClient
2421
25- # Historical data
26- esios indicators history 600 --start 2025-01-01 --end 2025-01-31
27- esios indicators history 600 -s 2025-01-01 -e 2025-01-31 --format csv --output data.csv
28- esios indicators history 600 -s 2025-01-01 -e 2025-01-31 --format parquet --output data.parquet
22+ client = ESIOSClient() # reads config file, then ESIOS_API_KEY env var
2923
30- # Filter by geography (ID or name)
31- esios indicators history 600 -s 2025-01-01 -e 2025-01-31 --geo España
32- esios indicators history 600 -s 2025-01-01 -e 2025-01-31 --geo 3
24+ # --- Indicators ---
3325
34- # Ad-hoc pandas expressions on fetched data
35- esios indicators exec 600 -s 2025-01-01 -e 2025-01-31 --expr " df.describe()"
36- esios indicators exec 600 -s 2025-01-01 -e 2025-01-31 --expr " df.resample('D').mean()"
37- ```
26+ # Get indicator handle
27+ handle = client.indicators.get(600 )
3828
39- ### Archives
29+ # Historical data as DataFrame
30+ df = handle.historical(" 2025-01-01" , " 2025-01-31" )
4031
41- ``` bash
42- # List all available archives
43- esios archives list
32+ # Filter by geography
33+ df = handle.historical(" 2025-01-01" , " 2025-01-31" , geo_ids = [3 ]) # España only
4434
45- # Download archive files
46- esios archives download 34 --start 2025-05-01 --end 2025-05-31 --output ./data
47- esios archives download 34 --date 2025-06-01
35+ # Inspect geographies
36+ handle.geos # List of {"geo_id": int, "geo_name": str}
37+ handle.geos_dataframe() # DataFrame with geo_id and geo_name columns
38+ handle.resolve_geo(" España" ) # Returns 3
4839
49- # List sheets (table of contents) in an I90 file
50- esios archives sheets 34 --date 2025-06-01
40+ # Search indicators
41+ results = client.indicators.search( " precio " )
5142
52- # Parse and query archive data (like indicators exec but for archives)
53- esios archives exec 34 --sheet I90DIA03 --date 2025-06-01
54- esios archives exec 34 --sheet I90DIA03 --date 2025-06-01 -x " df.describe()"
55- esios archives exec 34 --sheet I90DIA03 -s 2025-05-05 -e 2025-06-08 \
56- -x " df[df['Sentido']=='Bajar'].groupby('Unidad de Programación')['value'].sum().sort_values()"
57- esios archives exec 34 --sheet I90DIA26 --date 2025-06-01 --format csv --output pbf.csv
58- ```
43+ # Compare multiple indicators
44+ df = client.indicators.compare([600 , 10034 , 10035 ], " 2025-01-01" , " 2025-01-07" )
5945
60- ### Cache Management
46+ # --- I90 Settlement Files ---
6147
62- ``` bash
63- esios cache status # Path, size, geos registry, catalog info
64- esios cache geos # Global geo_id → geo_name registry
65- esios cache path # Print cache directory
66- esios cache clear # Clear indicator cache
67- esios cache clear --all # Clear everything (indicators, archives, geos, catalog)
68- esios cache clear --indicator 600 # Clear one indicator
69- ```
48+ from esios.processing.i90 import I90Book
7049
71- ### Configuration
50+ archive = client.archives.get(34 )
51+ books = I90Book.from_archive(archive, start = " 2025-05-05" , end = " 2025-06-08" )
7252
73- ``` bash
74- esios config set token < API_KEY>
75- esios config show
53+ book = books[0 ]
54+ sheet = book[" I90DIA03" ]
55+ df = sheet.df # Preprocessed DataFrame with datetime index
56+ print (sheet.frequency) # "hourly" or "hourly-quarterly"
7657```
7758
78- ## Common Indicator IDs
59+ ### Common Indicator IDs
7960
8061| ID | Name | Description | Geos |
8162| ----| ------| -------------| ------|
@@ -86,24 +67,18 @@ esios config show
8667| 10035 | Generación solar FV | Real-time solar PV generation | ES |
8768| 1293 | Demanda prevista | Forecasted demand | ES |
8869
89- Use ` esios indicators search "query"` to find more. Use ` esios indicators meta <id> ` to see full metadata including geographies and units .
70+ Use ` client. indicators. search( "query") ` to find more.
9071
91- ## Multi-Geo Indicators
72+ ### Multi-Geo Indicators
9273
93- Some indicators (e.g. 600) return data for multiple countries. The output is pivoted so each geography becomes a column:
74+ Some indicators (e.g. 600) return data for multiple countries. Output is pivoted so each geography becomes a column:
9475
9576```
9677datetime España Portugal Francia Alemania Bélgica Países Bajos
97782025-01-01 00:00:00 63.50 63.50 72.10 58.20 58.20 58.20
98- 2025-01-01 01:00:00 55.80 55.80 60.30 48.90 48.90 48.90
99- ```
100-
101- Filter to specific geos with ` --geo ` :
102- ``` bash
103- esios indicators history 600 -s 2025-01-01 -e 2025-01-07 --geo España --geo Portugal
10479```
10580
106- ## Geography Reference
81+ ### Geography Reference
10782
10883| geo_id | geo_name |
10984| --------| ----------|
@@ -114,94 +89,94 @@ esios indicators history 600 -s 2025-01-01 -e 2025-01-07 --geo España --geo Por
11489| 8827 | Bélgica |
11590| 8828 | Países Bajos |
11691
117- The ` --geo ` flag accepts both IDs and names (case-insensitive substring match):
118- - ` --geo 3 ` or ` --geo España ` or ` --geo españa `
119- - ` --geo "Países Bajos" ` or ` --geo 8828 `
92+ ### I90 Key Sheets
12093
121- ## Python Library
94+ | Sheet | Description |
95+ | -------| -------------|
96+ | I90DIA03 | Restricciones en el Mercado Diario (curtailment) |
97+ | I90DIA08 | Restricciones en Tiempo Real |
98+ | I90DIA26 | Programa Base de Funcionamiento (PBF, generation program) |
99+ | I90DIA01 | Programa PVP |
100+ | I90DIA07 | Regulación Terciaria (mFRR) |
122101
123- ``` python
124- from esios import ESIOSClient
102+ ### Key conventions
125103
126- client = ESIOSClient() # reads config file, then ESIOS_API_KEY env var
104+ - All timestamps are in Europe/Madrid timezone
105+ - Date ranges > 3 weeks are auto-chunked into smaller API requests
106+ - Data older than 48h is considered final (won't be re-fetched)
107+ - Recent data (last 48h) is re-fetched on each request (electricity market corrections)
108+ - Cache is per-column sparse: fetching ` geo_ids=[3] ` only caches that column
109+ - Custom exceptions: ` ESIOSError ` , ` AuthenticationError ` , ` APIResponseError ` , ` NetworkError `
127110
128- # Get indicator handle
129- handle = client.indicators.get(600 )
111+ ## CLI Reference (quick lookups)
130112
131- # Historical data as DataFrame
132- df = handle.historical(" 2025-01-01" , " 2025-01-31" )
113+ ### Catalog (offline)
133114
134- # Filter by geo
135- df = handle.historical(" 2025-01-01" , " 2025-01-31" , geo_ids = [3 ]) # España only
115+ ``` bash
116+ esios catalog list indicators # List cataloged indicators
117+ esios catalog list indicators " precio" # Filter by name
118+ esios catalog list archives # List cataloged archives
119+ esios catalog show indicator 600 # Details for indicator
120+ esios catalog show archive 34 # Details for archive
121+ esios catalog refresh # Refresh from live API
122+ esios catalog refresh --dry-run # Preview changes
123+ ```
136124
137- # Inspect geographies
138- handle.geos # List of {"geo_id": int, "geo_name": str}
139- handle.geos_dataframe() # DataFrame with geo_id and geo_name columns
140- handle.resolve_geo(" España" ) # Returns 3
125+ ### Indicators
141126
142- # Search and compare
143- results = client.indicators.search(" precio" )
144- df = client.indicators.compare([600 , 10034 , 10035 ], " 2025-01-01" , " 2025-01-07" )
127+ ``` bash
128+ esios indicators list # List all indicators
129+ esios indicators search " precio" # Search by name
130+ esios indicators meta 600 # Show metadata
131+ esios indicators history 600 -s 2025-01-01 -e 2025-01-31
132+ esios indicators history 600 -s 2025-01-01 -e 2025-01-31 --geo España
133+ esios indicators history 600 -s 2025-01-01 -e 2025-01-31 --format csv --output data.csv
145134```
146135
147- ## I90 Settlement Files
148-
149- ### CLI (quickest path)
136+ ### Archives
150137
151138``` bash
152- # Discover available sheets
153- esios archives sheets 34 --date 2025-06-01
139+ esios archives list # List available archives
140+ esios archives download 34 -s 2025-05-01 -e 2025-05-31 --output ./data
141+ esios archives sheets 34 --date 2025-06-01 # List sheets in I90 file
142+ ```
154143
155- # Key I90DIA sheets:
156- # I90DIA03 — Restricciones en el Mercado Diario (curtailment)
157- # I90DIA08 — Restricciones en Tiempo Real
158- # I90DIA26 — Programa Base de Funcionamiento (PBF, generation program)
159- # I90DIA01 — Programa PVP
160- # I90DIA07 — Regulación Terciaria (mFRR)
144+ ### Exec (ad-hoc pandas)
161145
162- # Total curtailment by direction
163- esios archives exec 34 --sheet I90DIA03 --date 2025-06-01 \
164- -x " df.groupby('Sentido')['value'].sum()"
146+ ``` bash
147+ # Indicators
148+ esios indicators exec 600 -s 2025-01-01 -e 2025-01-31 -x " df.describe()"
149+ esios indicators exec 600 -s 2025-01-01 -e 2025-01-31 --geo España -x " df.resample('D').mean()"
150+ esios indicators exec 600 10034 -s 2025-01-01 -e 2025-01-31 -x " df.corr()"
165151
166- # Multi-day curtailment analysis
152+ # Archives (I90)
153+ esios archives exec 34 --sheet I90DIA03 --date 2025-06-01 -x " df.groupby('Sentido')['value'].sum()"
167154esios archives exec 34 --sheet I90DIA03 -s 2025-05-05 -e 2025-06-08 \
168- -x " df[df['Sentido']=='Bajar'].groupby('Unidad de Programación')['value'].sum().sort_values().head(20) "
155+ -x " df[df['Sentido']=='Bajar'].groupby('Unidad de Programación')['value'].sum().sort_values()"
169156```
170157
171- ### Python library
158+ ### Cache management
172159
173- ``` python
174- from esios import ESIOSClient
175- from esios.processing.i90 import I90Book
160+ ``` bash
161+ esios cache status # Path, size, registry info
162+ esios cache geos # Global geo_id → geo_name registry
163+ esios cache clear # Clear indicator cache
164+ esios cache clear --all # Clear everything
165+ esios cache clear --indicator 600 # Clear one indicator
166+ ```
176167
177- # Download + parse in one step
178- client = ESIOSClient()
179- archive = client.archives.get(34 )
180- books = I90Book.from_archive(archive, start = " 2025-05-05" , end = " 2025-06-08" )
168+ ### Output options
181169
182- # Access a sheet
183- book = books[0 ]
184- sheet = book[" I90DIA03" ]
185- df = sheet.df # Preprocessed DataFrame with datetime index
186- print (sheet.frequency) # "hourly" or "hourly-quarterly"
170+ ```
171+ --format table|csv|json|parquet (default: table)
172+ --output file.csv (write to file instead of stdout)
187173```
188174
189- ## Caching Behavior
190-
191- - Data is cached locally as parquet files (` ~/.cache/esios/ ` )
192- - Each indicator gets its own directory: ` indicators/{id}/data.parquet `
193- - Indicator metadata cached in ` indicators/{id}/meta.json ` (7-day TTL)
194- - Indicator catalog cached in ` indicators/catalog.json ` (24h TTL)
195- - Global geo registry at ` geos.json ` (persisted forever, grows incrementally)
196- - Data older than 48h is considered final (won't be re-fetched)
197- - Recent data (last 48h) is re-fetched on each request (electricity market corrections)
198- - Cache is per-column sparse: fetching ` --geo España ` only caches that column
175+ ## Configuration
199176
200- ## Key Conventions
177+ ``` bash
178+ esios config set token < API_KEY>
179+ esios config show
180+ ```
201181
202- - All timestamps are in Europe/Madrid timezone
203- - Date ranges > 3 weeks are auto-chunked into smaller API requests
204- - Archives support skip-existing (won't re-download cached files)
205- - I90 sheets detect hourly vs quarter-hourly frequency automatically
206- - API token resolution: config file (` ~/.config/esios/config.toml ` ) > ` ESIOS_API_KEY ` env var
207- - Custom exceptions: ` ESIOSError ` , ` AuthenticationError ` , ` APIResponseError ` , ` NetworkError `
182+ Config file: ` ~/.config/esios/config.toml ` . API key resolution: config file > ` ESIOS_API_KEY ` env var.
0 commit comments