Skip to content

In this project, I built a simple Weather API that fetches real-time weather data from a third-party source (OpenWeatherMap). Through this project, I explored how to integrate external APIs, implement caching with Redis, and securely manage environment variables for API keys.

License

Notifications You must be signed in to change notification settings

Simply-Blessing/Weather-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌦 Weather API

A simple Flask-based Weather API that fetches live weather data from the OpenWeatherMap API, caches results with Redis, and applies rate limiting to prevent abuse.


🧰 Features

  • 🌍 Get current weather by city name
  • ⚡ Caching with Redis (12-hour expiry)
  • 🚦 Rate limiting using Flask-Limiter
  • 😎 Weather condition emojis for easy reading
  • 🔐 Secure API key loading via .env

🏗️ Tech Stack

  • Flask — lightweight web framework
  • Redis — in-memory cache for API responses
  • Flask-Limiter — request rate limiting
  • Requests — for external API calls
  • python-dotenv — load environment variables
  • OpenWeatherMap API — weather data source

📦 Installation

1️⃣ Clone the repository

git clone https://github.com/yourusername/weather-api.git
cd weather-api

2️⃣ Create and activate a Conda environment

conda create -n weatherapi python=3.11 -y
conda activate weatherapi

3️⃣ Install dependencies

pip install flask flask-limiter requests redis python-dotenv

4️⃣ Install Redis (if you are using Anaconda Powershell and windows) check out this installation guide: https://medium.com/@baertschi91/redis-installation-guide-for-windows-67ca177e2836

conda install -c binstar redis-server
conda install -c anaconda redis-py

5️⃣ Run Redis on a powershell prompt in your conda environment

redis-server

6️⃣ On another powershell prompt you connect Redis using this

redis-cli ping

🚀 Run the App

Sign in at OpenWeatherMap to get your free API key.

# .env
API_KEY=your_openweathermap_api_key

Running it on the command line or powershell

python app.py

By default, the app runs at:

http://127.0.0.1:5000

🌤 Usage

Get current weather

http://127.0.0.1:5000/weather?city=<city_name>
http://127.0.0.1:5000/weather?city=london

Response:

{
  "city": "london",
  "temperature": "17°C",
  "emoji": "",
  "description": "scattered clouds"
}

🧠 How It Works

  • The user sends a request like /weather?city=london.
  • The app first checks Redis cache using the key weather:london.
  • If data exists → it’s served instantly from cache.
  • If not → it fetches from OpenWeatherMap, parses, stores it in Redis (12-hour TTL), and returns JSON.

Project Inspiration

Weather API Wrapper Service

Weather APP from Bro code

About

In this project, I built a simple Weather API that fetches real-time weather data from a third-party source (OpenWeatherMap). Through this project, I explored how to integrate external APIs, implement caching with Redis, and securely manage environment variables for API keys.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages