Base client interface

Common client interface as for sync as for async engines.

class freedictionaryapi.clients.base_client_interface.BaseDictionaryApiClientInterface(default_language_code: freedictionaryapi.languages.LanguageCodes = <LanguageCodes.ENGLISH_US: 'en_US'>)[source]

Bases: abc.ABC

Implements base dictionary API client interface.

Abstract client interface that supposed to be inherited for sync and async base clients.

Here, interface:

Class that implements some useful API and makes sense in inheritance for other base clients that also must implement this base API but also provide some specific such concrete abstract methods.

So, for implementing of sync and async base clients base API is not repeated in code but provided with inheritance from this interface.

__init__(default_language_code: freedictionaryapi.languages.LanguageCodes = <LanguageCodes.ENGLISH_US: 'en_US'>)None[source]

Init base dictionary API client instance.

Parameters

default_language_code (LanguageCodes) – default language of the searched words for the client

Raise
TypeError

if has been passed unsupported default_language_code

static _analyze_response(url: str, status_code: int, response: Union[dict, list])Union[dict, list][source]

Analyze API response.

Do this:

  • log about response status (successful | unsuccessful);

  • raise correspond error if response is not successful.

Parameters
  • url (str) – URL that generated for API request

  • status_code (int) – response status code

  • response (Union[dict, list]) – API response that loaded in python object

Returns

passed response

Return type

Union[dict, list]

Raise
DictionaryApiError

when unsuccessful status code got of API request

_generate_url(word: str, language_code: Optional[freedictionaryapi.languages.LanguageCodes] = None)Tuple[str, freedictionaryapi.languages.LanguageCodes][source]

Generate URL for API request.

Parameters
  • word (str) – searched word

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

Returns

tuple of:

  • generated URL;

  • used language code.

Return type

Union[str, LanguageCodes]

property default_language_code: freedictionaryapi.languages.LanguageCodes
Returns

default client language code

Return type

LanguageCodes