Asynchronous dictionary API client

Class for asynchronous work with API client.

Requires aiohttp package to be installed.

class freedictionaryapi.clients.async_client.AsyncDictionaryApiClient(default_language_code: freedictionaryapi.languages.LanguageCodes = <LanguageCodes.ENGLISH_US: 'en_US'>, *, session: Optional[aiohttp.client.ClientSession] = None)[source]

Bases: freedictionaryapi.clients.base_async_client.BaseAsyncDictionaryApiClient

Implements asynchronous dictionary API client.

Based on aiohttp.ClientSession.

async close()None[source]

Close dictionary API client.

Returns

None

Return type

None

property default_language_code: freedictionaryapi.languages.LanguageCodes
Returns

default client language code

Return type

LanguageCodes

async fetch_api_response(url: str)Tuple[int, Any][source]

Fetch data of the API response.

Implements abstract method for async client with aiohttp.ClientSession usage.

Parameters

url (str) – url that is generated by input params in invoked function

Returns

tuple of:

  • response status code;

  • python object loaded from API response with JSON decoding.

Return type

tuple[int, Any]

async fetch_json(word: str, language_code: Optional[freedictionaryapi.languages.LanguageCodes] = None)Any

Fetch API json response that loaded in Python object (await response.json()).

Parameters
  • word (str) – searched word

  • language_code (Optional[LanguageCodes]) – language of the searched word

Returns

JSON response (supposed to be list or dict)

Return type

Any

Raise
DictionaryApiError

when unsuccessful status code got of API request

async fetch_parser(word: str, language_code: Optional[freedictionaryapi.languages.LanguageCodes] = None)freedictionaryapi.parsers.response_parser.DictionaryApiParser

Fetch dictionary API parser.

Parameters
  • word (str) – searched word

  • language_code (Optional[LanguageCodes]) – language of the searched word (word)

Returns

dictionary API parser

Return type

DictionaryApiParser

async fetch_word(word: str, language_code: Optional[freedictionaryapi.languages.LanguageCodes] = None)freedictionaryapi.types.word.Word

Fetch word - parsed object that has all word info.

Shortcut for the DictionaryApiParser.word.

Parameters
  • word (str) – searched word

  • language_code (Optional[LanguageCodes]) – language of the searched word

Returns

word (parsed object)

Return type

Word

property session: aiohttp.client.ClientSession
Returns

session used for making HTTP requests

Return type

aiohttp.ClientSession