Small, dependency-light Python wrapper around WeatherAPI.com to fetch current weather by city.
Once you push this repo to GitHub, other people can install it directly:
python -m pip install "git+https://github.com/headzoo/weather-api-python.git"python -m pip install -e ".[dev]"Set your API key:
export WEATHERAPI_KEY="..."Call the function:
from weather_api_python.weather import WeatherAPI
client = WeatherAPI(api_key="test")
data = fetch_weather("Austin")
print(data["temp_f"], data["condition"])Network/API problems raise WeatherAPIError:
from weather_api_python.weather import WeatherAPIError, fetch_weather
try:
fetch_weather("Austin")
except WeatherAPIError as e:
print("Weather error:", e)To run the tests, you'll need pytest, which is included if you install the dev dependencies:
pytest -m pytest