How to Validate a Street Address in Python
Determining the validity of street addresses is incredibly important in maintaining the integrity and reputation of a business.
Consider this example; a user purchases a product from your website but spells the street name incorrectly when entering it into the shipping information field. Now, when your shipping department is getting ready to send the product out, there is a possibility that it could go to the wrong address, or worse, not be delivered at all. Utilizing our Validate Street Address API on the front-end can save you from this sort of situation by immediately scanning the address for validity.
To use this API, we first need to install the SDK:
pip install cloudmersive-validate-api-client
Next, we can create an instance of the API and call the street validation function with the following code:
from __future__ import print_function
import time
import cloudmersive_validate_api_client
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'# 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:
# Validate a street address
api_response = api_instance.address_validate_address(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling AddressApi->address_validate_address: %s\n" % e)
Once complete, the operation will return a response indicating the validity of the street address, as well as the longitude and latitude of the valid addresses. To receive a personal API key that gives you access to 800 calls/month, go to the Cloudmersive website and register for a free account.