A lightweight, high-performance weather API wrapper built with Flask, Redis caching, and rate limiting.
Designed for learning backend fundamentals including third-party APIs, caching strategies, and environment variables.
WeatherFlow is a Flask-based backend service that retrieves real-time weather data from the Visual Crossing Weather API and improves performance using Redis caching alongside Flask-Limiter-based rate limiting.
This project was developed as part of the roadmap.sh backend learning pathway:
- π Project Brief: https://roadmap.sh/projects/weather-api-wrapper-service
- π Weather API Provider: https://www.visualcrossing.com/account/
It demonstrates practical experience in:
- Integrating third-party APIs
- Implementing Redis-based caching (cache-aside pattern)
- Managing environment variables securely
- Protecting APIs using rate limiting
- Structuring a scalable Flask backend service
This project was developed with reference to architectural ideas from:
- Reference repository: https://github.com/alinakitieva/weather_api
- Additional guidance from roadmap.sh project documentation
Some debugging support and system improvements were assisted using AI tools to ensure reliability, correctness, and cleaner architecture design.
- π Live weather data from Visual Crossing API
- β‘ Redis caching to reduce redundant external API calls
- π Secure environment variable configuration
- π¦ Rate limiting (50 requests per hour per IP address)
- π§ Cache-aside architecture implementation
- π§ͺ Clean and minimal REST API design
Before running this project, ensure the following are installed:
- Python 3.8 or higher
- Redis server (running locally)
- A free Visual Crossing API key
This project requires a running Redis instance before the application starts.
sudo apt install redis-serverStart Redis:
redis-serverVerify Redis is running:
redis-cli pingExpected output:
PONG
This project uses the free Visual Crossing Weather API.
- Visit: https://www.visualcrossing.com/account/
- Sign up or log in
- Open your Account Dashboard
- Locate the API Key section
- Copy your unique key
- Paste it into your
.envfile
git clone https://github.com/alinakitieva/weather_api.git
cd weather_apipython3 -m venv venv
source venv/bin/activatepip install flask flask-limiter redis python-dotenv requestsA sample environment configuration is provided for convenience.
Create a .env file in the project root and populate it as follows:
API_KEY=your_api_key_here
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0Ensure Redis is running before starting the application.
You will need three terminal sessions:
redis-serverOption 1:
flask runOption 2:
python app.pyThe server will run at:
http://localhost:5000
curl "http://localhost:5000/weather?location=Manchester"GET /weather
curl "http://localhost:5000/weather?location=Manchester"curl "http://localhost:5000/weather?location=New York&datefrom=2026-06-01"The
quotefunction is used internally to URL-encode the location parameter, ensuring that spaces and special characters are handled correctly.
curl "http://localhost:5000/weather?location=Manchester&datefrom=2026-06-01&dateto=2026-06-10"The /weather endpoint receives query parameters:
locationdatefromdateto
The application first checks Redis using the full request URL as the cache key.
- If a cached response exists β it is returned immediately
- If not β the request proceeds to the external API
The system calls the Visual Crossing API and retrieves weather data in JSON format.
The response is stored in Redis with a TTL of:
43200 seconds (12 hours)
The final JSON response is returned to the client.
Main controller function:
- Checks Redis cache first
- Falls back to API if no cached data exists
- Returns the final response
- Retrieves cached data from Redis
- Returns a Python dictionary or
None
- Sends request to Visual Crossing API
- Parses JSON response
- Stores result in Redis cache
- Returns fresh data
- Stores API response in Redis
- Applies a TTL of 12 hours
Each client IP address is limited to:
50 requests per hour
This helps prevent abuse and protects external API usage limits.
weather_api/
β
βββ app.py
βββ services/
β βββ cached_data.py
βββ .env
βββ requirements.txt
βββ README.md
- Ensure Redis is running before starting the application
- Never expose your API key publicly
- Caching significantly reduces external API calls and improves performance
- Rate limiting protects against excessive usage
This project is licensed under the MIT Licence β see the LICENCE file for details.
MIT Licence
Copyright (c) 2026 Sheikh Hussain
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.