Skip to Content
cwa
Guides

Weather snapshots

A township's forecast, current conditions and warnings in one call.

cwa.weather.get() returns the three things most often needed for a township in one call: the forecast, current conditions from a nearby station and the active warnings. For a weather app or notifications, this is usually all you need.

import cwa

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

if weather.current:
    print("Now", weather.current.temperature)
if weather.today:
    print("Chance of rain today", weather.today.precipitation.max_probability)
for alert in weather.alerts:
    print(alert.title)

days works as in Forecasts and defaults to 7.

FieldContainsDetails
locationThe queried townshipLocations
as_ofQuery time
currentCurrent conditions, see below; None when no station qualifiesObservations and stations
forecastThe full forecastForecasts
today, tomorrowThe forecasts for today and tomorrow, same as forecast.today and forecast.tomorrow; None when not coveredForecasts
alertsWarnings affecting this township; loop over it with forWarnings

Current weather

current comes from the nearest station within 10 km that has a reading from the last two hours. That station may be in a neighboring township.

These fields are available directly on current:

FieldDescription
current.stationThe reporting station, for example current.station.name
current.distance_kmDistance from the station to the township’s reference point (km)
current.observed_atObservation time
current.temperatureAir temperature (°C)

Humidity, pressure, wind, rainfall and the weather condition are in current.observation:

if weather.current:
    observation = weather.current.observation
    print(observation.humidity, observation.pressure, observation.wind.speed, observation.precipitation.millimetres)

See Observation fields for each field’s unit and what a missing value means. To change the distance or time limits, use cwa.observations.nearest() instead.

Many townships

Pass a county or a list to get results keyed by township; get_all() covers every township in Taiwan. See Batch queries and export.