A simple, elegant command-line interface for fetching real-time weather information from OpenWeatherMap API.
- 🌍 Get weather for any city worldwide
- 🌡️ Detailed weather information including temperature, humidity, wind speed, and more
- 🔧 Configurable temperature units (Celsius, Fahrenheit, Kelvin)
- 🔐 Secure API key management via environment variables
- ✨ Clean, modular Python code with type hints
- 🧪 Comprehensive error handling
- 📦 Easy installation and setup
- Python 3.7 or higher
- pip (Python package manager)
- An OpenWeatherMap API key (get one free here)
- Clone this repository:
git clone https://github.com/codeforgood-org/weather-cli.git
cd weather-cli- Install dependencies:
pip install -r requirements.txt- Set up your API key:
export OPENWEATHER_API_KEY='your_api_key_here'Or create a .env file:
echo "OPENWEATHER_API_KEY=your_api_key_here" > .envInstall as a package for system-wide access:
pip install -e .Get weather for a city:
python -m weather_cli.cli LondonOr if installed as a package:
weather-cli LondonFor cities with spaces in their names:
python -m weather_cli.cli New York
python -m weather_cli.cli San FranciscoChoose your preferred temperature unit:
# Celsius (default)
python -m weather_cli.cli Tokyo
# Fahrenheit
python -m weather_cli.cli Tokyo --units imperial
# Kelvin
python -m weather_cli.cli Tokyo --units standard# Get weather for Paris
$ python -m weather_cli.cli Paris
Weather in Paris, FR:
Description: Clear sky
Temperature: 18.5°C (feels like 17.8°C)
Humidity: 65%
Pressure: 1015 hPa
Wind Speed: 3.5 m/s
Cloudiness: 10%weather-cli/
├── weather_cli/ # Main package directory
│ ├── __init__.py # Package initialization
│ ├── cli.py # Command-line interface
│ ├── config.py # Configuration management
│ └── weather.py # Weather data fetching and processing
├── tests/ # Test directory
│ ├── __init__.py
│ ├── test_config.py
│ ├── test_weather.py
│ └── test_cli.py
├── .env.example # Example environment variables
├── .gitignore # Git ignore rules
├── LICENSE # MIT License
├── README.md # This file
├── requirements.txt # Production dependencies
├── requirements-dev.txt # Development dependencies
└── pyproject.toml # Project configuration
Install development dependencies:
pip install -r requirements-dev.txtRun tests:
pytestRun tests with coverage:
pytest --cov=weather_cli --cov-report=htmlThis project uses various tools to maintain code quality:
# Format code with black
black weather_cli tests
# Sort imports
isort weather_cli tests
# Lint with flake8
flake8 weather_cli tests
# Type checking with mypy
mypy weather_cliOPENWEATHER_API_KEY(required): Your OpenWeatherMap API keyWEATHER_UNITS(optional): Default temperature units (metric,imperial, orstandard)
- Visit OpenWeatherMap
- Sign up for a free account
- Navigate to API Keys section
- Generate a new API key
- Add it to your environment variables
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please make sure to update tests as appropriate and follow the code style guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Weather data provided by OpenWeatherMap
- Built with ❤️ by codeforgood-org
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue if your problem isn't already listed
- Provide as much detail as possible including error messages and your environment
Future enhancements planned:
- 5-day weather forecast
- Multiple city comparison
- Weather alerts and notifications
- Historical weather data
- Colorized terminal output
- JSON output format option
- Configuration file support
Made with Python 🐍