Skip to main content

Get historical weather data for US ZIP codes from NOAA stations

Project description

Get Weather Data

PyPI Version Downloads License Python 3.11+ Docs

Get historical weather data for US ZIP codes. Uses NOAA weather station data (GHCN Daily and GSOD) with automatic station selection based on proximity.

Installation

pip install get-weather-data

Or with uv:

uv pip install get-weather-data

Quick Start

Python API

from get_weather_data import Weather

# Initialize and set up database (downloads ~50MB first time)
weather = Weather()
weather.setup()

# Get weather for a ZIP code and date
result = weather.get("10001", "2024-01-15")

print(f"Max temp: {result.tmax / 10:.1f} °C")
print(f"Min temp: {result.tmin / 10:.1f} °C")
print(f"Station: {result.station_name}")

Command Line

# Set up database (first time only)
get-weather setup

# Get weather for a location and date
get-weather get 10001 2024-01-15

# Process a CSV file
get-weather process input.csv output.csv

Features

  • Simple API: One class, three methods: setup(), get(), process_csv()
  • Automatic station selection: Finds nearest weather stations for each ZIP code
  • Two data sources: GHCN Daily (~100K US stations) and GSOD (~3K stations)
  • Batch processing: Process CSV files with ZIP codes and dates
  • Local database: SQLite database for fast repeated queries
  • CLI tool: Command-line interface for quick lookups

Usage Examples

Get Weather for a Date Range

from datetime import date
from get_weather_data import Weather

weather = Weather()

results = weather.get_range(
    zipcode="90210",
    start_date=date(2024, 7, 1),
    end_date=date(2024, 7, 7),
)

for r in results:
    print(f"{r.date}: High {r.tmax/10:.0f}°C, Low {r.tmin/10:.0f}°C")

Process a CSV File

from get_weather_data import Weather

weather = Weather()

# Input CSV should have zip, year, month, day columns
weather.process_csv(
    input_path="locations.csv",
    output_path="locations_with_weather.csv",
    zipcode_column="zip",
    year_column="year",
    month_column="month",
    day_column="day",
)

More examples in the examples/ directory.

Data Sources

This package uses data from NOAA's National Centers for Environmental Information:

  • GHCN Daily: Global Historical Climatology Network daily summaries
  • GSOD: Global Summary of the Day from USAF/WBAN stations
  • GeoNames: ZIP code to coordinates mapping

Weather Variables

Variable Description Unit
tmax Maximum temperature tenths of °C
tmin Minimum temperature tenths of °C
tavg Average temperature tenths of °C
prcp Precipitation tenths of mm
snow Snowfall mm
snwd Snow depth mm
awnd Average wind speed tenths of m/s

Database Setup

The first time you run setup(), the package downloads:

  • GHCN station list (~20K US stations)
  • ISD station list (~3K US stations)
  • US ZIP code coordinates from GeoNames

Then it builds an index mapping each ZIP code to nearby weather stations. This takes a few minutes but only needs to be done once.

weather = Weather()
weather.setup()  # Downloads data, builds index

# Check what was imported
info = weather.info()
print(f"GHCN stations: {info['ghcn_stations']:,}")
print(f"USAF stations: {info['usaf_stations']:,}")
print(f"ZIP codes: {info['zipcodes']:,}")

Configuration

Custom database location:

weather = Weather(database_path="/path/to/my.db")

Or via CLI:

get-weather --database /path/to/my.db setup

License

MIT License. See LICENSE for details.

Authors

  • Suriyan Laohaprapanon
  • Gaurav Sood

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

get_weather_data-3.2.1.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

get_weather_data-3.2.1-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file get_weather_data-3.2.1.tar.gz.

File metadata

  • Download URL: get_weather_data-3.2.1.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for get_weather_data-3.2.1.tar.gz
Algorithm Hash digest
SHA256 1171bb771dacc4d07beeabf4e14256d19a6a2351b1fff403fefcaad0e857745e
MD5 3829773a3ff239a738542543d8e4773f
BLAKE2b-256 458806ff3807d7917bc7e2dcbd2b7b127860d701238ec4fa42a292408a735967

See more details on using hashes here.

File details

Details for the file get_weather_data-3.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for get_weather_data-3.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b3de2a443e330d0ba0feabdf16dc05c9ca47e1e021e2f4447ba45c0c1244a50
MD5 4fab88637fbe8d4ad163423c32b57363
BLAKE2b-256 15952d6f449a4f715b7fec8ebc74131aaaf18cb441accdee2ae92753c0a93b83

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page