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

Cloudmersive
2 min readJan 27, 2022

In this article, we’re going to walk through using a useful iteration of Cloudmersive’s Validate API in Python. The /validate/address/parse iteration uses Machine Learning (ML) & Natural Language Processing (NLP) to parse an unstructured input text string into an international, formatted address. This iteration can handle a wide variety of cases, which includes non-standard and unstructured address strings across a wide array of countries and address-formatting norms. Connecting is made easy with ready-to-run code and extensive documentation for your convenience.

To use this API, first install the Python SDK with the below command:

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

After that, you’ll need to authorize your API key with the below snippet. If you don’t have a key already, you can get one by creating 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'

You can then complete the function by copying & pasting 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.ParseAddressRequest() # ParseAddressRequest | Input parse request
try:
# Parse an unstructured input text string into an international, formatted address
api_response = api_instance.address_parse_string(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling AddressApi->address_parse_string: %s\n" % e)

--

--

Cloudmersive

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