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.0.tar.gz (32.2 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.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openweatherwrap-1.1.0.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for openweatherwrap-1.1.0.tar.gz
Algorithm Hash digest
SHA256 83c4b488ddee771462bad0d7e45279805ceefc1a01aa70e2cbcba6e2b59063a9
MD5 f3fcb19e3ba7cfba007de29f726a6ad3
BLAKE2b-256 0cdc97d62dba9945a6176987b743e89152148ea4a840134ab90395fae0cdf0b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openweatherwrap-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b647e2035e21dffa27bfb21282b82d09d8c3ff178c63b71590205a8e6a43e34
MD5 c0619399a6ad1c4b308394e15b5caa18
BLAKE2b-256 6cbdf8e6b70014d1cf3d719605f742ea9ea060ff650dab68aea1d7e425f73660

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