A comprehensive Python wrapper around OpenWeatherMap web APIs providing weather data, forecasts, air pollution, UV index, and agricultural information
—
Personal weather station management for creating, updating stations and sending/retrieving measurement data. Enables users to create their own weather monitoring network and contribute data to OpenWeatherMap.
class StationsManager:
def stations_api_version(self) -> tuple:
"""
Get Stations API version.
Returns:
Tuple representing the API version
"""
def create_station(self, external_id: str, name: str, lat: float, lon: float, alt: float = None) -> Station:
"""
Create a new weather station.
Parameters:
- external_id: User-defined station identifier
- name: Station name
- lat: Latitude (-90.0 to 90.0)
- lon: Longitude (-180.0 to 180.0)
- alt: Altitude in meters (optional, must be >= 0)
Returns:
Station object representing the created station
"""
def get_stations(self) -> List[Station]:
"""Get all user stations."""
def get_station(self, id: str) -> Station:
"""Get specific station by ID."""
def update_station(self, station: Station) -> None:
"""Update station information."""
def delete_station(self, station: Station) -> None:
"""Delete a station."""class StationsManager:
def send_measurement(self, measurement: Measurement) -> None:
"""Send single measurement to a station."""
def send_measurements(self, list_of_measurements: List[Measurement]) -> None:
"""Send multiple measurements to stations."""
def get_measurements(self, station_id: str, aggregated_on: str, from_timestamp: int,
to_timestamp: int, limit: int = 100) -> List[AggregatedMeasurement]:
"""
Retrieve aggregated measurements from a station.
Parameters:
- station_id: Station ID
- aggregated_on: 'm' (minute), 'h' (hour), 'd' (day)
- from_timestamp: Start time (UNIX timestamp)
- to_timestamp: End time (UNIX timestamp)
- limit: Maximum number of results (default 100)
Returns:
List of AggregatedMeasurement objects
"""
def send_buffer(self, buffer: Buffer) -> None:
"""Send buffered measurements."""from pyowm import OWM
from pyowm.stationsapi30.measurement import Measurement
from datetime import datetime
owm = OWM('your-api-key')
stations_mgr = owm.stations_manager()
# Create a weather station
station = stations_mgr.create_station(
external_id='my_station_001',
name='Home Weather Station',
lat=40.7128,
lon=-74.0060,
alt=10.0 # 10 meters above sea level
)
print(f"Created station: {station.name} (ID: {station.id})")
# Send weather measurement
measurement = Measurement(
station_id=station.id,
timestamp=int(datetime.now().timestamp()),
temperature=22.5,
humidity=65,
pressure=1013.25,
wind_speed=5.2,
wind_deg=270,
rain_1h=0.0
)
stations_mgr.send_measurement(measurement)
print("Measurement sent successfully")
# Retrieve measurements
from_time = int((datetime.now() - timedelta(days=1)).timestamp())
to_time = int(datetime.now().timestamp())
measurements = stations_mgr.get_measurements(
station_id=station.id,
aggregated_on='h', # Hourly aggregation
from_timestamp=from_time,
to_timestamp=to_time
)
print(f"Retrieved {len(measurements)} hourly measurements")
for measurement in measurements[-5:]: # Last 5 measurements
print(f"Time: {measurement.creation_time('iso')}")
if measurement.temp:
print(f" Temperature: {measurement.temp['avg']}°C")
if measurement.humidity:
print(f" Humidity: {measurement.humidity['avg']}%")class Station:
def __init__(self, id: str, created_at: str, updated_at: str, external_id: str,
name: str, lon: float, lat: float, alt: float, rank: int): ...
def creation_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...
def last_update_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...
@property
def id(self) -> str: ...
@property
def external_id(self) -> str: ...
@property
def name(self) -> str: ...
@property
def lon(self) -> float: ...
@property
def lat(self) -> float: ...
@property
def alt(self) -> float: ...
@property
def rank(self) -> int: ...
class Measurement:
def __init__(self, station_id: str, timestamp: int, **kwargs): ...
def creation_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...
def to_JSON(self) -> str: ...
@property
def station_id(self) -> str: ...
@property
def timestamp(self) -> int: ...
# Weather parameters (all optional)
@property
def temperature(self) -> Union[float, None]: ...
@property
def wind_speed(self) -> Union[float, None]: ...
@property
def wind_gust(self) -> Union[float, None]: ...
@property
def wind_deg(self) -> Union[float, None]: ...
@property
def pressure(self) -> Union[float, None]: ...
@property
def humidity(self) -> Union[int, None]: ...
# Precipitation parameters
@property
def rain_1h(self) -> Union[float, None]: ...
@property
def rain_6h(self) -> Union[float, None]: ...
@property
def rain_24h(self) -> Union[float, None]: ...
@property
def snow_1h(self) -> Union[float, None]: ...
@property
def snow_6h(self) -> Union[float, None]: ...
@property
def snow_24h(self) -> Union[float, None]: ...
class AggregatedMeasurement:
def __init__(self, station_id: str, timestamp: int, aggregated_on: str,
temp: dict = None, humidity: dict = None, wind: dict = None,
pressure: dict = None, precipitation: dict = None): ...
def creation_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...
@property
def station_id(self) -> str: ...
@property
def timestamp(self) -> int: ...
@property
def aggregated_on(self) -> str: # 'm', 'h', or 'd'
"""Aggregation timeframe: 'm' (minute), 'h' (hour), 'd' (day)"""
@property
def temp(self) -> Union[dict, None]:
"""Temperature statistics: {'min': float, 'max': float, 'avg': float}"""
@property
def humidity(self) -> Union[dict, None]:
"""Humidity statistics: {'min': int, 'max': int, 'avg': int}"""
@property
def wind(self) -> Union[dict, None]:
"""Wind statistics: {'speed': {'min': float, 'max': float, 'avg': float}, 'deg': {'avg': float}}"""
@property
def pressure(self) -> Union[dict, None]:
"""Pressure statistics: {'min': float, 'max': float, 'avg': float}"""
@property
def precipitation(self) -> Union[dict, None]:
"""Precipitation statistics: {'sum': float}"""Install with Tessl CLI
npx tessl i tessl/pypi-pyowm