pyowm

csparpaMIT长期未更新

封装 OpenWeatherMap 天气 API 的 Python 库,用简洁的接口获取实时天气、预报和气象数据,省去手动处理 HTTP 请求和解析响应。

A Python wrapper around the OpenWeatherMap web API

3.5.0发布于 2025-08-26 22:34 UTC812star172fork同步于 2026-11-07 07:32 UTC

怎么上手

由 README 提炼,执行前请确认
pip install pyowm
硬件要求按 README 说明

README 未说明,纯 Python 客户端库,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

封装 OpenWeatherMap 各类 Web API 的 Python 客户端库,用对象模型快速取天气数据

封装 OpenWeatherMap 天气 API 的 Python 库,用简洁的接口获取实时天气、预报和气象数据,省去手动处理 HTTP 请求和解析响应。

核心能力

  • 用 weather_manager 按地名查询实况与预报
  • 支持 OneCall API 作为 Dark Sky 的替代方案
  • 覆盖空气质量、紫外线、土壤与卫星影像等 API
  • 可创建气象站并发布本地观测数据
  • 支持正反向地理编码与地图图层瓦片

容易踩的坑

必须先申请 OWM API key,否则库无法工作;免费订阅的请求会被限流;付费接口需用 get_default_config_for_subscription_type 生成配置

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本3.5.0
  1. 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.0 instead of 2.5 in their URI
    • Allow empty sender and description strings in NationalWeatherAlert initialization (#399)
    • Fallback to path argument instead of empty string in HTTPClient.get_png and HTTPClient.get_geotiff (#401)
    • Fix sqlite3.OperationalError with NamedTemporaryFile on Windows (#398)
    • Update urllib3.util.Retry parameter name from method_whitelist to allowed_methods (#437)
    • Correct OWM.version return type to tuple again instead of string (70ddaf5)
    • Correct types for forecast parameters for OneCall initialization (#400)

    Misc

    • Replace pkg_resources usage with importlib.resources functions (#435)
    • Remove print in Tile.bounding_polygon (9d2076b)
    • Remove old build and publish scripts (971004c)
    • Correct grammar in timeout error message for HTTPClient.get_json (#396)
    • Update and improve various documentation and tests
  2. 3.4.02025-08-22 · 2025-08-22 10:20 UTC
    查看更新说明

    New Features

    • Document support for Python 3.10, 3.11, 3.12, and 3.13 (f0938be)
    • Add support for geojson >= 3, < 4 (#415)

    API Backwards-Incompatible Changes

    • Update to use One Call API 3.0, as One Call API 2.5 has been deprecated (#404, #444)

    Python Backwards-Incompatible Changes

    • Drop support for Python 3.7, which has reached end-of-life status (087bffe)

    Misc

    • Replace old Slack workspace with GitHub Discussions (1234289)
    • Remove PYOWM_VERSION constant (05f227f)
    • Remove version_tuple_to_str utility function (2082a3f)
    • Use GitHub Actions workflow to publish to PyPI (ef26046)
  3. 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. CityIDRegistry interface has changed but in a retrocompatible way

    Enhancements

    381 Now it is possible to specify how many times to retry an API call

    Bugfixes

    379 Experimental fix for 404 errors on Agromonitor API satellite image search 387 Fixed lat/lon swap bug on Airpollution API 389 Fixed wrong city name in City ID database

  4. 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_coords
        • AirPollutionManager.ozone_around_coords
        • AirPollutionManager.no2index_around_coords
        • AirPollutionManager.so2index_around_coords
  5. 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

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    logo

    PyOWM

    A Python wrapper around OpenWeatherMap web APIs

    PyPI version PyPI - Downloads PyPI - Python Version Latest Release Documentation Build Status Coverage Status Say Thanks!

    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.

    License

    MIT license