Validate a City and State/Province Combination; Get Location Information About it in Python

Cloudmersive
2 min readJan 27, 2022

--

Ensuring locational information is correct is a difficult task — even when you have all the right information, the smallest formatting mistakes can cause errors in shipping, mailing, travel directions, and more. If your application is handling such information, Cloudmersive’s Validate API can bring a lot to the table. The /validate/address/city iteration will check if an input city, state name or code is valid, and return normalized information. Let’s look at how you can take advantage of this in Python.

To connect with this API, first run the below command to install the Python SDK:

pip install cloudmersive-validate-api-clientfrom __future__ import print_function
import time
import cloudmersive_validate_api_client
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint

Next, you can enter in the below code snippet for access authorization. This code will capture your API key (which can be obtained by making a free account on the Cloudmersive website):

# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

Finally, you can complete the function using the below code:

# 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.ValidateCityRequest() # ValidateCityRequest | Input parse request
try:
# Validate a City and State/Province combination, get location information about it
api_response = api_instance.address_validate_city(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling AddressApi->address_validate_city: %s\n" % e)

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet