Skip to main content

Python Windy API package for interacting with the Windy API.

Project description

Windy API

Actions Status PyPI version PyPI platforms

Python Windy API package for interacting with the Windy API. Currently only supports access to the point forecast API.

Features

  • Point Forecast API: Get detailed weather forecasts for any geographic location using latitude/longitude coordinates
  • Multiple Weather Models: Support for 7+ weather forecast models including GFS, ICON EU, GFS Wave, NAM regional models, and CAMS air quality
  • Comprehensive Parameters: Access 20+ weather parameters including temperature, wind, precipitation, humidity, clouds, pressure, CAPE, and more
  • Automatic Validation: Built-in parameter validation ensures only compatible parameters are requested for each model
  • Async Support: Full async/await support for concurrent API requests with get_point_forecast_async()
  • Type Safety: Strongly typed with Pydantic models for reliable data validation and IDE autocomplete
  • Easy Data Access: Intuitive response objects with helper methods like get_data() and get_unit() for accessing forecast data
  • Error Handling: Clear error messages and exceptions for robust application development

Installation

python -m pip install windy_api

From source:

git clone https://github.com/stedonnelly/windy-api
cd windy-api
python -m pip install .

Usage

Quick Start

from windy_api import WindyAPI

# Initialize the client with your API key
api = WindyAPI(api_key="your_api_key_here")

# Get point forecast for San Francisco
response = api.get_point_forecast(
    latitude=37.7749,
    longitude=-122.4194,
    model="gfs",
    parameters=["temp", "wind"]
)

# Access forecast data
print(f"Timestamps: {response.ts}")
print(f"Temperature data: {response.get_data('temp-surface')}")
print(f"Temperature unit: {response.get_unit('temp-surface')}")

Available Weather Models

The following weather forecast models are supported:

  • gfs - Global Forecast System (default)
  • iconeu - ICON EU regional model
  • gfs_wave - GFS Wave model
  • namconus - NAM CONUS regional model
  • namhawaii - NAM Hawaii regional model
  • namalaska - NAM Alaska regional model
  • cams - CAMS air quality model

Available Parameters

Common weather parameters you can request:

  • temp - Temperature
  • wind - Wind speed and direction (returns wind_u and wind_v components)
  • windGust - Wind gusts
  • dewpoint - Dew point temperature
  • precip - Precipitation
  • convPrecip - Convective precipitation
  • snowPrecip - Snow precipitation
  • cape - Convective Available Potential Energy
  • pressure - Atmospheric pressure
  • rh - Relative humidity
  • lclouds, mclouds, hclouds - Low/medium/high clouds
  • gh - Geopotential height
  • ptype - Precipitation type

Model Parameter Checking

Upon submitting a request to the Windy API the request is validated. If a parameter is requested for a model that does not support it, the incompatible parameters will automatically be removed from the request on validation.

Detailed Examples

Multiple Parameters

# Request multiple weather parameters
response = api.get_point_forecast(
    latitude=40.7128,
    longitude=-74.0060,
    model="gfs",
    parameters=["temp", "dewpoint", "pressure", "rh", "precip"]
)

# Access each parameter
for timestamp in response.ts:
    print(f"Time: {timestamp}")

temp_data = response.get_data("temp-surface")
dewpoint_data = response.get_data("dewpoint-surface")
pressure_data = response.get_data("pressure-surface")

Working with Wind Data

# Wind returns u and v components
response = api.get_point_forecast(
    latitude=51.5074,
    longitude=-0.1278,
    model="gfs",
    parameters=["wind", "windGust"]
)

# Get wind components
wind_u = response.get_data("wind_u-surface")  # East-west component
wind_v = response.get_data("wind_v-surface")  # North-south component
wind_gust = response.get_data("windGust-surface")

Async Usage

import asyncio
from windy_api import WindyAPI

async def get_forecasts():
    api = WindyAPI(api_key="your_api_key_here")

    # Fetch multiple locations concurrently
    responses = await asyncio.gather(
        api.get_point_forecast_async(37.7749, -122.4194, "gfs", ["temp"]),
        api.get_point_forecast_async(40.7128, -74.0060, "gfs", ["temp"]),
        api.get_point_forecast_async(51.5074, -0.1278, "gfs", ["temp"])
    )

    return responses

# Run the async function
responses = asyncio.run(get_forecasts())

Using Environment Variables for API Key

import os
from dotenv import load_dotenv
from windy_api import WindyAPI

# Load API key from .env file
load_dotenv()
api = WindyAPI(api_key=os.getenv("WINDY_API_KEY"))

response = api.get_point_forecast(
    latitude=48.8566,
    longitude=2.3522,
    model="iconeu",  # Use ICON EU model for Europe
    parameters=["temp", "precip", "wind"]
)

Error Handling

from httpx import HTTPStatusError

try:
    response = api.get_point_forecast(
        latitude=37.7749,
        longitude=-122.4194,
        model="gfs",
        parameters=["temp"]
    )
except HTTPStatusError as e:
    print(f"API request failed: {e.response.status_code}")
    print(f"Response: {e.response.text}")
except ValueError as e:
    print(f"Invalid parameters: {e}")

Getting Your API Key

To use this library, you need a Windy API key. Visit Windy API to register and obtain your API key.

Contributing

See CONTRIBUTING.md for instructions on how to contribute.

License

Distributed under the terms of the MIT license.

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

windy_api-0.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

windy_api-0.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file windy_api-0.1.tar.gz.

File metadata

  • Download URL: windy_api-0.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for windy_api-0.1.tar.gz
Algorithm Hash digest
SHA256 0024135df57ab207c035c8ec3205162ad8e6a19f7d1979b42bc442b15e74b180
MD5 078845e571a8211a0a1a68204d33e7c4
BLAKE2b-256 886639af2d3711845a1d586a7e44f179d5e42b281e101b10939c5b4a08c39080

See more details on using hashes here.

Provenance

The following attestation bundles were made for windy_api-0.1.tar.gz:

Publisher: cd.yml on stedonnelly/windy-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file windy_api-0.1-py3-none-any.whl.

File metadata

  • Download URL: windy_api-0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for windy_api-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2450f8f60144a44e24abd4f604cbd844e23ffeba86e465e4dbfdd152b244dfd1
MD5 0d4f9eb38ac59e7ab35d540df0b412ec
BLAKE2b-256 99d0de551ac1e08af228a3e175d740602d8cb546bf47e76b8b4183968a97e21e

See more details on using hashes here.

Provenance

The following attestation bundles were made for windy_api-0.1-py3-none-any.whl:

Publisher: cd.yml on stedonnelly/windy-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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