Meteostat Python Library
Meteostat is an open-source Python library that provides an easy and efficient way to access and analyze historical weather and climate data. It retrieves observations and statistics from Meteostat's bulk data interface, which aggregates information from various public sources, including national weather services like NOAA and DWD. The library is currently at version 2.1.4 and is actively maintained with a focus on performance improvements and a consistent API experience.
Warnings
- breaking Meteostat 2.0.0 introduced breaking changes, including performance improvements and a more consistent API experience. Code written for versions prior to 2.0.0 may require adjustments.
- deprecated Meteostat shut down version 1 of its JSON API on May 1, 2021. While this primarily affects direct API users, older versions of the Python library might have relied on aspects of API v1, leading to unexpected behavior if not updated.
- gotcha By default, Meteostat caches data dumps on your local drive in `~/.meteostat/cache`. If you are short on storage, monitor the cache size or specify a different `cache_dir` parameter.
- gotcha Meteostat uses the metric system (e.g., °C for temperature, mm for precipitation, km/h for wind speed) and UTC for time. Ensure your data processing and visualizations account for these default units and timezones.
Install
-
pip install meteostat
Imports
- Point
from meteostat import Point
- Daily
from meteostat import Daily
- Hourly
from meteostat import Hourly
- Stations
from meteostat import Stations
- Parameter
from meteostat import Parameter
Quickstart
from datetime import date
import matplotlib.pyplot as plt
import meteostat as ms
# Specify location and time range for Frankfurt, Germany
POINT = ms.Point(50.1155, 8.6842, 113)
START = date(2018, 1, 1)
END = date(2018, 12, 31)
# Get nearby weather stations
stations = ms.stations.nearby(POINT, limit=4)
# Get daily data & perform interpolation
ts = ms.daily(stations, START, END)
df = ms.interpolate(ts, POINT).fetch()
# Plot line chart including average, minimum and maximum temperature
df.plot(y=[ms.Parameter.TEMP, ms.Parameter.TMIN, ms.Parameter.TMAX])
plt.title('2018 Temperature Data for Frankfurt, Germany')
plt.xlabel('Date')
plt.ylabel('Temperature (°C)')
plt.show()