.env file in the project root using python-dotenv. Two environment variables control the application’s behaviour: AEMET_API_KEY, which is required for all AEMET API calls, and SECRET_KEY, which secures Flask sessions. This page explains how to obtain your API key and configure both variables correctly.
Getting an AEMET API key
AEMET provides free API access to its public weather observation data through the OpenData portal. Follow these steps to get your key:1
Go to opendata.aemet.es
Open https://opendata.aemet.es in your browser. This is Spain’s official open meteorological data portal.
2
Register an account
Click Acceso con clave de API and then choose the option to register a new account. Fill in the required fields (name and email address) and submit the form.
3
Request your API key
After registration, AEMET will send your API key to the email address you provided. Copy the key — you will add it to your
.env file in the next step. API keys are free and have no expiration date, but they are rate-limited by AEMET’s usage policies.Environment variables
string
required
Your API key from opendata.aemet.es. This key is sent as an
api_key header on every request to the AEMET conventional observation endpoint. If this variable is missing when the application starts, WeatherAPIService raises a ValueError and the app will not serve weather data.string
default:"clave_secreta"
The Flask session secret. Used by Flask to cryptographically sign session cookies. Defaults to
clave_secreta if not set. You should set this to a long, random string in any environment where you handle real user sessions.Example .env file
Create this file in the root of your ClimApp project directory:load_dotenv() at the top of app.py, making them available through os.getenv.
ClimApp queries AEMET’s conventional observation endpoint to retrieve all active station readings:This URL is the
base_url defined in WeatherAPIService. AEMET returns a metadata response whose datos field contains a second URL with the actual observation records. ClimApp follows this two-step pattern automatically on every /api/clima request.