Expand description
noaa-tides
Library to fetch NOAA tide and currents data from their CO-OPS API.
The CO-OPS API is a single endpoint with multiple products that can be requested with different combinations of query parameters. This library was built to provide a type-safe interface for building requests and deserializing responses into dedicated structs. This library currently supports the “predictions” product, which includes predicted tide heights for specified stations and date ranges.
Contributions to support additional products are welcome!
No API keys are required since the NOAA CO-OPS API does not require authentication, please be mindful with usage.
§Example
Below is an example to fetch high/low tide predictions for the San Francisco Golden Gate station for January 2026
use noaa_tides::{params, NoaaTideClient, PredictionsRequest};
use chrono::NaiveDate;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = NoaaTideClient::new();
let request = PredictionsRequest {
station: "9414290".into(),
date_range: params::DateRange {
begin_date: NaiveDate::from_ymd_opt(2026, 1, 1).unwrap(),
end_date: NaiveDate::from_ymd_opt(2026, 1, 31).unwrap(),
},
datum: params::Datum::MLLW,
time_zone: params::Timezone::LST_LDT,
interval: params::Interval::HighLow,
units: params::Units::English,
};
let data = client.fetch_predictions(&request).await?;
println!("High/low tide predictions:");
for p in data.predictions.iter() {
println!(
"{} - {:?} tide height: {}",
p.datetime,
p.tide_type.unwrap(),
p.height
);
}
Ok(())
}Re-exports§
pub use crate::products::predictions::PredictionsRequest;pub use crate::products::predictions::PredictionsResponse;
Modules§
- params
- Module with parameter types for building requests
- products
- Module with product request and response types
Structs§
- Noaa
Tide Client - Client to get data from the NOAA Tides and Currents API
Enums§
- Noaa
Tide Error - Possible errors when fetching data from the NOAA API