Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
☀️🌤🌧🌩❄️ 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
⚠️ Warning: As a developer of this library, I recommend you not to use Yandex Weather API, here are some reasons:
Optional
fields that I had to use in models, that means you should add None
checks before access literally to any attributeConsider usage of OpenWeatherMap with 1 mln free requests every month and really good documentation which easy to understand and parse.
Just
pip install yaweather
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
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
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
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
API have one method:
forecast
— request for the forecast, return type: ResponseForecast
This library uses pydantic for parsing API responses. You can see data models in yaweather/models.
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)
Ramzan Bekbulatov:
Contributions, issues and feature requests are welcome!
This project is MIT licensed.
FAQs
Yandex Weather API with asyncio support and typings
We found that yaweather demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.