A NOAA NCEI API wrapper for weather data
Project description
NOAA Climate Data Online API Client
An asynchronous Python client for the NOAA National Centers for Environmental Information (NCEI) Climate Data Online (CDO) Web Services API v2. Features automatic rate limiting, connection pooling, and comprehensive type safety.
Features
- ⚡ Asynchronous API: Built with
aiohttpfor high-performance async I/O - 🚦 Automatic Rate Limiting: Enforces NOAA's limits (5 req/sec, 10,000 req/day)
- 🔄 Connection Pooling: Efficient TCP connection reuse
- 📝 Type Safety: Full type hints and runtime validation
- 🎨 Beautiful Documentation: Color-formatted docstrings with pdoc
- 🛡️ Resource Management: Proper async context management
- 📊 Complete Coverage: All documented NOAA CDO v2 endpoints supported
Installation
pip install noaa-cdo-api
API Documentation
Full API documentation with colored formatting is available at https://fxf8.github.io/noaa-cdo-api/.
Quick Start
import asyncio
from noaa_cdo_api import NOAAClient, Extent
async def main():
# Best Practice: Use async context manager for automatic cleanup
async with NOAAClient(token="YOUR_TOKEN_HERE") as client:
# Query available datasets
datasets = await client.get_datasets(limit=10)
# Query stations in a geographic region
stations = await client.get_stations(
extent=Extent(40.0, -80.0, 45.0, -75.0), # latitude_min, longitude_min, latitude_max, longitude_max
datasetid="GHCND",
limit=5
)
# Get climate data with unit conversion
data = await client.get_data(
datasetid="GHCND",
startdate="2022-01-01",
enddate="2022-01-31",
stationid="GHCND:USW00094728",
units="metric",
limit=100,
)
if __name__ == "__main__":
asyncio.run(main())
Important Implementation Notes
Event Loop Management
# ❌ BAD: Creating multiple event loops
client1 = await NOAAClient(token="TOKEN1")
client2 = await NOAAClient(token="TOKEN2")
results = [*asyncio.run(client1.get_datasets(...)), *asyncio.run(client2.get_datasets(...))]
# ✅ GOOD: Share the same event loop (note that rate limits apply **per token**)
async with NOAAClient(token="TOKEN1") as client1, \
NOAAClient(token="TOKEN2") as client2:
await asyncio.gather(
client1.get_datasets(),
client2.get_datasets()
)
Resource Management
# ❌ Less ideal but functional: Manual cleanup
client = NOAAClient(token="TOKEN")
try:
await client.get_datasets()
finally:
client.close() # Might miss resources (note: close does not need to be awaited)
# ✅ Better: Use async context manager
async with NOAAClient(token="TOKEN") as client:
await client.get_datasets()
Rate Limiting
# ✅ Ideal
async def parallel_with():
async with NOAAClient(token="TOKEN") as client:
tasks = [client.get_datasets() for _ in range(20)]
return await asyncio.gather(*tasks) # Rate limits respected
# Works too since returns are asynchronous
async def parallel_separate():
tasks = []
for i in range(20):
client = NOAAClient(token="TOKEN") # Each has separate limiter
tasks.append(client.get_datasets())
return await asyncio.gather(*tasks) # May exceed limits
Tips
-
Connection Pooling
- Reuse the same client instance
- Default connection limit is 10
- Adjust with
tcp_connector_limitparameter
-
Pagination
- Use
limitandoffsetfor large result sets - Process data in chunks for memory efficiency
- Use
-
Data Volume
- Limit date ranges (1 year for daily, 10 years for monthly)
- Use specific station IDs when possible
- Set
includemetadata=Falseif not needed
-
Caching
- Cache frequently accessed metadata
- Implement local caching for historical data
Available Endpoints
/datasets: Query available datasets/datacategories: Query data categories/datatypes: Query data types/locationcategories: Query location categories/locations: Query locations/stations: Query weather stations/data: Query actual climate data
Type Safety
The library provides comprehensive type checking through:
TypedDictschemas for all parameters- Runtime validation of parameter values
- Proper enum types for constrained fields
Example with type checking:
from noaa_cdo_api import parameter_schemas
params: parameter_schemas.StationsParameters = {
"extent": "42.0,-90.0,40.0,-88.0",
"datasetid": "GHCND",
"limit": 100
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- NOAA's National Centers for Environmental Information (NCEI)
- The aiohttp team for their excellent HTTP client
- Contributors to the project
Getting Help
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file noaa_cdo_api-0.0.3.tar.gz.
File metadata
- Download URL: noaa_cdo_api-0.0.3.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92f2da08cf9330867900ebf3de92854fae5d2ecff1a35be42cbededf76914341
|
|
| MD5 |
6e47a915ffb3cac96017770816b11700
|
|
| BLAKE2b-256 |
7f4a94784d8bfe8fe84f665157d70cc0c4d23c11bf2eb471c1c7ca5b2dcbc0cd
|
File details
Details for the file noaa_cdo_api-0.0.3-py3-none-any.whl.
File metadata
- Download URL: noaa_cdo_api-0.0.3-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a979f095f3a1ed6e073ab95e1c8fd3f7602ef1b67859db0f0e387ffd3634075
|
|
| MD5 |
df966ec7a7747cecab2cacb5fad33f83
|
|
| BLAKE2b-256 |
572074fcbc32cb27e647efb602f6c1de30a82fc594e047f8bfb5f1197b4a97ba
|