Configuration¶
This page describes how to configure the ENTSO-E API Python library, including API key management and network settings.
Overview¶
The library uses a global configuration system that allows you to set common parameters once and reuse them across all API calls. This configuration includes:
- API Key (Security Token): Required for authentication with the ENTSO-E Transparency Platform
- API Endpoint URL: The base URL for the ENTSO-E API (configurable via
ENTSOE_ENDPOINT_URL) - Timeout: HTTP request timeout duration
- Retries: Number of retry attempts for failed requests
- Retry Delay Function: Function that determines wait time between retry attempts (supports exponential backoff)
- Log Level: Configurable logging level for controlling output verbosity
- Number of Workers: How many concurrent requests can be made
API Key Management¶
Using Environment Variables (Recommended)¶
The easiest way to set your API key is using an environment variable:
When the library is imported, it automatically checks for the ENTSOE_API environment variable:
The above is sufficient for most use cases.
Manual Configuration¶
You can also set the API key programmatically using the set_config() function:
import entsoe
# Set global configuration
entsoe.config.set_config(security_token="your-security-token-here")
API Key Priority
The library checks for API keys in this order:
1. Global configuration (entsoe.config.set_config())
2. Environment variable (ENTSOE_API)
All parameter classes use the global configuration - there is no per-request API key option.
API Endpoint Configuration¶
The library uses https://web-api.tp.entsoe.eu/api by default. You can customize this using the ENTSOE_ENDPOINT_URL environment variable:
Or programmatically:
References:¶
entsoe.config.set_config ¶
set_config(
security_token: Optional[str] = None,
endpoint_url: Optional[str] = None,
timeout: int = 5,
retries: int = 5,
retry_delay: Union[int, Callable[[int], int]] = lambda attempt: 2**attempt,
max_workers: int = 4,
log_level: LogLevel = "SUCCESS",
) -> None
Set the global configuration.
Parameters:
-
security_token(Optional[str], default:None) –API security token. If not provided, will try to get from ENTSOE_API environment variable.
-
endpoint_url(Optional[str], default:None) –API endpoint URL. If not provided, will try to get from ENTSOE_ENDPOINT_URL environment variable. If neither is available, defaults to "https://web-api.tp.entsoe.eu/api".
-
timeout(int, default:5) –Request timeout in seconds (default: 5)
-
retries(int, default:5) –Number of retry attempts for failed requests (default: 5)
-
retry_delay(Union[int, Callable[[int], int]], default:lambda attempt: 2 ** attempt) –Function that takes attempt number and returns delay in seconds, or integer for constant delay (default: exponential backoff 2**attempt)
-
max_workers(int, default:4) –Maximum number of parallel API calls when splitting large date ranges (default: 4)
-
log_level(LogLevel, default:'SUCCESS') –Log level for loguru logger. Available levels: TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL (default: SUCCESS)
entsoe.config.get_config ¶
Get the global configuration instance.
Returns:
-
EntsoEConfig–Global EntsoEConfig instance
Raises:
-
RuntimeError–If no global configuration has been set