Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openweatherwrap-1.1.1.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openweatherwrap-1.1.1-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file openweatherwrap-1.1.1.tar.gz.

File metadata

  • Download URL: openweatherwrap-1.1.1.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for openweatherwrap-1.1.1.tar.gz
Algorithm Hash digest
SHA256 7aa7b81c17f0379da6bbd3ac74757fe2ab284cf858ae66b32ca06323f5fecdd3
MD5 e664f831ea7e6ad2c7fdb910ef902849
BLAKE2b-256 2ea0d81d565576a348d1b0144415022cc4e473c00714bfe765cf2b94cc621316

See more details on using hashes here.

File details

Details for the file openweatherwrap-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for openweatherwrap-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b04d1fcd03ac83d308e582723963399d6456b64416ad3be5d3a71e3a6f165cb3
MD5 9d8b694936278c0a362de08cbae5d5b3
BLAKE2b-256 1dd01bcac33504d3517006461a5f7a6672c381038e844bd5827b808459abf342

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page