Yandex Weather API with asyncio support and typings
Project description
YaWeather | Yandex Weather API
☀️🌤🌧🌩❄️ 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
Release history Release notifications | RSS feed
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.1.5.tar.gz
(27.6 kB
view hashes)
Built Distribution
yaweather-1.1.5-py3-none-any.whl
(28.6 kB
view hashes)
Close
Hashes for yaweather-1.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4837eb33d4fe92f228a5a379d54dcf76cbc98d0ee23a44efd5f4f143a8b6afde |
|
MD5 | 3d9aa2f77a53d93bcd595f64d735544b |
|
BLAKE2b-256 | 9d92c6b9619f24df8e1dd7c08b733d36635658dc4f62a1f3a0c962b45211494e |