cwa
中央氣象署開放資料 API 的 Python SDK。
繁體中文 | English
輸入地名,就能取得鄉鎮預報、鄰近測站的即時觀測值及生效中的警特報。cwa 負責呼叫氣象署 API、驗證回應,並把資料整理成有型別的 Python 物件,不需要自己解析 JSON 或 XML。
安裝
需要 Python 3.13 以上版本。
pip install cwa
使用 uv 則執行 uv add cwa。匯出表格、座標比對等選用功能需要額外套件,見選用功能。
設定授權碼
至中央氣象署開放資料平臺申請授權碼,並設為環境變數 CWA_API_KEY:
# macOS、Linux
export CWA_API_KEY="授權碼"
# Windows PowerShell
$env:CWA_API_KEY = "授權碼"
範例
import cwa
w = cwa.weather.get("臺北市信義區")
if w.current: # 附近沒有符合條件的測站時為 None
print(w.current.station.name, w.current.temperature) # 信義 22.5
if w.tomorrow:
print(w.tomorrow.precipitation.max_probability) # 20
for alert in w.alerts:
print(alert.title)
功能
| 功能 | 說明 |
|---|---|
| 綜合天氣 | 一次取得預報、目前天氣及警特報 |
| 預報 | 一至七日鄉鎮預報,可依日期或時刻查詢 |
| 觀測值及測站 | 鄰近測站的即時觀測值、測站清單 |
| 警特報 | 依縣市、鄉鎮或座標篩選生效中的警特報 |
| 地震 | 有感地震報告、各地震度、震央距離 |
| 颱風 | 颱風位置及預測路徑 |
| 海嘯 | 海嘯報告、警報與解除通報 |
| 海象 | 一個月潮汐預報、浮標與潮位站觀測 |
| 天文 | 日出日沒、月出月沒 |
| 健康氣象 | 熱傷害、冷傷害與溫差提醒指數 |
| 氣候 | 每日氣候、雨量紀錄、氣候平均值、測站沿革、臭氧 |
| 批次查詢與匯出 | 一次查詢多個地點,匯出為 Polars、Pandas 或 Arrow 表格 |
| 用戶端與快取 | 重複使用連線、非同步查詢、記憶體快取 |
| 原始資料集 | 以資料集編號讀取 SDK 尚未包裝的資料 |
完整說明見文件網站。
貢獻
請見貢獻指南及變更紀錄。問題回報請至 GitHub Issues。
氣象資料來自中央氣象署開放資料平臺。cwa 為非官方套件,與中央氣象署無關。
cwa 以 MIT 授權釋出。
Metadata
Release files for cwa 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cwa-0.3.1.tar.gz | 79.3 kB | Without provenance | Details for cwa-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cwa-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for cwa-0.3.1-py3-none-any.whl |
Total release size: 173.6 kB
Release files / cwa-0.3.1.tar.gz
| Download URL | cwa-0.3.1.tar.gz |
|---|---|
| Size | 79.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8843081497a387aca03dba49f9a31808ad2a6315ec5c7d26235072574256b12c
|
|
BLAKE2b-256 checksum How to use checksums |
0d3e0209c832dbf8595771a475ba75dcd346e59b5ff7194c93afb1c787a58f60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cwa-0.3.1-py3-none-any.whl
| Download URL | cwa-0.3.1-py3-none-any.whl |
|---|---|
| Size | 94.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bed656c186c1080787babb8591bda0bc82ebc2a94ebf3ab102c75223977178c3
|
|
BLAKE2b-256 checksum How to use checksums |
1774b78fa2dc3226e225c034c674843c8c32ca8671233a6a0f4d8784efafedbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for cwa 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.