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
⚠️ Warning: As a developer of this library, I recommend you not to use Yandex Weather API, here are some reasons:
- Incomplete responses even for metropolises — you can have a look to all
Optional
fields that I had to use in models, that means you should addNone
checks before access literally to any attribute - Bad official documentation — for example, I really had to parse html code of doc pages just because tables copying was broken
- Incomprehensible and big delay answers from support team
- Few requests available — 50 per day on free rate and 5000 per day for one test month
- Closed information about real prices that are accessible only via support team
Consider usage of OpenWeatherMap with 1 mln free requests every month and really good documentation which easy to understand and parse.
📝 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
Built Distribution
File details
Details for the file yaweather-1.2.2.tar.gz
.
File metadata
- Download URL: yaweather-1.2.2.tar.gz
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7527676772d212cf650f320b122f015e045e717796653e7c50aedd5de01791a |
|
MD5 | a7176fe080db490b31face1f6490aaea |
|
BLAKE2b-256 | 56810a01584c2007524f7b5586ce06c8261c8027e939497c84449d81f65df1b2 |
File details
Details for the file yaweather-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: yaweather-1.2.2-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a18c1a4122529850a16441354cfce18b4bc95f46fea42029fb2f6eef22d73ff0 |
|
MD5 | 97fbf1c432fe410502e5a1c715dbae37 |
|
BLAKE2b-256 | dacdf0fd43857f07a1fda479030dd82508cfe29b45624d4b0d35401322c8cfa4 |