Validate a Postal Code, Get Location Information About It in Python

It’s important to get your locational information right! Using the validate/address/postal-code iteration of the Cloudmersive Validate API, you can empower your application to ensure any given postal code is valid, and get more information about it in return about the City & State it corresponds with (supports all major countries). In this article we’ll walk through a few simple steps to use this API in Python.

The first step in the process is to install the Python SDK. You can copy & paste the below code from the Cloudmersive API console:

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

Once that step is complete, you’ll need to copy in the below snippet to authenticate your API key for access. If you don’t already have an API key, you can get one by creating a free account on the Cloudmersive website (good for 800 API calls per month).

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

Finally, you can finish off the function with the following code, and you’re all set to go:

# 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.ValidatePostalCodeRequest() # ValidatePostalCodeRequest | Input parse request
try:
# Validate a postal code, get location information about it
api_response = api_instance.address_validate_postal_code(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling AddressApi->address_validate_postal_code: %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

Microservices

Everything Wrong With Facial Recognition Software and 3 Essential Ethical Considerations That Must…

More Like This Query (MLT) — Java API Client

Checking the Code of Zephyr Operating System

Create a VPC, NAT GateWayAnd Deploy Public WordPress Site With Private MYSQL Database Using…

An Introduction to Sociotechnical Architecture Patterns

Create A Portfolio Website: Part Three

How Relevant Is Java Today Compared to Python?

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
Cloudmersive

Cloudmersive

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

More from Medium

Parse an Unstructured Input Text String into an International, Formatted Address in Python

Socket Programming-Python

Auto-book COVID test appointment

Python — Best Coding Practices