Skip to Content
cwa
Guides

Forecasts

One- to seven-day township forecasts, by date or by time.

cwa.forecast.get() returns a township’s forecast for the next one to seven days. Read it day by day, or ask for a specific time or time range.

import cwa

forecast = cwa.forecast.get("臺北市信義區", days=7)

for day in forecast:
    condition = day.condition.description if day.condition else None
    print(day.date, day.temperature.min, day.temperature.max, condition)

days sets how many days of forecast to get, from 1 to 7, counting from today in Taiwan time. For example, days=3 gets today, tomorrow and the day after, and days=1 gets only today.

One day

WriteTo get
forecast.todayToday
forecast.tomorrowTomorrow
forecast.on(date(2026, 12, 1))A given date
forecast[0], forecast[-1]The first or last day, by position

today, tomorrow and on() return None when the forecast does not cover that day, so check first:

if forecast.tomorrow:
    print(forecast.tomorrow.precipitation.max_probability)

Daily fields

FieldMeaningNone when
dateThe Taiwan date
temperature.min, temperature.maxThe low and high published by the CWA (°C); see belowThe published periods do not cover the whole day, usually today
temperature.sampled_min, temperature.sampled_maxThe lowest and highest hourly temperature forecast during the day (°C)The day has no hourly forecast, i.e. it is beyond the three-day forecast
precipitation.max_probabilityThe highest probability of precipitation among the day’s periods (%)The day has no precipitation forecast
wind.max_speedThe day’s highest wind speed (m/s)The day has no wind forecast
conditionThe daytime (06:00–18:00) weather; condition.description is the textThe daytime period is over or unpublished, usually this evening
periodsEvery raw forecast period of the day; see Raw periods

Low versus sampled low

The two pairs come from different sources and suit different uses:

min, maxsampled_min, sampled_max
SourceThe CWA’s published 12-hour lows and highsHourly (or 3-hourly) temperature forecasts
Covers18:00 the evening before to 06:00 the next morning, slightly wider than the dateOnly times within the date
AvailableEvery day from tomorrow; today’s disappears once the daytime period endsDays the three-day forecast covers

The CWA publishes lows and highs for daytime (06:00–18:00) and night (18:00–06:00 the next day). The SDK takes every period covering the date, meaning the night before, the daytime and that night, to compute min and max. Because night periods cross midnight, min may come from late the evening before or early the next morning.

Use min and max for an everyday “today’s high and low”; use sampled_min and sampled_max for the rest of today, or when you need values strictly within the date.

Probability of precipitation

The CWA publishes the probability of precipitation for 3- or 12-hour periods, depending on the forecast. max_probability is the highest of the day’s periods: 20% in the morning and 60% in the afternoon gives 60. It means “the wettest period of the day”, not “the chance it rains at some point during the day”.

Wind lower bounds

Some wind speeds are published only as a lower bound, such as “11 m/s or more”. wind.max_speed_is_lower_bound is then True and max_speed holds the bound; the actual wind may be stronger.

At a given time

at() returns the forecast valid at one moment, and between() the forecast over a time range. A datetime without a timezone is taken as Taiwan time:

from datetime import datetime, timedelta

now = datetime.now()

forecast_at_time = forecast.at(now + timedelta(hours=3))
if forecast_at_time:
    for period in forecast_at_time.periods:
        print(period.element, period.sample.value)

tonight = forecast.between(now, now + timedelta(hours=12))
print(tonight.temperature.min(), tonight.temperature.max())
MethodReturnsWithout data
at(time)Every forecast period valid at that time, in at.periodsNone
between(start, end)The forecast overlapping that range, of the same type as forecast, readable day by dayA forecast with no days

Periods include their start and exclude their end: a 00:00–03:00 period applies at 00:00 but no longer at 03:00. between() keeps the original start and end of overlapping periods rather than trimming them.

forecast.temperature holds the point temperature forecasts and offers min(), max() and mean(). They skip missing values and return None when there are none.

Raw periods

periods lists every forecast the CWA published, for when you need an element the SDK does not summarize:

FieldMeaning
elementThe CWA element name, such as 溫度 or 3小時降雨機率
sample.valueThe value; a value published only as a lower bound is a LowerBound
sample.start, sample.endThe validity period; end is None for a forecast at a single instant
sample.sourceThis value’s data source

Many townships

Pass a county or a list to get results keyed by township, which you can also export as a table. See Batch queries and export.

County 36-hour forecast

cwa.forecast.county() returns a county’s forecast for the next 36 hours in three 12-hour periods:

county = cwa.forecast.county("臺北市")
for period in county.periods:
    print(period.start, period.condition, period.precipitation_probability, period.min_temperature, period.max_temperature, period.comfort)

A sequence of counties returns a mapping keyed by County; without an argument, every county is returned.