Synchronous dictionary API client¶
Class for synchronous work with API client.
Requires httpx package to be installed.
- class freedictionaryapi.clients.sync_client.DictionaryApiClient(default_language_code: freedictionaryapi.languages.LanguageCodes = <LanguageCodes.ENGLISH_US: 'en_US'>, *, client: Optional[httpx.Client] = None)[source]¶
Bases:
freedictionaryapi.clients.base_sync_client.BaseDictionaryApiClientImplements synchronous dictionary API client.
Based on
httpx.Client.- property client: httpx.Client¶
- Returns
client used for making HTTP requests
- Return type
httpx.Client
- property default_language_code: freedictionaryapi.languages.LanguageCodes¶
- Returns
default client language code
- Return type
LanguageCodes
- fetch_api_response(url: str) → Tuple[int, Any][source]¶
Fetch data of the API response.
Implements abstract method for
syncclient withhttpx.Clientusage.- 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]
- fetch_json(word: str, language_code: Optional[freedictionaryapi.languages.LanguageCodes] = None) → Any¶
Fetch API JSON response that loaded in Python object (
response.json()).- Parameters
word (
str) – searched wordlanguage_code (
Optional[LanguageCodes]) – language of the searched word
- Returns
JSON response (supposed to be
listordict)- Return type
Any- Raise
- DictionaryApiError
when unsuccessful status code got of API request
- fetch_parser(word: str, language_code: Optional[freedictionaryapi.languages.LanguageCodes] = None) → freedictionaryapi.parsers.response_parser.DictionaryApiParser¶
Fetch dictionary API parser.
- Parameters
word (
str) – searched wordlanguage_code (
Optional[LanguageCodes]) – language of the searched word (word)
- Returns
dictionary API parser
- Return type
DictionaryApiParser
- fetch_word(word: str, language_code: Optional[freedictionaryapi.languages.LanguageCodes] = None) → freedictionaryapi.types.word.Word¶
Fetch word (
Word) - parsed object that has all word info.Shortcut for the
DictionaryApiParser.word.- Parameters
word (
str) – searched wordlanguage_code (
Optional[LanguageCodes]) – language of the searched word
- Returns
word (parsed object)
- Return type
Word