This library aims to be a thin, transparent wrapper around OpenWeatherMap current weather, forecasts and geocoding APIs for Python programmers.
It avoids imposing additional constraints or defaults beyond those defined by OWM itself. Parameters are passed through as-is most of the time, and validation is delegated to the upstream service.
JSON responses are returned as parsed Python objects (dict or list),
depending on the upstream API.
import owmlib
api_key = "YOUR_API_KEY"
coordinates = owmlib.geo_direct("London", api_key)[0] # First match
latitude = coordinates["lat"]
longitude = coordinates["lon"]
data = owmlib.weather(latitude, longitude, api_key, units="metric")
print(data["weather"]["description"])
print(data["main"]["temp"])- Python 3.9+
pip install git+https://github.com/helanabi/owmlib.git
- Current weather
- 3-hour forecast for 5 days
- Geocoding
lat: latitudelon: longitudeappid: OWM account API keymode:xml|html-- Response format (JSON by default)units:standard|metric|imperial-- Units of measurement (default:standard)lang: two-letter output language code (e.g.arfor Arabic)cnt: number of timestamps in the API responsecity: city namestate: state code for US citiescountry: ISO 3166 country codelimit: the number of matching locations (max: 5)zip_code: zip/post code
Access current weather data for any location
mode,units,lang
5-day forecast for any location with 3-hour step in JSON or XML format.
mode,units,lang,cnt
forecast()does not supporthtmlmode
Convert the specified location name to geographical coordinates
Get coordinates by zip/post code
Convert geographical coordinates to location names
- Missing parameters in API responses means that the corresponding weather phenomena did not occur at the time of measurement.
- More information about accepted values, value interpretation and API response fields can be found in the respective API documentation pages linked below.
This is not an official OWM software. Documentation was adapted from openweathermap.org.
This project is licensed under the MIT license.