This guide provides step-by-step instructions to create an API key on OpenWeather and integrate it into Airflow for weather data retrieval. Follow these steps to configure your API connection securely and effectively.
- Visit the OpenWeather website.
- Click Sign Up in the top-right corner of the homepage.
- Fill in the required details (username, email, and password) to register.
- Complete the registration process by confirming your email address via the verification link sent to your inbox.
- After verifying your email, log in to your OpenWeather account using your credentials.
-
Once logged in, locate the API section in the main navigation bar.
-
For this project, we are using the Current Weather API. Click on its documentation link to view details.
-
You will see the API call format:
https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API key}
-
Review the documentation for parameter details such as
lat
(latitude),lon
(longitude), andappid
(your API key).
- Go to your account dashboard and find the API Keys section (under My API Keys).
- Click Create Key and provide a descriptive name for your key (e.g.,
My Weather App
). - Copy the generated API key for later use.
- OpenWeather offers a free tier for basic usage, suitable for this project.
- Ensure that your API key is set up for the free plan.
- Review the pricing page to confirm the limits of the free plan (e.g., number of API calls per minute).
Before configuring the API connection, activate your Airflow virtual environment:
source ~/airflow_env/bin/activate
-
Log in to the Airflow UI at http://localhost:8080.
-
Navigate to Admin → Connections.
-
Click the plus (+) button to create a new connection.
-
Fill out the connection details as follows:
- Conn Id:
openweather_api_key
- Conn Type: HTTP
- Host:
https://api.openweathermap.org/data/2.5/weather
- Extra: Add the API key in JSON format:
{ "api_key": "YOUR_API_KEY" }
- Conn Id:
-
Click Save to store the connection securely in Airflow.
In this project, the DAG code references the connection created above using the Conn Id (openweather_api_key
). This ensures secure and seamless integration with the OpenWeather API.
- Keep your API key secure and avoid hardcoding it into your scripts.
- Monitor your API usage to ensure it stays within the tier limits.