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

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




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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Make your Python code run faster

Parse a Structured Date/Time String in Python

A phrase that a parent, mentor, or teacher said that stuck with us and changed everything

How to Pass data to view from Controller ?

Mounting Azure Files with SMB on Debian-based distributions

Top Email clients for Linux

AWS Cli — ECR display only image tags in the repository

Community Highlight: How Timbergrove Uses InfluxDB to Offer a Smart Workplace Kit

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


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

More from Medium

Translate English to French Text with Deep Learning AI in Python

DelayQueue in Python

Benefits of Using Python for Software Development

How to setup streaming replication in PostgreSQL step by step on Ubuntu