Open-Meteo Python Library

1.7.5 · active · verified Wed Apr 15

The openmeteo-requests library is an API client for the Open-Meteo Weather API, currently at version 1.7.5. It uses FlatBuffers for efficient data transfer, particularly for long time-series data, offering zero-copy data transfer to popular libraries like NumPy, Pandas, or Polars. Designed primarily for data scientists, it facilitates quick processing and analysis of weather data, including historical data from 1940 onwards. The library maintains an active development status with regular updates, often focusing on bug fixes and internal improvements, with new features and breaking changes typically introduced in minor or major version bumps.

Warnings

Install

Imports

Quickstart

This quickstart initializes the Open-Meteo client, defines weather parameters for a specific location (Berlin), and fetches current and hourly forecast data. It then demonstrates how to access the FlatBuffers-encoded data, specifically extracting current temperature and relative humidity. Note that Open-Meteo's API generally does not require an API key for non-commercial use.

import openmeteo_requests
from openmeteo_sdk.Variable import Variable

# Initialize the Open-Meteo API client
om = openmeteo_requests.Client()

# Define parameters for the weather request
params = {
    "latitude": 52.52,
    "longitude": 13.41,
    "hourly": ["temperature_2m", "precipitation", "wind_speed_10m"],
    "current": ["temperature_2m", "relative_humidity_2m"],
    "timezone": "Europe/Berlin"
}

# Make the API call
url = "https://api.open-meteo.com/v1/forecast"
responses = om.weather_api(url, params=params)

# Process the first location's response (assuming single location for brevity)
response = responses[0]

print(f"Coordinates: {response.Latitude()}°N {response.Longitude()}°E")
print(f"Elevation: {response.Elevation()} m asl")
print(f"Timezone: {response.Timezone()} {response.TimezoneAbbreviation()}")
print(f"Timezone difference to GMT+0: {response.UtcOffsetSeconds()} s")

# Access current weather data
current = response.Current()
current_variables = list(map(lambda i: current.Variables(i), range(0, current.VariablesLength())))

current_temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, current_variables))
current_relative_humidity_2m = next(filter(lambda x: x.Variable() == Variable.relative_humidity and x.Altitude() == 2, current_variables))

print(f"Current time: {current.Time()}")
print(f"Current temperature_2m: {current_temperature_2m.Value()} °C")
print(f"Current relative_humidity_2m: {current_relative_humidity_2m.Value()} %")

view raw JSON →