# Quick start (https://nolantw.github.io/cwa/en/)

cwa lets you query Taiwan's Central Weather Administration (CWA) open data by place name. This page walks you through installing it, setting your API key and getting the weather for one township.

## Installation

Requires Python 3.13 or later.

```shell
pip install cwa
```

With uv, run `uv add cwa`.

### Optional features

The base install covers every query. The features below need extra packages, installed as `pip install "cwa[polars]"`:

| Extra | Adds | Without it |
| --- | --- | --- |
| `cwa[polars]` | `to_polars()` export | The call raises `MissingDependencyError` |
| `cwa[pandas]` | `to_pandas()` export | The call raises `MissingDependencyError` |
| `cwa[arrow]` | `to_arrow()` export | The call raises `MissingDependencyError` |
| `cwa[geo]` | Matching warning areas against coordinates | Warning queries by coordinates raise `MissingDependencyError`; queries by county or township still work |
| `cwa[fast]` | Distances computed with PyProj, tens of times faster for many points | GeographicLib is used instead, with the same results |
| `cwa[all]` | All of the above | |

## API key

Apply for an API key on the [CWA Open Data platform](https://opendata.cwa.gov.tw/user/authkey). The SDK reads it from the `CWA_API_KEY` environment variable:

```shell
# macOS, Linux
export CWA_API_KEY="api-key"
```

```powershell
# Windows PowerShell
$env:CWA_API_KEY = "api-key"
```

If the key comes from a config file or a secrets manager and an environment variable is inconvenient, pass it when you create a client. Module functions such as `cwa.weather.get()` read only the environment variable, so use a client in that case:

```python
from cwa import CWA

with CWA(api_key="api-key") as client:
    weather = client.weather.get("臺北市信義區")
```

See [Clients and caching](/en/advanced/clients) for what else a client does.

## First query

`cwa.weather.get()` returns a township's forecast, current conditions and active warnings in one call:

```python
import cwa

weather = cwa.weather.get("臺北市信義區")

if weather.current:
    print(weather.current.station.name, weather.current.temperature)
if weather.tomorrow:
    print(weather.tomorrow.temperature.max, weather.tomorrow.precipitation.max_probability)
for alert in weather.alerts:
    print(alert.title)
```

| Field | Contains | When it is `None` |
| --- | --- | --- |
| `current` | The latest reading from a nearby station | No station within 10 km has a reading from the last two hours |
| `today`, `tomorrow` | The forecasts for today and tomorrow | The forecast does not cover that day |
| `alerts` | Warnings affecting this township; loop over it with `for` | Never; it is empty when there are no warnings |

Check fields that can be `None` with `if` before using them, as above. See [Weather snapshots](/en/guides/weather) for every field.

## Next steps

| To | Read |
| --- | --- |
| Use short names, constants or coordinates | [Locations](/en/guides/locations) |
| Get a week of forecasts, or the forecast at a given time | [Forecasts](/en/guides/forecast) |
| Read nearby station observations | [Observations and stations](/en/guides/observations) |
| Filter warnings and check whether they affect a place | [Warnings](/en/guides/alerts) |
| Query earthquakes and typhoons | [Earthquakes](/en/guides/earthquakes), [Typhoons](/en/guides/typhoons), [Tsunamis](/en/guides/tsunamis) |
| Query marine, astronomy, health and climate data | [Marine](/en/guides/marine), [Astronomy](/en/guides/astronomy), [Health weather](/en/guides/health), [Climate](/en/guides/climate) |
| Query many places at once and export tables | [Batch queries and export](/en/advanced/batch) |
| Learn the rules for time, units and missing values | [Data notes](/en/reading) |