API Client
Google
Functions to interact with Google Maps API Client.
- 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 linked 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, fail_on_api_error=False)[source]
Validate an address using google’s address validation API.
- Parameters:
address_to_validate (
str) – address to validateclient (
Client) – client for Google Maps APIregion_code (
Optional[str]) – region to use for validation, optionallocality (
Optional[str]) – locality to use for validation, optionalenable_usps_cass (
bool) – whether to use USPS validationfail_on_api_error (
bool) – whether to raise an error if API call fails, or continue processing
- Return type:
- Returns:
toolbox address validation mapping
- Raises:
RuntimeError – if API key is invalid, or if API call fails and fail_on_api_error is True
- tamr_toolbox.enrichment.api_client.google_address_validate.get_empty_address_validation(input_addr)[source]
Get address validation data with only input address; other fields set to empty or default values.
Expiration date is set to the year 2100 to avoid excess called to the API with null or bad data.
- Parameters:
input_address – the address to be validated
- Return type:
- Returns:
A validation object with all fields except input_address and expiration set to null values.
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 languageclient (
Client) – location of the credentials JSON read by the google_api clientsource_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 automaticallytarget_language (
str) – the language to translate intotranslation_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 pairnum_of_tries (
int) – number of times to try to translate if the translation call fails
- Return type:
- Returns:
A toolbox translation dictionary. None if the translation failed