Skip to main content

WeatherFlow4Py

A Python library for interacting with the WeatherFlow REST API and WebSocket services. This library provides both synchronous and asynchronous interfaces to access weather data from WeatherFlow weather stations.

PyPI Test PyPI

Features

  • REST API Client: Access station data, forecasts, and observations
  • WebSocket Client: Real-time weather data updates
  • Type Annotations: Full type support for better development experience
  • Asynchronous Support: Built with asyncio for efficient I/O operations
  • Pydantic Models: Strongly-typed data models for all API responses

Installation

pip install weatherflow4py

Or with uv:

uv pip install weatherflow4py

Prerequisites

Quick Start

REST API Example

import asyncio
from weatherflow4py.api import WeatherFlowRestAPI

async def main():
    # Initialize the API with your token
    async with WeatherFlowRestAPI("YOUR_API_TOKEN") as api:
        # Get all available stations
        stations = await api.async_get_stations()
        
        for station in stations.stations:
            print(f"Station: {station.name}")
            print(f"Location: {station.latitude}, {station.longitude}")
            
            # Get current observations
            obs = await api.async_get_observation(station.station_id)
            print(f"Current temperature: {obs.obs[0].air_temperature}°C")
            
            # Get forecast
            forecast = await api.async_get_forecast(station.station_id)
            print(f"Forecast high: {forecast.forecast.daily[0].air_temp_high}°C")

if __name__ == "__main__":
    asyncio.run(main())

WebSocket Example

import asyncio
import logging
from weatherflow4py.ws import WeatherFlowWebsocketAPI

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

async def main():
    # Initialize the WebSocket client
    ws = WeatherFlowWebsocketAPI("YOUR_API_TOKEN")
    
    # Define callback functions for different message types
    def handle_observation(data):
        print(f"Observation received - Temp: {data.air_temperature}°C")
    
    def handle_rapid_wind(data):
        print(f"Wind speed: {data.wind_speed} m/s at {data.wind_direction}°")
    
    # Register callbacks
    ws.register_callback("obs_st", handle_observation)
    ws.register_callback("rapid_wind", handle_rapid_wind)
    
    try:
        # Start listening for messages
        await ws.connect()
        
        # Start listening to all available devices
        await ws.start_listening()
        
        # Keep the connection alive
        while True:
            await asyncio.sleep(1)
            
    except KeyboardInterrupt:
        print("Disconnecting...")
    finally:
        await ws.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

API Documentation

REST API

The WeatherFlowRestAPI class provides the following methods:

  • async_get_stations(): Get all stations associated with the account
  • async_get_observation(station_id): Get current observations for a station
  • async_get_forecast(station_id): Get forecast data for a station
  • async_get_device_observations(device_id): Get observations from a specific device
  • get_all_data(): Get all available data for all stations

WebSocket API

The WeatherFlowWebsocketAPI class provides real-time updates:

  • connect(): Establish WebSocket connection
  • disconnect(): Close the connection
  • start_listening(device_ids=None): Start listening for updates
  • stop_listening(device_ids=None): Stop listening for updates
  • register_callback(message_type, callback): Register a callback for specific message types

Error Handling

The library raises specific exceptions for different error conditions:

  • TokenError: When no API token is provided
  • APIError: For general API errors
  • WebSocketError: For WebSocket connection issues

Rate Limiting

  • REST API: Limited to 100 requests per minute
  • WebSocket: Follows WeatherFlow's rate limiting policies

Resources

Development

This project uses uv for dependency management and virtual environment creation.

Setup with Nix

If you have Nix installed with flakes enabled:

# Enter the development environment
nix develop

# This will automatically:
# 1. Create a virtual environment with uv
# 2. Install dependencies from requirements.txt and requirements-dev.txt
# 3. Install the project in development mode

Manual Setup with uv

# Create a virtual environment
uv venv

# Activate the virtual environment
source .venv/bin/activate

# Install dependencies
uv pip install -r requirements.txt
uv pip install -r requirements-dev.txt

# Install the project in development mode
uv pip install -e .

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • WeatherFlow for their excellent weather station hardware and API
  • All contributors who have helped improve this library

Support

For support, please open an issue on the GitHub repository.

Download files

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

Source Distribution

weatherflow4py-1.5.10.tar.gz (145.5 kB view details)

Uploaded Source

Built Distribution

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

weatherflow4py-1.5.10-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file weatherflow4py-1.5.10.tar.gz.

File metadata

  • Download URL: weatherflow4py-1.5.10.tar.gz
  • Upload date:
  • Size: 145.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for weatherflow4py-1.5.10.tar.gz
Algorithm Hash digest
SHA256 706f7bb13401166b7c2b53c8d5a3341889cd38c3b5e5e01ce14626721a073bac
MD5 8d6d717c10682fd9c860d6a58c7ec644
BLAKE2b-256 2a93014d4e3f09f13e18bb02d63b8112978d4fbb845093768c6a5999e413c33a

See more details on using hashes here.

Provenance

The following attestation bundles were made for weatherflow4py-1.5.10.tar.gz:

Publisher: release.yml on jeeftor/weatherflow4py

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

File details

Details for the file weatherflow4py-1.5.10-py3-none-any.whl.

File metadata

  • Download URL: weatherflow4py-1.5.10-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for weatherflow4py-1.5.10-py3-none-any.whl
Algorithm Hash digest
SHA256 3e6a2ca01ee68b9bd97dc7c09cf1c411e7da624232d7462c7f3acc06b3cc7877
MD5 0598bea62843090248ec46a5b483b6bf
BLAKE2b-256 0fa20829dd59be9775def7ddeec8e24ecec1a45f034336b0f136907b201093d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for weatherflow4py-1.5.10-py3-none-any.whl:

Publisher: release.yml on jeeftor/weatherflow4py

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

Release history Release notifications | RSS feed

This release

1.5.10 This release

2 files

1.5.8

2 files

1.5.7

2 files

1.5.4

2 files

1.5.2

2 files

1.4.1

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.20

2 files

1.1.18

2 files

1.1.16

2 files

1.1.14

2 files

1.1.13

2 files

1.1.12

2 files

1.1.11

2 files

1.1.10

2 files

1.1.9

2 files

1.1.8

2 files

1.1.7

2 files

1.1.6

2 files

1.1.5

2 files

1.1.1

2 files

1.1.0

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.23

2 files

0.2.22

2 files

0.2.21

2 files

0.2.20

2 files

0.2.18

2 files

0.2.17

2 files

0.2.16

2 files

0.2.15

2 files

0.2.14

2 files

0.2.13

2 files

0.2.10

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.2

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

Supported by

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