Open-Meteo Python Library
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
- breaking The `.close()` method was removed from client objects in `v1.7.0`.
- gotcha Data from the FlatBuffers response objects must be accessed using function calls (e.g., `response.Latitude()`) rather than direct attribute access (e.g., `response.Latitude`).
- gotcha The `openmeteo-requests` library works with `openmeteo-sdk`. You need to install `openmeteo-sdk` separately to properly work with `Variable` enums and fully process the FlatBuffers responses.
Install
-
pip install openmeteo-requests
Imports
- Client
from openmeteo_requests import Client
import openmeteo_requests om = openmeteo_requests.Client()
- Variable
from openmeteo_sdk.Variable import Variable
Quickstart
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()} %")