API Client

Google

tamr_toolbox.enrichment.api_client.google_address_validate.get_maps_client(googlemaps_api_key)[source]

Get GoogleMaps client.

Parameters

googlemaps_api_key (str) – API key for the Google Maps address validation API

Return type

Client

Returns

API client linekd to specified key

tamr_toolbox.enrichment.api_client.google_address_validate.validate(*, address_to_validate, client, locality=None, region_code=None, enable_usps_cass=False)[source]

Validate an address using google’s address validation API.

Parameters
  • address_to_validate (str) – address to validate

  • client (Client) – client for Google Maps API

  • region_code (Optional[str]) – region to use for validation, optional

  • locality (Optional[str]) – locality to use for validation, optional

  • enable_usps_cass (bool) – whether to use USPS validation

Return type

Optional[AddressValidationMapping]

Returns

toolbox address validation mapping, or None if API call fails

Raises

RuntimeError – if API key is invalid

Tasks related to translating data with the google translation API

tamr_toolbox.enrichment.api_client.google_translate.translation_client_from_json(json_credential_path)[source]

Returns a Google translation client based on credentials stored in a Google credential json file

Parameters

json_credential_path (str) – path to the google credential json file

Return type

Client

Returns

A Google Translate Client

tamr_toolbox.enrichment.api_client.google_translate.translate(phrases_to_translate, client, *, source_language='auto', target_language='en', translation_model='nmt', num_of_tries=4)[source]

Translate a list of text to a target language using google’s translation api

Parameters
  • phrases_to_translate (List[str]) – list of phrases to translate from the source language to the target language

  • client (Client) – location of the credentials JSON read by the google_api client

  • source_language (str) – the language the text to translate is in, “auto” means the api_client google_api api_client will try to detect the source language automatically

  • target_language (str) – the language to translate into

  • translation_model (str) – google_api api_client api_client model to use, “nmt” or “pbmt”. Choose “pbmt” if an “nmt” model doesn’t exists for your source to target language pair

  • num_of_tries (int) – number of times to try to translate if the translation call fails

Return type

Optional[Dict[str, TranslationDictionary]]

Returns

A toolbox translation dictionary. None if the translation failed