A simple and professional Weather API Wrapper built with FastAPI, SQLite, and httpx. This project fetches weather data from the free Open-Meteo API and stores query history locally.
- Fetch current weather by city π
- Fetch current weather by GPS coordinates π
- Fetch 5-day forecast for a city π
- Store weather history in SQLite ποΈ
- Retrieve all history records π
- Delete history records β
- List all unique cities queried ποΈ
- FastAPI β Web framework
- httpx β Async HTTP client for API calls
- SQLite + SQLAlchemy β Database & ORM
- Pydantic β Data validation
# Clone repo git clone https://github.com/your-username/weather-api-wrapper.git cd weather-api-wrapper # Create virtual environment python -m venv venv source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows # Install dependencies pip install -r requirements.txt # Run server uvicorn main:app --reloadGET /pingβ Response:
{ "message": "pong" }GET /weather/{city}β Example:
GET /weather/LagosResponse:
{ "id": 1, "city": "Lagos", "temperature": 29.5, "description": "Partly cloudy", "timestamp": "2025-09-05T17:50:23" }GET /weather/coordinates?lat={lat}&lon={lon}β Example:
GET /weather/coordinates?lat=6.5244&lon=3.3792Response:
{ "id": 2, "city": "(6.5244,3.3792)", "temperature": 29.0, "description": "Clear sky", "timestamp": "2025-09-05T17:55:42" }GET /forecast/{city}?days=5β Example:
GET /forecast/London?days=5Response:
{ "city": "London", "daily": { "temperature_2m_max": [23.5, 22.1, 21.7, 24.0, 25.3], "temperature_2m_min": [15.2, 14.8, 14.5, 15.0, 16.3] } }GET /historyβ Response:
[ { "id": 1, "city": "Lagos", "temperature": 29.5, "description": "Partly cloudy", "timestamp": "2025-09-05T17:50:23" }, { "id": 2, "city": "(6.5244,3.3792)", "temperature": 29.0, "description": "Clear sky", "timestamp": "2025-09-05T17:55:42" } ]DELETE /history/{id}β Example:
DELETE /history/2Response:
{ "message": "Record 2 deleted" }GET /citiesβ Response:
{ "cities": ["Lagos", "London", "(6.5244,3.3792)"] }-
Import the endpoints above into Postman
-
Start the server with:
uvicorn main:app --reload
-
Test endpoints like:
http://127.0.0.1:8000/weather/Lagoshttp://127.0.0.1:8000/forecast/London?days=3
- Add caching with Redis for faster repeated lookups
- Add user authentication with JWT tokens
- Build a React frontend for visualizing weather
MIT License. Free to use and modify.
Ipaye Babatunde
- π Lagos, Nigeria
- π§ b.tunde.ipaye@gmail.com
- π LinkedIn
- π» GitHub