Configuration

aemetxfb uses a central configuration object to manage HTTP request timeouts and other runtime settings.

AEMetConfig

The AEMetConfig dataclass holds all runtime settings:

class AEMetConfig(http_timeout: float = 10.0, download_timeout: float = 60.0, cache_enabled: bool = False, cache_ttl: int = 86400, cache_dir: str = '.aemet_cache')

Frozen (immutable) dataclass for library configuration.

Parameters:
  • http_timeout – Timeout in seconds for lightweight HTTP probes (status checks, small requests). Default: 10.0.

  • download_timeout – Timeout in seconds for large file downloads (radar, satellite, tarballs). Default: 60.0.

  • cache_enabled – Enable/disable the disk cache. Default: False.

  • cache_ttl – Cache time-to-live in seconds. Default: 86400 (24 hours).

  • cache_dir – Directory for the SQLite cache database. Default: ".aemet_cache".

Example:

from aemetxfb import AEMetConfig

config = AEMetConfig()
print(config.http_timeout)       # 10.0
print(config.download_timeout)   # 60.0
print(config.cache_enabled)      # False

Accessing the current config

The CONFIG singleton holds the active configuration:

from aemetxfb import CONFIG

print(CONFIG.http_timeout)  # 10.0

Runtime configuration changes

Use set_config() to swap the global configuration at runtime:

from aemetxfb import AEMetConfig, CONFIG, set_config

# Save original
original = CONFIG

# Apply new config
set_config(AEMetConfig(http_timeout=5.0, download_timeout=30.0))
print(CONFIG.http_timeout)  # 5.0

# Restore original
set_config(original)

Note

AEMetConfig is frozen (immutable). set_config() replaces the module-level reference, so all subsequent calls use the new values. Always restore the original config if you need to revert changes.

Timeout strategy

The library uses two timeout tiers:

  • http_timeout (10s) — Used for lightweight requests: status probes, small HTML pages, JSON responses, and CSV data fetches.

  • download_timeout (60s) — Used for large file downloads: radar images, satellite imagery, tar.gz archives, and bulk data exports.

This distinction prevents slow network conditions from blocking quick status checks while still allowing large downloads to complete.

See also

Caching — Enable the optional disk cache for climate data.