aiopywttr¶
Welcome to the documentation of aiopywttr, the asynchronous wrapper for the wttr.in weather API!
Synchronous version here.
Installation¶
The latest version can be installed with the following command:
pip install -U aiopywttr pywttr-models
API Reference¶
Asynchronous wrapper for wttr.in weather API.
Examples:
Choose language. First option is preferred because of type safety.
language = aiopywttr.Language.ZH_CN
language = aiopywttr.Language["ZH_CN"]
language = aiopywttr.Language("zh-cn")
Print the average temperature in Paris today:
async with aiopywttr.Wttr() as wttr:
weather = await wttr.weather("Paris", language=language)
print(weather.weather[0].avgtemp_c)
Custom base url:
async with aiopywttr.Wttr(
base_url=pydantic.AnyHttpUrl("https://example.com")
) as wttr:
...
Custom aiohttp.ClientSession:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=60, connect=5)
) as session:
wttr = aiopywttr.Wttr(session=session)
...
Language ¶
Bases: StrEnum
StrEnum of languages supported by wttr.in.
Examples:
First option is preferred because of type safety.
language = Language.ZH_CN
language = Language["ZH_CN"]
language = Language("zh-cn")
Wttr ¶
Wttr(
*,
base_url: AnyHttpUrl = build(
scheme="https", host="wttr.in"
),
session: ClientSession | None = None,
)
Asynchronous wrapper for wttr.in weather API.
Examples:
Choose language. First option is preferred because of type safety.
language = aiopywttr.Language.ZH_CN
language = aiopywttr.Language["ZH_CN"]
language = aiopywttr.Language("zh-cn")
Print the average temperature in Paris today:
async with aiopywttr.Wttr() as wttr:
weather = await wttr.weather("Paris", language=language)
print(weather.weather[0].avgtemp_c)
Custom base url:
async with aiopywttr.Wttr(
base_url=pydantic.AnyHttpUrl("https://example.com")
) as wttr:
...
Custom aiohttp.ClientSession:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=60, connect=5)
) as session:
wttr = aiopywttr.Wttr(session=session)
...
weather async ¶
Asynchronous wrapper for wttr.in weather API.
Examples:
Choose language. First option is preferred because of type safety.
language = aiopywttr.Language.ZH_CN
language = aiopywttr.Language["ZH_CN"]
language = aiopywttr.Language("zh-cn")
Print the average temperature in Paris today:
async with aiopywttr.Wttr() as wttr:
weather = await wttr.weather("Paris", language=language)
print(weather.weather[0].avgtemp_c)
Custom base url:
async with aiopywttr.Wttr(
base_url=pydantic.AnyHttpUrl("https://example.com")
) as wttr:
...
Custom aiohttp.ClientSession:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=60, connect=5)
) as session:
wttr = aiopywttr.Wttr(session=session)
...
models ¶
Internal library for pywttr and aiopywttr.
AnyModel module-attribute ¶
AnyModel: TypeAlias = (
af.Model
| am.Model
| ar.Model
| be.Model
| bn.Model
| ca.Model
| da.Model
| de.Model
| el.Model
| en.Model
| et.Model
| fa.Model
| fr.Model
| gl.Model
| hi.Model
| hu.Model
| ia.Model
| id.Model
| it.Model
| lt.Model
| mg.Model
| nb.Model
| nl.Model
| oc.Model
| pl.Model
| pt_br.Model
| ro.Model
| ru.Model
| ta.Model
| th.Model
| tr.Model
| uk.Model
| vi.Model
| zh_cn.Model
| zh_tw.Model
)
base ¶
CurrentConditionItem ¶
Bases: FrozenModel
precip_inches class-attribute instance-attribute ¶
pressure_inches class-attribute instance-attribute ¶
visibility_miles class-attribute instance-attribute ¶
weather_desc class-attribute instance-attribute ¶
weather_desc: tuple[WeatherDescItem, ...] = Field(
alias="weatherDesc"
)
weather_icon_url class-attribute instance-attribute ¶
weather_icon_url: tuple[WeatherIconUrlItem, ...] = Field(
alias="weatherIconUrl"
)
winddir16_point class-attribute instance-attribute ¶
winddir_degree class-attribute instance-attribute ¶
windspeed_kmph class-attribute instance-attribute ¶
NearestAreaItem ¶
Bases: FrozenModel
area_name class-attribute instance-attribute ¶
area_name: tuple[AreaNameItem, ...] = Field(
alias="areaName"
)
weather_url class-attribute instance-attribute ¶
weather_url: tuple[WeatherUrlItem, ...] = Field(
alias="weatherUrl"
)
RequestItem ¶
AstronomyItem ¶
HourlyItem ¶
Bases: FrozenModel
wind_gust_kmph class-attribute instance-attribute ¶
wind_gust_miles class-attribute instance-attribute ¶
precip_inches class-attribute instance-attribute ¶
pressure_inches class-attribute instance-attribute ¶
visibility_miles class-attribute instance-attribute ¶
weather_desc class-attribute instance-attribute ¶
weather_desc: tuple[WeatherDescItem, ...] = Field(
alias="weatherDesc"
)
weather_icon_url class-attribute instance-attribute ¶
weather_icon_url: tuple[WeatherIconUrlItem, ...] = Field(
alias="weatherIconUrl"
)
winddir16_point class-attribute instance-attribute ¶
winddir_degree class-attribute instance-attribute ¶
windspeed_kmph class-attribute instance-attribute ¶
WeatherItem ¶
en ¶
CurrentConditionItem ¶
Bases: CurrentConditionItem
HourlyItem ¶
Bases: HourlyItem
pt_br ¶
CurrentConditionItem ¶
Bases: CurrentConditionItem
lang_pt_br class-attribute instance-attribute ¶
lang_pt_br: tuple[WeatherDescItem, ...] = Field(
alias="lang_pt-br"
)
HourlyItem ¶
Bases: HourlyItem
lang_pt_br class-attribute instance-attribute ¶
lang_pt_br: tuple[WeatherDescItem, ...] = Field(
alias="lang_pt-br"
)
zh_cn ¶
CurrentConditionItem ¶
Bases: CurrentConditionItem
lang_zh_cn class-attribute instance-attribute ¶
lang_zh_cn: tuple[WeatherDescItem, ...] = Field(
alias="lang_zh-cn"
)
HourlyItem ¶
Bases: HourlyItem
lang_zh_cn class-attribute instance-attribute ¶
lang_zh_cn: tuple[WeatherDescItem, ...] = Field(
alias="lang_zh-cn"
)
zh_tw ¶
CurrentConditionItem ¶
Bases: CurrentConditionItem
lang_zh_tw class-attribute instance-attribute ¶
lang_zh_tw: tuple[WeatherDescItem, ...] = Field(
alias="lang_zh-tw"
)
HourlyItem ¶
Bases: HourlyItem
lang_zh_tw class-attribute instance-attribute ¶
lang_zh_tw: tuple[WeatherDescItem, ...] = Field(
alias="lang_zh-tw"
)