Client reference¶
- class python_weather.client.Client(*, unit: _Unit = <Unit [C, Kmph]>, locale: Locale = Locale.ENGLISH, session: ClientSession | None = None, max_retries: int = 3)¶
Interact with the API’s endpoints.
Examples:
# Explicit cleanup client = python_weather.Client(unit=python_weather.IMPERIAL) # ... await client.close() # Implicit cleanup async with python_weather.Client(unit=python_weather.IMPERIAL) as client: # ...
- Parameters:
unit (
_Unit) – Whether to use the metric or imperial/customary system (IMPERIAL). Defaults toMETRIC.locale (
Locale) – Whether to use a different locale/language as the description for the returned forecast. Defaults toLocale.ENGLISH.session (
ClientSession|None) – Whether to use an existingClientSessionfor requesting or not. Defaults toNone(creates a new one instead).max_retries (
int|None) – Maximum amount of retries upon request failure before raising aRequestError. Use-1to disable (NOT recommended). Defaults to 3 retries.
- Raises:
Error –
unitis notMETRICorIMPERIALorlocaleis not a part of theLocaleenum.
- async get(location: str, *, unit: _Unit | None = None, locale: Locale | None = None) Forecast¶
Fetches a weather forecast for a specific location.
Example:
weather = await client.get('New York')
- Parameters:
- Raises:
TypeError – The specified location is not a string.
ValueError – The specified location is empty.
Error – The client is already closed.
RequestError – The client received a non-favorable response from the API.
- Returns:
The requested weather forecast.
- Return type:
- property unit: _Unit¶
The measuring unit used.
- class python_weather.enums.Locale¶
A supported locale.
- AFRIKAANS = 'af'¶
- AMHARIC = 'am'¶
- ARABIC = 'ar'¶
- ARMENIAN = 'hy'¶
- AZERBAIJANI = 'az'¶
- BANGLA = 'bn'¶
- BASQUE = 'eu'¶
- BELARUSIAN = 'be'¶
- BOSNIAN = 'bs'¶
- BULGARIAN = 'bg'¶
- CATALAN = 'ca'¶
- CHINESE_SIMPLIFIED = 'zh'¶
- CHINESE_SIMPLIFIED_CHINA = 'zh-cn'¶
- CHINESE_TRADITIONAL_TAIWAN = 'zh-tw'¶
- CROATIAN = 'hr'¶
- CZECH = 'cs'¶
- DANISH = 'da'¶
- DUTCH = 'nl'¶
- ENGLISH = 'en'¶
- ESPERANTO = 'eo'¶
- ESTONIAN = 'et'¶
- FINNISH = 'fi'¶
- FRENCH = 'fr'¶
- FRISIAN = 'fy'¶
- GALICIAN = 'gl'¶
- GEORGIAN = 'ka'¶
- GERMAN = 'de'¶
- GREEK = 'el'¶
- HINDI = 'hi'¶
- HIRI_MOTU = 'ho'¶
- HUNGARIAN = 'hu'¶
- ICELANDIC = 'is'¶
- INDONESIAN = 'id'¶
- INTERLINGUA = 'ia'¶
- IRISH = 'ga'¶
- ITALIAN = 'it'¶
- JAPANESE = 'ja'¶
- JAVANESE = 'jv'¶
- KAZAKH = 'kk'¶
- KISWAHILI = 'sw'¶
- KOREAN = 'ko'¶
- KYRGYZ = 'ky'¶
- LATVIAN = 'lv'¶
- LITHUANIAN = 'lt'¶
- MACEDONIAN = 'mk'¶
- MALAGASY = 'mg'¶
- MALAYALAM = 'ml'¶
- MARATHI = 'mr'¶
- NORWEGIAN_BOKMAL = 'nb'¶
- NORWEGIAN_NYNORSK = 'nn'¶
- OCCITAN = 'oc'¶
- PERSIAN = 'fa'¶
- POLISH = 'pl'¶
- PORTUGUESE = 'pt'¶
- PORTUGUESE_BRAZIL = 'pt-br'¶
- ROMANIAN = 'ro'¶
- RUSSIAN = 'ru'¶
- SERBIAN = 'sr'¶
- SERBIAN_LATIN = 'sr-lat'¶
- SLOVAK = 'sk'¶
- SLOVENIAN = 'sl'¶
- SPANISH = 'es'¶
- SWEDISH = 'sv'¶
- TAMIL = 'ta'¶
- TELUGU = 'te'¶
- THAI = 'th'¶
- TURKISH = 'tr'¶
- UKRAINIAN = 'uk'¶
- UZBEK = 'uz'¶
- VIETNAMESE = 'vi'¶
- WELSH = 'cy'¶
- ZULU = 'zu'¶
- class python_weather.client.Client(*, unit: _Unit = <Unit [C, Kmph]>, locale: Locale = Locale.ENGLISH, session: ClientSession | None = None, max_retries: int = 3)
Interact with the API’s endpoints.
Examples:
# Explicit cleanup client = python_weather.Client(unit=python_weather.IMPERIAL) # ... await client.close() # Implicit cleanup async with python_weather.Client(unit=python_weather.IMPERIAL) as client: # ...
- Parameters:
unit (
_Unit) – Whether to use the metric or imperial/customary system (IMPERIAL). Defaults toMETRIC.locale (
Locale) – Whether to use a different locale/language as the description for the returned forecast. Defaults toLocale.ENGLISH.session (
ClientSession|None) – Whether to use an existingClientSessionfor requesting or not. Defaults toNone(creates a new one instead).max_retries (
int|None) – Maximum amount of retries upon request failure before raising aRequestError. Use-1to disable (NOT recommended). Defaults to 3 retries.
- Raises:
Error –
unitis notMETRICorIMPERIALorlocaleis not a part of theLocaleenum.
- async close() None
Closes the client.
Example:
await client.close()
- async get(location: str, *, unit: _Unit | None = None, locale: Locale | None = None) Forecast
Fetches a weather forecast for a specific location.
Example:
weather = await client.get('New York')
- Parameters:
- Raises:
TypeError – The specified location is not a string.
ValueError – The specified location is empty.
Error – The client is already closed.
RequestError – The client received a non-favorable response from the API.
- Returns:
The requested weather forecast.
- Return type:
- property locale: Locale
The localization used.
- property unit: _Unit
The measuring unit used.
- python_weather.constants.METRIC = <Unit [C, Kmph]>¶
A supported measurement unit.
- python_weather.constants.IMPERIAL = <Unit [F, Miles]>¶
A supported measurement unit.