ArchivesManager provides access to ZIP and XLS archive files with intelligent caching and automatic date-range iteration.
ArchivesManager
Access viaclient.archives.
list(*, source=“local”)
List all available archives as a DataFrame.Data source:
"local"— Returns full static catalog (153 archives including I90, settlements, etc.)"api"— Queries ESIOS API (returns only ~24 archives)
pd.DataFrame with columns:
id(index)name— Archive namehorizon— Time granularity ("D"for daily,"M"for monthly)archive_type— File format ("zip"or"xls")- Additional metadata fields
get(archive_id)
Get a specific archive by ID and return a handle for downloading.Unique archive identifier
ArchiveHandle instance with metadata and download methods.
download(archive_id, **kwargs)
Convenience method combiningget() and download() in one call.
Archive identifier
Single date (YYYY-MM-DD format) — mutually exclusive with
start/endStart date (YYYY-MM-DD) — requires
endEnd date (YYYY-MM-DD) — requires
startDirectory to copy files to (in addition to cache)
Date interpretation:
"datos" (data date) or "publicacion" (publication date)list[Path] — Sorted list of downloaded file paths.
ArchiveHandle
Returned byArchivesManager.get(). Provides metadata access and download functionality for a specific archive.
Attributes
Archive ID
Archive name (updated after
configure() or download())Raw API metadata including horizon, archive_type, etc.
Parsed archive model
configure(**kwargs)
Configure archive parameters and resolve the download URL.Single date (YYYY-MM-DD) — mutually exclusive with
start/endStart date (YYYY-MM-DD) — requires
endEnd date (YYYY-MM-DD) — requires
startDate interpretation:
"datos" or "publicacion"Response language (
"es" or "en")- Updates
handle.metadatawith API response - Updates
handle.namewith resolved filename - Sets internal
_download_urlfor subsequent download
ValueError if neither date nor both start/end are provided.
download(**kwargs)
Download archive files for a single date or date range.Single date (YYYY-MM-DD) — mutually exclusive with
start/endStart date (YYYY-MM-DD) — requires
endEnd date (YYYY-MM-DD) — requires
startDirectory to copy extracted files to (in addition to cache)
Date interpretation:
"datos" or "publicacion"list[Path] — Sorted list of file paths in cache directory.
Features:
- Automatically iterates over date ranges based on archive horizon:
- Daily archives (
horizon="D"): One request per day - Monthly archives (
horizon="M"): One request per month
- Daily archives (
- Skips dates already present in cache
- Extracts ZIP files or writes XLS files directly
- Optionally copies files to
output_dirwhile keeping cache copy - Handles API errors gracefully (logs warning and continues)
datekey is:
YYYYMMDDfor daily archivesYYYYMMfor monthly archives
ValueError if neither date nor both start/end are provided.
