Normalize a Street Address in Python
If you’re managing street-address data in your application, it’s essential to structure the components of that data with relevant, specific formatting, or each individual piece of information will lose its context. The Cloudmersive Validate API is capable of doing that for you — it’ll normalize an input street address, let you know if it’s valid or not, and even return the latitude & longitude of the address (if valid originally). In this article we’ll walk through how you can use this API in Python.
To connect with this API, the first step is to install the Python SDK using the below snippet:
pip install cloudmersive-validate-api-clientfrom __future__ import print_function
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint
Following that, you can authorize your API key within the following code:
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
If you don’t already have an API key, you can get one by heading to Cloudmersive.com and creating a free account (which includes 800 monthly API calls).
For the final step in the process, you can now copy in the rest of the code for the Python function:
# create an instance of the API class
api_instance = cloudmersive_validate_api_client.AddressApi(cloudmersive_validate_api_client.ApiClient(configuration))
input = cloudmersive_validate_api_client.ValidateAddressRequest() # ValidateAddressRequest | Input parse requesttry:
# Normalize a street address
api_response = api_instance.address_normalize_address(input)
except ApiException as e:
print("Exception when calling AddressApi->address_normalize_address: %s\n" % e)