Address Verification Using Python & Smarty Address Verification

Address Verification Using Python & Smarty Address Verification

To download my sample workbook visit my site:

If you'd like a video showing how I organized and ran the code:

https://youtu.be/BwCI36TS6T8

Address verification can be a beneficial process for Auditors. It can help us identify if we are sending a paycheck to a valid address.

It can allow us to compare vendor and employee addresses more accurately because it will make the address format consistent.

It can show us if a vendor is using a residential address or a non-deliverable address which is an indicator of a fraudulent vendor.

The best way to verify a lot of addresses and get great support is to use Smarty Address verification. It returns address information very quickly and works with Python very conveniently. I've also asked a few questions from their support while making this tutorial and they were very helpful.

You can process a demo on their website for free:

https://www.smarty.com/products/us-address-verification?v=2#demo

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

The demo provides useful information based on the address we provided.

However, if we want to process a lot of addresses you'll want to do it in Python.

The first step you need to do is create an account. They offer a free 30-day, 1,000-lookup trial. No credit card is required. With my program, you can see how it works and determine if you want to do more lookups which will cost more.

No alt text provided for this image

Next, we need to create a secret key that the program will use to identify you’re account.

No alt text provided for this image

We'll then give our key a name to identify where our lookups are coming from:

No alt text provided for this image

It will then create some credentials to put into the program

No alt text provided for this image

After you’ll need to make sure you have smartystreets_python_sdk library installed:

In Jupyter Notebook we will put pip install into a cell to install this library:

No alt text provided for this image

This will install the package. It is included in my example program.

We will the import pandas and smartystreet package:

No alt text provided for this image

We will then import a set of addresses from a spreadsheet:

No alt text provided for this image

We will convert the column to a python list just for convenience:

No alt text provided for this image

We can then put our credentials into the program and we will then connect it to their us address verification.

No alt text provided for this image

I will then provide it an address to see what it returns:

No alt text provided for this image

Match = “enhanced” is needed to return if the address is residential or commercial.

We then save the results to first_candidate

No alt text provided for this image

All the data Smarty has you can return it from these results. For details of everything returned and what some of the codes' definitions are visit smarty's website

https://www.smarty.com/docs/cloud/us-street-api#http-response-output

No alt text provided for this image

In my example program. I’m returning all the information I thought would be useful to an Auditor:

Here’s the code to display all the information I obtained

No alt text provided for this image

Where is what the displayed information looks like:

No alt text provided for this image

Probably the most important is delivery_line_1, 2, and last_line. These are the items you would include as a mailing address.

If you need the information broken out that information is available.

You can see it changed the information from what I provided. This would help in making sure addresses are uniform between different sources since it will be verified against Smarty’s database of addresses:

No alt text provided for this image


It also returned the zip code which was not provided.

I then created a function, which will take an address and return all the information into a pandas data frame. This way we can export all the results into an Excel Spreadsheet.

No alt text provided for this image

Now we can provide our list of addresses from our spreadsheet to this function and run it in a loop and return all the information from the addresses provided

No alt text provided for this image

This is the for loop that will go through each of the addresses and return the results and save them. In the end, it will combine all the results in df_results. 

No alt text provided for this image

Here is the return of all the results:

No alt text provided for this image

We can then filter some of the addresses for some items that may be higher risk.

  • We will filter for Residential addresses since that may make the vendor’s a higher risk

We can see these two addresses are noted as being Residential

No alt text provided for this image

  • We will filter for addresses that are either non-deliverable address or an address that may be missing information

No alt text provided for this image

Here is how Smarty defines this column. Postal-match is a match to a postal address so it’s a valid mailable address. The other items may warrant some additional research.

No alt text provided for this image

  • When the address verification service can’t find an address that normally means that address is not valid address. So I made it so it returns empty information with a comment. So we can follow up on these items.


No alt text provided for this image

I definitely didn’t display all the code, so feel free to download the workbook and look at it. I set it up so you can feed it a list of addresses from an Excel workbook and export the results to an Excel Workbook.

Let me know if you have any questions.

To view or add a comment, sign in

More articles by David Rudd

  • Look up Deleted Customer

    A common task for auditors is comparing two data sets. In this lesson I will compare a customer table to an invoice…

    1 Comment
  • Automate SAP with Excel

    This will probably be the only VBA lesson I do, but I think automating SAP is significantly easier using VBA because…

    9 Comments
  • Use Python to Add References to Audit Workpapers

    Sometimes as an auditor, we will get a lot of documents. It helps to organize the workpapers by numbering them so they…

  • Detecting Conflicts of Interest with Python

    One way to identify conflicts of interest is to compare employee data to vendor data to see if there is an employee has…

  • Web Scraping Tables with Python

    Visit my website to download the sample workbook and program: Send me an email at david.rudd@letsworkapps.

Others also viewed

Explore content categories