OpenWeatherWrap is an unofficial wrapper for the OpenWeatherMap API written in Python.
It includes classes for most of the free API endpoints, including OneCall API, Five-Day Forecast, Geocoding and more.
OpenWeatherWrap is designed to abstract the usage of the api using clases for each endpoint and methods to make each request easier.
It is designed to be easy to use and understand, while still providing all the functionality of the OpenWeatherMap API.
OpenWeatherWrap is open source and available on PyPI and GitHub.
from openweatherwrap.api import OneCallAPI
# Create an instance of the API
api = OneCallAPI(API_KEY, "London, England", units="metric")
# Get only the current weather
response = api.get_weather(exclude=["minutely", "hourly", "daily", "alerts"])
#Access the data
print(f"The temperature is {response.get_current_temp()}°C.")
print(f"And it feels like {response.get_current_feels_like()}°C")
This is a quick example on how to use the wrapper.
Notice how in this example, we use the city name, while the API requires coordinates. The wrapper converts those for you!
from openweatherwrap.asyncapi import OneCallAPI
import asyncio
async def onecall_example():
# Create an instance of the API
api = OneCallAPI(API_KEY, "London, England", units="metric")
# Get only the current weather
response = await api.get_weather(exclude=["minutely", "hourly", "daily", "alerts"])
#Access the data
print(f"The temperature is {response.get_current_temp()}°C.")
print(f"And it feels like {response.get_current_feels_like()}°C")
if __name__ == "__main__":
asyncio.run(onecall_example())
OpenWeatherWrap also includes capabilities for asynchronous programming.
The responses from the methods equal those of the synchronous wrapper, so the usage is nearly identical.
You can read more about how to use OpenWeatherWrap in the documentation