必须先申请 OWM API key,否则库无法工作;免费订阅的请求会被限流;付费接口需用 get_default_config_for_subscription_type 生成配置
pyowm
csparpaMIT长期未更新封装 OpenWeatherMap 天气 API 的 Python 库,用简洁的接口获取实时天气、预报和气象数据,省去手动处理 HTTP 请求和解析响应。
A Python wrapper around the OpenWeatherMap web API
pip install pyowmREADME 未说明,纯 Python 客户端库,无 GPU 或显存要求
封装 OpenWeatherMap 各类 Web API 的 Python 客户端库,用对象模型快速取天气数据
封装 OpenWeatherMap 天气 API 的 Python 库,用简洁的接口获取实时天气、预报和气象数据,省去手动处理 HTTP 请求和解析响应。
核心能力
- 用 weather_manager 按地名查询实况与预报
- 支持 OneCall API 作为 Dark Sky 的替代方案
- 覆盖空气质量、紫外线、土壤与卫星影像等 API
- 可创建气象站并发布本地观测数据
- 支持正反向地理编码与地图图层瓦片
容易踩的坑
- 3.5.0最新正式版2025-08-26 · 2025-08-26 22:34 UTC
Python Backwards-Incompatible Changes
- Drop support for Python 3.8, which has reached end-of-life status (2f60aa1)
Bug Fixes
- Separate One Call root URI and
HTTPClient(35c0feb)- This fixes an issue introduced in #444 where other weather APIs besides One Call also were switched to using a non-existent
3.0instead of2.5in their URI
- This fixes an issue introduced in #444 where other weather APIs besides One Call also were switched to using a non-existent
- Allow empty
senderanddescriptionstrings inNationalWeatherAlertinitialization (#399) - Fallback to
pathargument instead of empty string inHTTPClient.get_pngandHTTPClient.get_geotiff(#401) - Fix
sqlite3.OperationalErrorwithNamedTemporaryFileon Windows (#398) - Update
urllib3.util.Retryparameter name frommethod_whitelisttoallowed_methods(#437) - Correct
OWM.versionreturn type to tuple again instead of string (70ddaf5) - Correct types for forecast parameters for
OneCallinitialization (#400)
Misc
- 3.4.02025-08-22 · 2025-08-22 10:20 UTC
- 3.3.02022-02-14 · 2022-02-14 21:25 UTC
查看更新说明
New features
380 Implemented National Weather Alerts support 376 Now PyOWM uses SQLite instead of files to internally store city data.
CityIDRegistryinterface has changed but in a retrocompatible wayEnhancements
381 Now it is possible to specify how many times to retry an API call
Bugfixes
379 Experimental fix for
404errors on Agromonitor API satellite image search 387 Fixed lat/lon swap bug on Airpollution API 389 Fixed wrong city name in City ID database - 3.2.02021-02-24 · 2021-02-24 10:10 UTC
查看更新说明
-
New features
- Support for new AirPollution API encompassing current, historical and forecast air pollution indicators and air quality index
- Support for new Geocoding API
- Python 3.9 supported
- New matching method for
CityIDRegistry:startswith
-
Enhancements
- added probability of precipitation in OneCall API responses
-
Bugfixes
- fixed many typos in the documentation (code recipes)
-
Security
- Automatic fixes nailed by Dependabot
-
Deprecations introduced
- will be removed in version 4.0.0:
AirPollutionManager.coindex_around_coordsAirPollutionManager.ozone_around_coordsAirPollutionManager.no2index_around_coordsAirPollutionManager.so2index_around_coords
- will be removed in version 4.0.0:
-
- 3.1.1bis3.1.12020-10-02 · 2020-10-02 16:34 UTC
查看更新说明
What's new in Release 3.1.1
Bugfixes:
- Minutely rain data on OneCall calls were not read by PyOWM
- Fixed bugs in code recipes
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
PyOWM
A Python wrapper around OpenWeatherMap web APIs
What is it?
PyOWM is a client Python wrapper library for OpenWeatherMap (OWM) web APIs. It allows quick and easy consumption of OWM data from Python applications via a simple object model and in a human-friendly fashion.
PyOWM runs on Python 3.9+
Former Dark Sky API users: you can can use PyOWM to get OpenWeatherMap's OneCall API data as an easy replacement to Dark Sky
What kind of data can I get with PyOWM ?
With PyOWM you can integrate into your code any of the following OpenWeatherMap web APIs:
- Weather API v3.0 + OneCall API, providing current weather data, weather forecasts, weather history
- Agro API v1.0, providing soil data and satellite imagery search and download
- Air Pollution API v3.0, providing data about CO, O3, NO2 and SO2
- UV Index API v3.0, providing data about Ultraviolet exposition
- Stations API v3.0, allowing to create and manage meteostation and publish local weather measurements
- Weather Alerts API v3.0, allowing to set triggers on weather conditions and areas and poll for spawned alerts
- Image tiles for several map layers provided by OWM
- Geocoding API v1.0 allowing to perform direct/reverse geocoding
In case of trouble...
Please read the FAQ before filing a new issue on GitHub! There are many common issues, therefore a fix for your issue might come easier than you think
Get started
API key
As OpenWeatherMap APIs need a valid API key to allow responses, PyOWM won't work if you don't provide one. This stands for both free and paid (pro) subscription plans. You can signup for a free API key on the OWM website Please notice that the free API subscription plan is subject to requests throttling.
Example
With a free OWM API Key:
from pyowm import OWM
from pyowm.utils import config
from pyowm.utils import timestamps
# ---------- FREE API KEY examples ---------------------
owm = OWM('your free OWM API key')
mgr = owm.weather_manager()
# Search for current weather in London (Great Britain) and get details
observation = mgr.weather_at_place('London,GB')
w = observation.weather
w.detailed_status # 'clouds'
w.wind() # {'speed': 4.6, 'deg': 330}
w.humidity # 87
w.temperature('celsius') # {'temp_max': 10.5, 'temp': 9.7, 'temp_min': 9.0}
w.rain # {}
w.heat_index # None
w.clouds # 75
# Will it be clear tomorrow at this time in Milan (Italy) ?
forecast = mgr.forecast_at_place('Milan,IT', 'daily')
answer = forecast.will_be_clear_at(timestamps.tomorrow())
# ---------- PAID API KEY example ---------------------
config_dict = config.get_default_config_for_subscription_type('professional')
owm = OWM('your paid OWM API key', config_dict)
# What's the current humidity in Berlin (Germany) ?
one_call_object = mgr.one_call(lat=52.5244, lon=13.4105)
one_call_object.current.humidity
Installation
Install with pip for your ease:
$ pip install pyowm
There are alternatives: setuptools, Windows installers and common Linux package managers such as Yaourt (Arch Linux) YaST/Zypper (OpenSuse) (please refer to the documentation for more detail)
Eager to fetch the very latest updates to PyOWM? Install the development trunk (which might be unstable). Eg on Linux:
$ git clone https://github.com/csparpa/pyowm.git
$ cd pyowm && git checkout develop
$ pip install -r requirements.txt && python setup.py install
Documentation
The library software API documentation is available on Read the Docs.
The Code recipes section comes in handy!
Community & Contributing
Here are some cool projects that use PyOWM
Contributors (coding, testing, packaging, reporting issues) are welcome! See the the official documentation website for details.

