API reference¶
Wttr ¶
Wttr(
*,
base_url: AnyHttpUrl = build(
scheme="https", host="wttr.in"
),
session: ClientSession | None = None,
)
Asynchronous client for the wttr.in weather API.
Use it as an async context manager or call close when done.
Parameters:
-
base_url(AnyHttpUrl, default:build(scheme='https', host='wttr.in')) –Server to send requests to, e.g. a self-hosted wttr.in.
-
session(ClientSession | None, default:None) –HTTP client to send requests with. If
None, one is created on the first request, with a 60 s total timeout (5 s to connect).closecloses it either way.
Examples:
import asyncio
import aiopywttr
async def main() -> None:
async with aiopywttr.Wttr() as wttr:
weather = await wttr.weather("Paris")
asyncio.run(main())
weather async ¶
Get the current weather and a forecast for 3 days.
Raises aiohttp.ClientResponseError if wttr.in responds with an error status, e.g. for an unknown location.
Parameters:
-
location(str) –City, airport code,
~landmark,latitude,longitudeor anything else wttr.in accepts. -
language(Language, default:EN) –Language of the weather description. It also selects the return type, e.g.
Language.RUgivesaiopywttr.models.ru.Model.
Examples:
import asyncio
import aiopywttr
async def main() -> None:
async with aiopywttr.Wttr() as wttr:
weather = await wttr.weather("Paris", language=aiopywttr.Language.DE)
print(weather.current_condition[0].lang_de[0].value)
asyncio.run(main())
session property ¶
session: ClientSession | None
HTTP client; None until the first request if none was passed.
Language¶
Bases: StrEnum
Language of the weather description; values are wttr.in codes.
Examples:
Prefer the member: type checkers then know the exact response model.
language = Language.ZH_CN
language = Language["ZH_CN"]
language = Language("zh-cn")
Response models¶
Each language has its own module, such as aiopywttr.models.fr. Its CurrentConditionItem and HourlyItem add the translated description twice: as lang_fr and as lang_xx, which every language has.
Response models shared by all languages.
Model ¶
Bases: FrozenModel, Generic[_TCurrentConditionItem, _THourlyItem]
Weather at a location: now and for 3 days.
current_condition ¶
current_condition: tuple[_TCurrentConditionItem, ...]
Current weather, one item.
nearest_area ¶
nearest_area: tuple[NearestAreaItem, ...]
The area nearest to the location, one item.
weather ¶
weather: tuple[WeatherItem[_THourlyItem], ...]
Forecast for today, tomorrow and the day after.
CurrentConditionItem ¶
Bases: FrozenModel
Current weather.
WeatherItem ¶
HourlyItem ¶
Bases: FrozenModel
Forecast for a 3-hour slot.
AstronomyItem ¶
Bases: FrozenModel
Sun and moon for a day.
NearestAreaItem ¶
Bases: FrozenModel
The area nearest to the requested location.
weather_url ¶
weather_url: tuple[WeatherUrlItem, ...]
Forecast page on WorldWeatherOnline, one item.