Expand description
Provides a Rust interface for accessing historical weather and climate data from Meteostat, using their free bulk data interface.
This crate allows fetching hourly, daily, monthly, and climate normal data
for thousands of weather stations worldwide, either by station ID or by
geographical coordinates (latitude/longitude). Data is returned efficiently
as Polars LazyFrame wrappers, enabling powerful filtering and analysis
before loading data into memory. Automatic caching of station metadata and
weather data files minimizes redundant downloads.
§Features
- Fetch by Station ID or Location: Initiate requests via frequency-specific clients
(
client.hourly(),client.daily(), etc.) and then specify either.station("ID")or.location(LatLon). - Find Nearby Stations: Search for stations near coordinates using
client.find_stations(), optionally filtering by distance and required data availability (inventory). - Multiple Frequencies: Supports Hourly, Daily, Monthly, and Climate Normals data.
- Efficient Data Handling: Returns data as wrappers around Polars
LazyFrames (e.g.,HourlyLazyFrame), allowing for powerful, memory-efficient filtering and manipulation before collecting results. - Convenient Filtering: Frame wrappers provide methods for easy filtering by date,
year, month, or datetime ranges (e.g.,
daily_lazy.get_for_period(Year(2023))). - Flexible Collection: Collect results either as a Polars
DataFrame(.frame.collect()) or directly into Rust structs (.collect_hourly(),.collect_single_daily(), etc.) using methods on the frame wrappers. - Automatic Caching: Downloads and caches station metadata and weather data files locally to speed up subsequent requests.
- Asynchronous: Built with
tokiofor non-blocking I/O.
§Basic Usage
use meteostat::{Meteostat, LatLon, MeteostatError, Year};
use polars::prelude::*;
use chrono::{NaiveDate};
#[tokio::main]
async fn main() -> Result<(), MeteostatError> {
let client = Meteostat::new().await?;
// Period for which we want hourly data:
let period = NaiveDate::from_ymd_opt(2023, 9, 1).unwrap();
// --- Example 1: Collect 24 hourly data points into `Vec<Hourly>` ---
let hourly_vec = client
.hourly()
.location(LatLon(52.0836403, 5.1257283))
.call()
.await? // `HourlyLazyFrame`
.get_for_period(period)? // `HourlyLazyFrame` with filter plan
.collect_hourly()?; // `Vec<Hourly>`
// Do something with the hourly data...
// --- Example 2: Collect daily data from 2023 into a `DataFrame` ---
let daily_df = client
.daily()
.location(LatLon(52.0836403, 5.1257283))
.call()
.await? // `DailyLazyFrame`
.get_for_period(Year(2023))? // `DailyLazyFrame` with filter plan
.frame // `LazyFrame` with filter plan
.collect()?; // `DataFrame`
// Do something with the daily data...
Ok(())
}§Core Concepts
Meteostat: The main entry point client struct. Created viaMeteostat::neworMeteostat::with_cache_folder.- Frequency Clients: Accessed via methods on
Meteostat(e.g.,Meteostat::hourly,Meteostat::daily). These return builders. - Source Specification: Use
.station("ID")or.location(LatLon)on the frequency client builders. LazyFrameWrappers: Fetching data returns structs likeHourlyLazyFrame,DailyLazyFrame,MonthlyLazyFrame,ClimateLazyFramewhich contain a PolarsLazyFrameand provide convenience filtering and collection methods.- Filtering: Use methods like
get_range,get_at,get_for_periodon the frame wrappers, or access.framefor advanced Polars operations. - Collecting: Call
.frame.collect()?on the frame wrappers to execute the query and get aDataFrame, OR use specific methods like.collect_daily(),.collect_single_hourly(), etc., to get results directly as Rust structs (e.g.,Vec<Daily>,Hourly). - Finding Stations: Use
Meteostat::find_stationsto search forStationobjects near aLatLon, optionally filtering byInventoryRequestcriteria.
§Data Source and Attribution
- All weather data is sourced from Meteostat.
- This crate uses Meteostat’s free bulk data interface. No API key is required. Please consider supporting them if you find their service useful.
Structs§
- Climate
- Represents a row of climate normals data, suitable for collecting results.
- Climate
Client - A client builder specifically for fetching climate normals data.
- Climate
Lazy Frame - A wrapper around a Polars
LazyFramespecifically for Meteostat climate data. - Daily
- Represents a row of daily weather data, suitable for collecting results.
- Daily
Client - A client builder specifically for fetching daily weather data.
- Daily
Lazy Frame - A wrapper around a Polars
LazyFramespecifically for Meteostat daily weather data. - Hourly
- Represents a row of hourly weather data, suitable for collecting results.
- Hourly
Client - A client builder specifically for fetching hourly weather data.
- Hourly
Lazy Frame - A wrapper around a Polars
LazyFramespecifically for Meteostat hourly weather data. - Inventory
Request - Represents criteria for filtering weather stations based on their data inventory.
- LatLon
- Represents a geographical coordinate using Latitude and Longitude.
- Meteostat
- The main client struct for accessing Meteostat data.
- Month
- Monthly
- Represents a row of monthly weather data, suitable for collecting results.
- Monthly
Client - A client builder specifically for fetching monthly weather data.
- Monthly
Lazy Frame - A wrapper around a Polars
LazyFramespecifically for Meteostat monthly weather data. - Station
- Represents a single Meteostat weather station and its associated metadata.
- Year
Enums§
- Frequency
- Represents the time frequency or granularity of Meteostat weather data.
- Locate
Station Error - Meteostat
Error - Required
Data - Specifies the criteria for checking if a weather station has the necessary
data inventory when searching for stations (e.g., using
crate::Meteostat::find_stations). - Weather
Condition - Represents the weather condition code reported by Meteostat.
- Weather
Data Error