meteomatics
raw JSON → 3.0.0 verified Mon Apr 27 auth: no python
Python client for the Meteomatics Weather API. Provides access to historical, current, and forecast weather data. Latest version: 3.0.0, actively maintained.
pip install meteomatics Common errors
error ImportError: cannot import name 'MeteomaticsConnector' from 'meteomatics' ↓
cause v3.0.0 removed the MeteomaticsConnector class.
fix
Use module-level functions like
from meteomatics import query_time_series. error TypeError: query_time_series() got an unexpected keyword argument 'on_invalid' ↓
cause `on_invalid` parameter is only available for grid queries, not time series.
fix
Remove
on_invalid argument from time series calls, or use it with query_grid_unpivoted. error ValueError: startdate and enddate must be timezone-aware ↓
cause SQL-like parameters require timezone-aware datetime objects.
fix
Convert naive datetimes using
pytz.UTC.localize() or datetime.replace(tzinfo=zoneinfo.ZoneInfo('UTC')). Warnings
breaking v3.0.0 removed deprecated functions like `query_dem` and `query_grid` without the `_unpivoted` suffix. ↓
fix Update calls to current API functions: e.g., use `query_grid_unpivoted` instead of `query_grid`.
gotcha The module-level functions (e.g., query_time_series) require username and password passed directly; the old MeteomaticsConnector class is gone. ↓
fix Pass credentials to each function call, not through a connector object.
gotcha Time parameters must be timezone-aware for SQL-like queries; naive datetimes may raise errors. ↓
fix Use pytz or zoneinfo to make datetimes aware before passing.
Imports
- MeteomaticsConnector wrong
from meteomatics import MeteomaticsConnectorcorrectimport meteomatics - query_time_series
from meteomatics import query_time_series
Quickstart
import datetime as dt
from meteomatics import query_time_series
username = os.environ.get('METEOMATICS_USER', '')
password = os.environ.get('METEOMATICS_PASSWORD', '')
now = dt.datetime.utcnow()
startdate = now - dt.timedelta(days=1)
enddate = now
interval = dt.timedelta(hours=1)
parameters = ['t_2m:C']
locations = [(50.0, 10.0)]
df = query_time_series(startdate, enddate, interval, parameters, locations, username, password)
print(df.head())