Skip to main content

Yandex Weather API with asyncio support and typings

Project description

YaWeather | Yandex Weather API

Python PyPI License: MIT

Build Status

☀️🌤🌧🌩❄️ Yandex Weather API wrapper with typings and asyncio support.

Docs: https://tech.yandex.com/weather/doc/dg/concepts/forecast-test-docpage (RU)

Get API Key: https://developer.tech.yandex.ru/services/18

📝 Table of Contents


🎒 Installation

Just

pip install yaweather

🛠 Examples

Simple

from yaweather import UnitedKingdom, YaWeather

y = YaWeather(api_key='secret')
res = y.forecast(UnitedKingdom.London)

print(f'Now: {res.fact.temp} °C, feels like {res.fact.feels_like} °C')
print(f'Condition: {res.fact.condition}')

Output:

Now: 18.0 °C, feels like 15.0 °C
Condition: cloudy

Simple Async

import asyncio

from yaweather import Russia, YaWeatherAsync


async def main():
    async with YaWeatherAsync(api_key='secret') as y:
        res = await y.forecast(Russia.Moscow)

        print(f'Now: {res.fact.temp} °C, feels like {res.fact.feels_like} °C')
        print(f'Condition: {res.fact.condition}')


asyncio.run(main())

Output:

Now: 16.0 °C, feels like 16.0 °C
Condition: clear

Forecasts

from yaweather import UnitedStates, YaWeather

y = YaWeather(api_key='secret')

res = y.forecast(UnitedStates.NewYork)

for f in res.forecasts:
    day = f.parts.day_short
    print(f'{f.date} | {day.temp} °C, {day.condition}')

Output:

2020-07-30 | 32.0 °C, cloudy
2020-07-31 | 26.0 °C, light-rain
2020-08-01 | 28.0 °C, cloudy
2020-08-02 | 28.0 °C, rain
2020-08-03 | 28.0 °C, light-rain
2020-08-04 | 27.0 °C, rain
2020-08-05 | 29.0 °C, light-rain

Forecasts Async

import asyncio

from yaweather import China, YaWeatherAsync


async def main():
    async with YaWeatherAsync(api_key='secret') as y:
        res = await y.forecast(China.Beijing)

        for f in res.forecasts:
            day = f.parts.day_short
            print(f'{f.date} | {day.temp} °C, {day.condition}')


asyncio.run(main())

Output:

2020-07-31 | 34.0 °C, light-rain
2020-08-01 | 34.0 °C, cloudy
2020-08-02 | 30.0 °C, heavy-rain
2020-08-03 | 33.0 °C, cloudy
2020-08-04 | 35.0 °C, cloudy
2020-08-05 | 34.0 °C, light-rain
2020-08-06 | 31.0 °C, heavy-rain

📜 Manual

Methods

API have one method:

  • forecast — request for the forecast, return type: ResponseForecast

Types

This library uses pydantic for parsing API responses. You can see data models in yaweather/models.

In case of unsupported types

API results can change and the library may not parse the new result. So you can request «raw» dicts:

raw_dict = y.forecast_raw(UnitedKingdom.London)

👨🏻‍💻 Author

Ramzan Bekbulatov:

💬 Contributing

Contributions, issues and feature requests are welcome!

📝 License

This project is MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yaweather-1.2.1.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

yaweather-1.2.1-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file yaweather-1.2.1.tar.gz.

File metadata

  • Download URL: yaweather-1.2.1.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for yaweather-1.2.1.tar.gz
Algorithm Hash digest
SHA256 098f1d23352057e6c4e06e0b86bdd87222137bb601f8b24b5320ef87354f0c2d
MD5 843db589ad6ad9f45ba47bd6cf4ea4d7
BLAKE2b-256 474a7d8489370bb3047295044a25cb966c114c6ea41bbcc276311f5d3403dc18

See more details on using hashes here.

File details

Details for the file yaweather-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: yaweather-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for yaweather-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e3345148b90fadc42c37ed72a184aee42d54b5a39447ad56485bcb9ee622919
MD5 134d7a14f9a41e01ae293d9a6d833678
BLAKE2b-256 383f08d0ac64bff69cb00cdd5985e1aab686efb05e8b8634032bde42a94b5a90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page