A simple and fun command-line tool to check the current weather for any city using the OpenWeatherMap API. Built with Python π.
$ python weather.py Nairobi
Weather in Nairobi:
π€ Clear sky
π‘οΈ Temperature: 25Β°C
π¨ Wind: 5.2 m/s
π§ Humidity: 58%
β’ Get current weather conditions for any city
β’ Uses OpenWeatherMap API for real-time data
β’ Easy to use, lightweight, and extensible
β’ Can be extended into a web API or app
Python 3.6+
requests library
OpenWeatherMap API key (free)
-
Clone the repo:
git clone https://github.com/your-username/weather-cli.git cd weather-cli -
Create a virtual environment (optional but recommended)
python -m venv venv # Activate it: source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows (CMD) venv\Scripts\Activate.ps1 # Windows (PowerShell)
-
Install dependencies
pip install requests
Or from requirements.txt:
pip install -r requirements.txt
-
Add your API key: Get a free API key from OpenWeatherMap, then open weather.py and replace:
API_KEY = "your_openweather_api_key"
with your actual API key (inside quotes).
To check the weather for any city:
python weather.py <city name>
Examples:
python weather.py Nairobi
python weather.py Tokyo
python weather.py "New York"
Check out the following repositoty for the web version: Weather-web-api
weather-cli/
β
βββ weather.py # Main CLI script
βββ requirements.txt # Dependencies
βββ .gitignore # Git ignored files
βββ README.md # This file
βββ venv/ # (optional) virtual environment
OpenWeatherMap for the weather data API