> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Weather

> Get weather data and forecasts

The Weather tool lets an agent fetch current conditions, forecasts, and air-quality data.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Weather"
        User[User] --> Agent[Agent]
        Agent --> Tool[WeatherTool]
        Tool --> API[Weather API]
        API --> Result[Forecast]
    end

    classDef input fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class User,Agent input
    class Tool,API process
    class Result output
```

## Overview

Weather tool provides current weather, forecasts, and air quality data using various weather APIs.

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "praisonai[tools]"
```

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export OPENWEATHER_API_KEY="${OPENWEATHER_API_KEY:?Set OPENWEATHER_API_KEY in your shell}"
# Or
export WEATHERAPI_KEY="${WEATHERAPI_KEY:?Set WEATHERAPI_KEY in your shell}"
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai_tools import WeatherTool

    # Initialize
    weather = WeatherTool()

    # Get weather
    result = weather.get_weather("London")
    print(result)
    ```
  </Step>

  <Step title="With Configuration">
    Use the same tool with an agent — see **Usage with Agent** below, or pass env vars and options from the sections above.
  </Step>
</Steps>

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Weather as WeatherTool
    participant API as Weather API

    User->>Agent: "What's the weather in X"
    Agent->>Weather: get_weather(location)
    Weather->>API: HTTPS request
    API-->>Weather: conditions
    Weather-->>Agent: result
    Agent-->>User: final answer
```

## Usage with Agent

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonai_tools import WeatherTool

agent = Agent(
    name="WeatherBot",
    instructions="You provide weather information.",
    tools=[WeatherTool()]
)

response = agent.chat("What's the weather in New York?")
print(response)
```

## Available Methods

### get\_weather(location)

Get current weather.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai_tools import WeatherTool

weather = WeatherTool()
result = weather.get_weather("San Francisco")
```

### get\_forecast(location, days=3)

Get weather forecast.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
forecast = weather.get_forecast("Tokyo", days=5)
```

### get\_air\_quality(location)

Get air quality index.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
aqi = weather.get_air_quality("Beijing")
```

## Common Errors

| Error                    | Cause            | Solution                 |
| ------------------------ | ---------------- | ------------------------ |
| `API key not configured` | Missing key      | Set environment variable |
| `City not found`         | Invalid location | Check city name          |

## Best Practices

<AccordionGroup>
  <Accordion title="Keep the weather API key in the environment">
    Set `OPENWEATHER_API_KEY` or `WEATHERAPI_KEY` in your shell or `.env`. `WeatherTool()` reads it automatically — never hard-code the key.
  </Accordion>

  <Accordion title="Bound forecast length">
    `get_forecast(location, days=3)` defaults to 3 days. Request only the horizon the task needs to keep responses concise.
  </Accordion>

  <Accordion title="Handle unknown locations">
    Invalid city names return a "City not found" error. Wrap the call in `try/except` so the agent can ask the user to clarify the location.
  </Accordion>
</AccordionGroup>

## Related Tools

<CardGroup cols={2}>
  <Card title="Google Maps" icon="book" href="/docs/tools/external/google-maps">
    Location services
  </Card>
</CardGroup>
