A comprehensive Python wrapper around OpenWeatherMap web APIs providing weather data, forecasts, air pollution, UV index, and agricultural information
—
Current weather conditions, forecasts, and historical weather data from OpenWeatherMap's Weather API v2.5 and OneCall API. Supports location queries by name, coordinates, city ID, zip code, and provides comprehensive weather forecasting capabilities.
Retrieve current weather observations for any location worldwide using various location identifiers.
class WeatherManager:
def weather_api_version(self) -> tuple:
"""
Get Weather API version.
Returns:
Tuple representing the API version
"""
def weather_at_place(self, name: str) -> Observation:
"""
Get current weather by location name.
Parameters:
- name: Location name (e.g., 'London,GB', 'New York,US')
Returns:
Observation object containing current weather data
"""
def weather_at_coords(self, lat: float, lon: float) -> Observation:
"""
Get current weather by geographic coordinates.
Parameters:
- lat: Latitude (-90.0 to 90.0)
- lon: Longitude (-180.0 to 180.0)
Returns:
Observation object containing current weather data
"""
def weather_at_zip_code(self, zipcode: str, country: str) -> Observation:
"""
Get current weather by postal/zip code.
Parameters:
- zipcode: Postal/zip code
- country: Two-letter country code (ISO 3166)
Returns:
Observation object containing current weather data
"""
def weather_at_id(self, id: int) -> Observation:
"""
Get current weather by OpenWeatherMap city ID.
Parameters:
- id: OpenWeatherMap city ID
Returns:
Observation object containing current weather data
"""
def weather_at_ids(self, ids_list: List[int]) -> List[Observation]:
"""
Get current weather for multiple city IDs.
Parameters:
- ids_list: List of OpenWeatherMap city IDs
Returns:
List of Observation objects
"""Search for weather data across multiple locations using patterns and geographic areas.
class WeatherManager:
def weather_at_places(self, pattern: str, searchtype: str, limit: int = None) -> List[Observation]:
"""
Search weather by location pattern.
Parameters:
- pattern: Location search pattern
- searchtype: 'accurate' for exact matches, 'like' for partial matches
- limit: Maximum number of results (optional)
Returns:
List of Observation objects matching the search
"""
def weather_at_places_in_bbox(self, lon_left: float, lat_bottom: float, lon_right: float, lat_top: float, zoom: int = 10, cluster: bool = False) -> List[Observation]:
"""
Get weather data within a bounding box.
Parameters:
- lon_left: Left longitude boundary
- lat_bottom: Bottom latitude boundary
- lon_right: Right longitude boundary
- lat_top: Top latitude boundary
- zoom: Map zoom level (1-20)
- cluster: Whether to cluster nearby stations
Returns:
List of Observation objects within the bounding box
"""
def weather_around_coords(self, lat: float, lon: float, limit: int = None) -> List[Observation]:
"""
Get weather data around coordinates.
Parameters:
- lat: Center latitude
- lon: Center longitude
- limit: Maximum number of results (optional)
Returns:
List of Observation objects around the coordinates
"""Retrieve weather forecast data with different time granularities and forecast horizons.
class WeatherManager:
def forecast_at_place(self, name: str, interval: str, limit: int = None) -> Forecaster:
"""
Get weather forecast by location name.
Parameters:
- name: Location name (e.g., 'London,GB')
- interval: '3h' for 3-hourly or 'daily' for daily forecasts
- limit: Maximum number of forecast items (optional)
Returns:
Forecaster object with forecast manipulation methods
"""
def forecast_at_coords(self, lat: float, lon: float, interval: str, limit: int = None) -> Forecaster:
"""
Get weather forecast by coordinates.
Parameters:
- lat: Latitude (-90.0 to 90.0)
- lon: Longitude (-180.0 to 180.0)
- interval: '3h' for 3-hourly or 'daily' for daily forecasts
- limit: Maximum number of forecast items (optional)
Returns:
Forecaster object with forecast manipulation methods
"""
def forecast_at_id(self, id: int, interval: str, limit: int = None) -> Forecaster:
"""
Get weather forecast by city ID.
Parameters:
- id: OpenWeatherMap city ID
- interval: '3h' for 3-hourly or 'daily' for daily forecasts
- limit: Maximum number of forecast items (optional)
Returns:
Forecaster object with forecast manipulation methods
"""Comprehensive weather data in a single API call including current weather, forecasts, alerts, and historical data.
class WeatherManager:
def one_call(self, lat: Union[int, float], lon: Union[int, float], **kwargs) -> OneCall:
"""
Get comprehensive weather data via OneCall API.
Parameters:
- lat: Latitude
- lon: Longitude
- exclude: List of data parts to exclude ('current', 'minutely', 'hourly', 'daily', 'alerts')
- units: Units format ('standard', 'metric', 'imperial')
- lang: Language code for weather descriptions
Returns:
OneCall object with current weather, forecasts, and alerts
"""
def one_call_history(self, lat: Union[int, float], lon: Union[int, float], dt: int = None) -> OneCall:
"""
Get historical weather data via OneCall API.
Parameters:
- lat: Latitude
- lon: Longitude
- dt: UNIX timestamp for historical data (optional, defaults to yesterday)
Returns:
OneCall object with historical weather data
"""Historical weather data from weather stations with different time aggregations.
class WeatherManager:
def station_tick_history(self, station_ID: int, limit: int = None) -> Historian:
"""
Get minute-level weather station history.
Parameters:
- station_ID: Weather station ID
- limit: Maximum number of measurements (optional)
Returns:
Historian object with historical data analysis methods
"""
def station_hour_history(self, station_ID: int, limit: int = None) -> Historian:
"""
Get hourly weather station history.
Parameters:
- station_ID: Weather station ID
- limit: Maximum number of measurements (optional)
Returns:
Historian object with historical data analysis methods
"""
def station_day_history(self, station_ID: int, limit: int = None) -> Historian:
"""
Get daily weather station history.
Parameters:
- station_ID: Weather station ID
- limit: Maximum number of measurements (optional)
Returns:
Historian object with historical data analysis methods
"""from pyowm import OWM
owm = OWM('your-api-key')
mgr = owm.weather_manager()
# Current weather by location name
observation = mgr.weather_at_place('London,GB')
weather = observation.weather
print(f"Temperature: {weather.temperature('celsius')['temp']}°C")
print(f"Feels like: {weather.temperature('celsius')['feels_like']}°C")
print(f"Status: {weather.detailed_status}")
print(f"Humidity: {weather.humidity}%")
print(f"Pressure: {weather.barometric_pressure()['press']} hPa")
print(f"Wind: {weather.wind()['speed']} m/s")
# Weather by coordinates
observation = mgr.weather_at_coords(51.5074, -0.1278)
weather = observation.weather
print(f"London weather: {weather.status}")# 3-hourly forecast
forecaster = mgr.forecast_at_place('New York,US', '3h')
# Check if it will rain in the forecast period
if forecaster.will_have_rain():
print("Rain is expected!")
rainy_times = forecaster.when_rain()
for weather in rainy_times:
print(f"Rain at: {weather.reference_time('iso')}")
# Get extreme weather conditions
hottest = forecaster.most_hot()
coldest = forecaster.most_cold()
windiest = forecaster.most_windy()
print(f"Hottest: {hottest.temperature('celsius')['temp']}°C")
print(f"Coldest: {coldest.temperature('celsius')['temp']}°C")
print(f"Windiest: {windiest.wind()['speed']} m/s")
# Daily forecast
daily_forecaster = mgr.forecast_at_place('Tokyo,JP', 'daily')
forecast = daily_forecaster.forecast
for weather in forecast[:5]: # Next 5 days
temp = weather.temperature('celsius')
print(f"{weather.reference_time('iso')}: {temp['min']}-{temp['max']}°C, {weather.status}")# Comprehensive weather data
one_call = mgr.one_call(lat=40.7128, lon=-74.0060, exclude=['minutely'])
# Current weather
current = one_call.current
print(f"Current: {current.temperature('celsius')['temp']}°C, {current.status}")
# Hourly forecast (next 48 hours)
if one_call.forecast_hourly:
for weather in one_call.forecast_hourly[:12]: # Next 12 hours
temp = weather.temperature('celsius')['temp']
print(f"{weather.reference_time('iso')}: {temp}°C")
# Daily forecast (next 8 days)
if one_call.forecast_daily:
for weather in one_call.forecast_daily:
temp = weather.temperature('celsius')
print(f"{weather.reference_time('iso')}: {temp['min']}-{temp['max']}°C")
# Weather alerts
if one_call.national_weather_alerts:
for alert in one_call.national_weather_alerts:
print(f"Alert: {alert.title}")
print(f"Description: {alert.description}")
print(f"Start: {alert.start_time('iso')}")
print(f"End: {alert.end_time('iso')}")class Observation:
def __init__(self, reception_time: int, location: Location, weather: Weather): ...
def reception_time(self, timeformat: str = 'unix') -> Union[int, str, datetime]: ...
@property
def location(self) -> Location: ...
@property
def weather(self) -> Weather: ...
def to_dict(self) -> dict: ...
class Weather:
def reference_time(self, timeformat: str = 'unix') -> Union[int, str, datetime]: ...
def sunset_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...
def sunrise_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...
def wind(self, unit: str = 'meters_sec') -> dict: ...
def temperature(self, unit: str = 'kelvin') -> dict: ...
def barometric_pressure(self, unit: str = 'hPa') -> dict: ...
def visibility(self, unit: str = 'meters') -> float: ...
def weather_icon_url(self, size: str = "") -> str: ...
@property
def status(self) -> str: ...
@property
def detailed_status(self) -> str: ...
@property
def weather_code(self) -> int: ...
@property
def weather_icon_name(self) -> str: ...
@property
def clouds(self) -> int: ...
@property
def rain(self) -> dict: ...
@property
def snow(self) -> dict: ...
@property
def humidity(self) -> int: ...
@property
def dewpoint(self) -> float: ...
@property
def heat_index(self) -> float: ...
@property
def humidex(self) -> float: ...
@property
def visibility_distance(self) -> float: ...
@property
def uvi(self) -> Union[int, float, None]: ...
@property
def precipitation_probability(self) -> Union[float, None]: ...
def to_dict(self) -> dict: ...
class Forecast:
def __init__(self, interval: str, reception_time: int, location: Location, weathers: List[Weather]): ...
def get(self, index: int) -> Weather: ...
def reception_time(self, timeformat: str = 'unix') -> Union[int, str, datetime]: ...
def actualize(self) -> None: ...
@property
def interval(self) -> str: ...
@property
def location(self) -> Location: ...
@property
def weathers(self) -> List[Weather]: ...
def __len__(self) -> int: ...
def __iter__(self): ...
class Forecaster:
def __init__(self, forecast: Forecast): ...
def when_starts(self, timeformat: str = 'unix') -> Union[int, str, datetime]: ...
def when_ends(self, timeformat: str = 'unix') -> Union[int, str, datetime]: ...
# Weather condition checks
def will_have_rain(self) -> bool: ...
def will_have_clear(self) -> bool: ...
def will_have_fog(self) -> bool: ...
def will_have_clouds(self) -> bool: ...
def will_have_snow(self) -> bool: ...
def will_have_storm(self) -> bool: ...
def will_have_tornado(self) -> bool: ...
def will_have_hurricane(self) -> bool: ...
# Weather filtering
def when_rain(self) -> List[Weather]: ...
def when_clear(self) -> List[Weather]: ...
def when_fog(self) -> List[Weather]: ...
def when_clouds(self) -> List[Weather]: ...
def when_snow(self) -> List[Weather]: ...
def when_storm(self) -> List[Weather]: ...
def when_tornado(self) -> List[Weather]: ...
def when_hurricane(self) -> List[Weather]: ...
# Time-specific weather checks
def will_be_rainy_at(self, timeobject) -> bool: ...
def will_be_clear_at(self, timeobject) -> bool: ...
def will_be_snowy_at(self, timeobject) -> bool: ...
def will_be_cloudy_at(self, timeobject) -> bool: ...
def will_be_foggy_at(self, timeobject) -> bool: ...
def will_be_stormy_at(self, timeobject) -> bool: ...
def will_be_tornado_at(self, timeobject) -> bool: ...
def will_be_hurricane_at(self, timeobject) -> bool: ...
def get_weather_at(self, timeobject) -> Weather: ...
# Weather extremes
def most_hot(self) -> Union[Weather, None]: ...
def most_cold(self) -> Union[Weather, None]: ...
def most_humid(self) -> Union[Weather, None]: ...
def most_rainy(self) -> Union[Weather, None]: ...
def most_snowy(self) -> Union[Weather, None]: ...
def most_windy(self) -> Union[Weather, None]: ...
@property
def forecast(self) -> Forecast: ...
class OneCall:
def __init__(self, lat: Union[int, float], lon: Union[int, float], timezone: str,
current: Weather, forecast_minutely: Optional[List[Weather]] = None,
forecast_hourly: Optional[List[Weather]] = None,
forecast_daily: Optional[List[Weather]] = None,
national_weather_alerts: Optional[List] = None): ...
def to_geopoint(self) -> Point: ...
@property
def lat(self) -> Union[int, float]: ...
@property
def lon(self) -> Union[int, float]: ...
@property
def timezone(self) -> str: ...
@property
def current(self) -> Weather: ...
@property
def forecast_minutely(self) -> Optional[List[Weather]]: ...
@property
def forecast_hourly(self) -> Optional[List[Weather]]: ...
@property
def forecast_daily(self) -> Optional[List[Weather]]: ...
@property
def national_weather_alerts(self) -> Optional[List]: ...
class Historian:
def __init__(self, station_history): ...
# Time series data
def temperature_series(self, unit: str = 'kelvin') -> List[Tuple[int, float]]: ...
def humidity_series(self) -> List[Tuple[int, int]]: ...
def pressure_series(self) -> List[Tuple[int, float]]: ...
def rain_series(self) -> List[Tuple[int, float]]: ...
def wind_series(self) -> List[Tuple[int, dict]]: ...
# Statistical methods
def max_temperature(self, unit: str = 'kelvin') -> Tuple[int, float]: ...
def min_temperature(self, unit: str = 'kelvin') -> Tuple[int, float]: ...
def average_temperature(self, unit: str = 'kelvin') -> float: ...
def max_humidity(self) -> Tuple[int, int]: ...
def min_humidity(self) -> Tuple[int, int]: ...
def average_humidity(self) -> float: ...
def max_pressure(self) -> Tuple[int, float]: ...
def min_pressure(self) -> Tuple[int, float]: ...
def average_pressure(self) -> float: ...
def max_rain(self) -> Tuple[int, float]: ...
def min_rain(self) -> Tuple[int, float]: ...
def average_rain(self) -> float: ...
class NationalWeatherAlert:
def __init__(self, sender: str, title: str, description: str, start_time: int, end_time: int, tags: Optional[List[str]] = None): ...
def start_time(self, timeformat: str = 'unix') -> Union[int, str, datetime]: ...
def end_time(self, timeformat: str = 'unix') -> Union[int, str, datetime]: ...
@property
def sender(self) -> str: ...
@property
def title(self) -> str: ...
@property
def description(self) -> str: ...
@property
def tags(self) -> Optional[List[str]]: ...
def to_dict(self) -> dict: ...Install with Tessl CLI
npx tessl i tessl/pypi-pyowm