Client reference

class python_weather.client.Client(*, unit: ~enum.auto | None = <Unit [C, Kmph]>, locale: ~python_weather.enums.Locale | None = Locale.ENGLISH, session: ~aiohttp.client.ClientSession | None = None)

The class that lets you interact with the API.

Parameters:
  • unit (Optional[enum.auto]) – Whether to use the metric or imperial/customary system (IMPERIAL). Defaults to METRIC.

  • locale (Optional[Locale]) – Whether to use a different locale/language as the description for the returned forecast. Defaults to Locale.ENGLISH.

  • session (Optional[aiohttp.ClientSession]) – Whether to use an existing aiohttp client session for requesting or not. Defaults to None (creates a new one instead)

Raises:

Error – If the unit argument is not None and it’s also not METRIC or IMPERIAL, or if the locale argument is not None and it’s also not a part of the Locale enum.

async close()

Closes the Client object. Nothing will happen if it’s already closed.

async get(location: str, *, unit: auto | None = None, locale: Locale | None = None) Forecast

Fetches a weather forecast for a specific location.

Parameters:
  • location (str) – The requested location name for said weather forecast.

  • unit (Optional[enum.auto]) – Overrides the metric or imperial/customary system (IMPERIAL) used by the Client object. Defaults to None (uses the one from the Client).

  • locale (Optional[Locale]) – Overrides the locale/language used by the Client object. Defaults to None (uses the one from the Client).

Raises:

Error – If the aiohttp client session used by the Client object is already closed, if the unit argument is not None and it’s also not METRIC or IMPERIAL, if the locale argument is not None and it’s also not a part of the Locale enum, or if the Client cannot send a web request to the web server.

Returns:

The requested weather forecast.

Return type:

Forecast

property locale: Locale

The localization used to display information in this object.

property unit: auto

The measuring unit used to display information in this object.

class python_weather.enums.Locale

Represents the list of supported locales/languages by this library.

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.errors.Error

Represents a python_weather error class. Extends Exception.