A polished Python CLI for fetching live weather and multi-day forecasts in your terminal, with on-disk response caching.
Project description
Weather CLI
A terminal weather tool — give it a city, get current conditions + a multi-day forecast in pretty colours.
A small but polished command-line tool built in Python that fetches live weather data from the OpenWeather API and renders it in the terminal with rich. Includes on-disk response caching so repeated calls don't hit the API.
Demo
Record a 10-second GIF of running the command and replace the line below.
Features
- 🌡️ Current weather — temperature, feels-like, humidity, wind for any city worldwide
- 📅 Multi-day forecast — up to 5 days of highs/lows + conditions
- 💾 On-disk caching — responses cached for 10 minutes in
~/.weather_cache.jsonto avoid hammering the API - ❌ Graceful errors — clean messages for unknown cities, bad API keys, and network failures
- 🎨 Pretty output — colour-coded panels and tables via
rich
Tech Stack
| Layer | Technology |
|---|---|
| Language | Python 3.10+ |
| HTTP | requests |
| Pretty terminal output | rich |
| Environment | python-dotenv |
| Weather data | OpenWeather API (free tier) |
Setup
1. Clone
git clone https://github.com/narasimharao2743/weather-cli.git
cd weather-cli
2. Virtual environment + dependencies
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate
pip install -r requirements.txt
3. Get a free OpenWeather API key
- Sign up at openweathermap.org/users/sign_up
- Copy your API key from the API keys tab
- New keys can take up to 2 hours to activate.
4. Create a .env file
cp .env.example .env
# then edit .env and paste your key
OPENWEATHER_API_KEY=your_api_key_here
Usage
# Current weather
python weather.py Bangalore
# Multi-word city
python weather.py "New York"
# Add a 3-day forecast
python weather.py Bangalore --days 3
# Up to 5-day forecast
python weather.py Mumbai -d 5
--help
usage: weather [-h] [-d {0,1,2,3,4,5}] city [city ...]
Get current weather and forecast for any city.
positional arguments:
city City name (e.g. "Bangalore" or "New York")
options:
-h, --help show this help message and exit
-d {0,1,2,3,4,5}, --days {0,1,2,3,4,5}
Show an N-day forecast in addition to current weather (0-5, default: 0)
How It Works
- CLI parsing —
argparseturns terminal arguments into a city + days value - API client (
api_client.py) — wraps the OpenWeather REST endpoints (/weatherand/forecast), reads the API key from.env, handles HTTP errors with custom exceptions - Caching — every successful response is written to
~/.weather_cache.jsonwith a timestamp. Repeat queries within 10 minutes return the cached copy instead of calling the API again - Formatter (
formatter.py) — usesrich.Panelfor the current-weather card andrich.Tablefor the forecast grid
Project Structure
weather-cli/
├── weather.py # CLI entry point (argparse + orchestration)
├── api_client.py # OpenWeather API wrapper + caching
├── formatter.py # Pretty terminal output via rich
├── requirements.txt # Python dependencies
├── .env.example # Template for your API key
├── .env # Your real key (gitignored)
├── .gitignore
└── README.md
Engineering Decisions
| Decision | Choice | Why |
|---|---|---|
| Cache TTL | 10 minutes | Weather doesn't change minute-to-minute, but a stale forecast > 10 min old feels wrong |
| Cache location | ~/.weather_cache.json (home dir, not repo) |
Same machine, multiple project checkouts share the cache; doesn't leak into git |
| Custom exceptions | CityNotFoundError, WeatherAPIError |
Lets weather.py distinguish "user typo" (exit 1) from "API down" (exit 2) for shell scripts |
units=metric hardcoded |
Yes | Simpler. Adding --units later is a one-line tweak |
| Forecast aggregation | Group 3-hourly entries by date, show min/max + mid-day conditions | OpenWeather free tier doesn't provide a daily summary endpoint, so we synthesise it from the 5-day/3-hour data |
Roadmap
-
--units imperial|metricflag - Bulk mode:
weather Bangalore Mumbai Delhiin one table - Config file at
~/.weather.yamlwith a default city - Package and publish to PyPI as
pip install rao-weather -
--alert "rain"flag with exit code 1 if rain in forecast (useful in cron jobs)
Author
Narasimharao Bhavirisetty — Python backend & GenAI engineer.
- 🌐 Portfolio: narasimharao2743.github.io
- 💼 LinkedIn: linkedin.com/in/narasimharao-bhavirisetty-0526891b0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weather_enquire-0.1.0.tar.gz.
File metadata
- Download URL: weather_enquire-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d2c91f8812b167f6e6b731507729b8a7425e818348d3b22f853078c382b38bc
|
|
| MD5 |
e20245b95dcbf36f15cb8dd231107194
|
|
| BLAKE2b-256 |
72b7daf8e0bd6c2bf8ec6e36f3f28f16ed8b7f43d382f2781a575c592c65a95a
|
File details
Details for the file weather_enquire-0.1.0-py3-none-any.whl.
File metadata
- Download URL: weather_enquire-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ba11914a66bc19f500da00fa3e3e0586d155ed04904a18faa5e35d1710cbc87
|
|
| MD5 |
84525080603f6b109c43d624c8a146e8
|
|
| BLAKE2b-256 |
d00a39b9472ab0b31c78c9df7bbf9cefc535e032b6d5297704c49fe4d47b00d8
|