A wrapper for the Openweathermap API
Project description
OpenWeatherWrap
OpenWeatherWrap is an unofficial wrapper for the OpenWeatherMap API.
Endpoints included in the wrapper
- One Call API 3.0
- Current Weather API
- 3-hour Forecast 5 days
- Air Pollution API
- Geocoding API
- Weather Maps 1.0
Getting Started
To install this package run
pip install openweatherwrap
To start fetching weather data, make sure you have an API-key from OpenWeatherMap.
Examples
One Call API
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 current temperature in London is {response.get_current_temp()}°C.")
print(f"The temperature feels like {response.get_current_feels_like()}°C")
Current Weather API
from openweatherwrap.api import CurrentWeatherAPI
# Create an instance of the API
api = CurrentWeatherAPI(API_KEY, "London, England", units='imperial')
# Getting the data
response = api.get_weather()
print(f"The current wind speed in London is {response.get_wind_speed()} miles per hour.")
5-Day/3-Hour Forecast
from openweatherwrap.api import FiveDayForecast
# Create an instance of the API
api = FiveDayForecast(API_KEY, "London, England", mode='xml')
# Getting the forecast
response = api.get_forecast()
temperature_sorted = sorted(response.get_temperature())
print(f"During the following five days, London will experience temperatures from {temperature_sorted[0]} Kelvin to {temperature_sorted[-1]} Kelvin")
Air Pollution API
from openweatherwrap.api import AirPollutionAPI
# Create an instance of the API
api = AirPollutionAPI(API_KEY, "London, England")
# Getting the current air pollution
response = api.get_current_air_pollution()
print(f"London currently has an AQI of {response.get_aqi()} and has {response.get_nitrogen_dioxide()}µg/m³ of NO₂.")
Geocoding API
from openweatherwrap.api import GeocodingAPI
# Create an instance of the API
api = GeocodingAPI(API_KEY)
# Getting the data
response = api.get_by_city("London", "England")
print(f"London has a latitude of {response.get_latitude()}° and a longitude of {response.get_longitude()}°")
Async
OpenWeatherWrap also includes asynchronous handling of the OpenWeatherMap API.
The usage is almost the same as the synchronous handler.
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 current temperature in London is {response.get_current_temp()}°C.")
print(f"The temperature feels like {response.get_current_feels_like()}°C")
if __name__ == "__main__":
asyncio.run(onecall_example())
Attribution
Weather data provided by OpenWeather
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openweatherwrap-1.0.0.tar.gz.
File metadata
- Download URL: openweatherwrap-1.0.0.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f247dfd711e9e616875e381d0ea0074f59ee5746ac6e61032140034dc362373
|
|
| MD5 |
d3c79713be7104e150410eadcb65c2a6
|
|
| BLAKE2b-256 |
06b26b55e7f7f17e48a2ee00ff515bb262f7bb9a91185187465c3a78c99cdfc8
|
File details
Details for the file openweatherwrap-1.0.0-py3-none-any.whl.
File metadata
- Download URL: openweatherwrap-1.0.0-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7386e85c66e88f5bf10bfafb442b836dbd3361ba51d5cb24e1aa83e24596975c
|
|
| MD5 |
5863c9efb2853b56a6c63caf43691132
|
|
| BLAKE2b-256 |
97488f931cd7018e8ca828e57b368d95a3fcbdfe8dc88dcaea69b257d5c0c745
|