This project has two sets of requirements:
- Minimum requirements: Only what you need to run the app.
- Optional (development) requirements: For testing, code formatting, and linting. Recommended if you want to contribute or check code quality.
- Python 3.10 or later
- requests
- python-dotenv
Install with:
pip install -r requirements.txt
- pytest: Run tests
- pytest-mock: Mocking for tests
- pytest-cov: Test coverage reporting
- black: Code formatter (auto-formats Python code)
- flake8: Linter (checks code style and errors)
- mypy: Type checker (checks type hints)
- types-requests: Type stubs for requests (for mypy type checking)
Install with:
pip install -r requirements-dev.txt
If you only install the minimum requirements, you can run the app but not run tests, lint, or format code.
A simple Python command-line app that fetches and displays the current weather for any city using the OpenWeatherMap API. You run it from the terminal and get the city name, temperature (Celsius), and weather description.
git clone <repository-url>
cd python-weather-cli
This project uses a .env
file for the API key. You must set your OpenWeatherMap API key in this file.
- Sign up at OpenWeatherMap and get your API key.
- Copy the example file and add your key:
cp .env.example .env
# Edit .env and set your key:
# OPENWEATHERMAP_API_KEY=your_api_key_here
pip install -r requirements-dev.txt
pip install -r requirements.txt
Run the app from the project root:
python -m weather_cli.main "London"
python -m weather_cli.main "New York"
python -m weather_cli.main "Tokyo"
Or use the installed script:
weather "London"
weather "New York"
weather "Tokyo"
You can use any city name. The app will print the current weather for that city.
You can see all available options with:
python -m weather_cli.main --help
Or:
weather --help
Example output:
usage: weather-cli [-h] [--debug] city
Get current weather information for a city
positional arguments:
city Name of the city to get weather for
options:
-h, --help show this help message and exit
--debug Enable debug logging
python-weather-cli/
├── .env.example
├── README.md
├── requirements.txt
├── requirements-dev.txt
├── setup.py
├── pyproject.toml
├── src/
│ └── weather_cli/
│ ├── __init__.py
│ ├── main.py
│ ├── weather_service.py
│ ├── weather_client.py
│ ├── weather_data.py
│ ├── config_util.py
│ └── exceptions.py
├── tests/
└── docs/
- Run all tests:
pytest
- Run tests with coverage:
pytest --cov=src
- Format code with black:
black src tests
- Lint code with flake8:
flake8 src tests
- Type check with mypy:
mypy src
This project includes comprehensive unit tests covering all major components and functionality. The test suite ensures reliability, security, and proper error handling across the application.
Quick testing commands:
- Run all tests:
pytest
- Run with coverage:
pytest --cov=src
- Run specific test file:
pytest tests/test_weather_client.py
The testing approach includes:
- Unit testing with mocked dependencies for isolation
- Error handling testing for all failure scenarios
- Security testing to ensure API keys aren't exposed
- Input validation testing for edge cases and malicious input
- Integration testing of component interactions
For detailed information about what is tested and how, see tests/TESTING.md.
- This project uses black for formatting and flake8 for linting.
- The maximum line length is set to 100 characters for both tools.
- Target Python version: 3.10+
To check code style:
flake8 src tests
To auto-format code:
black src tests
To type check:
mypy src
For more details, see the code and comments in each file.