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:
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.
Next, we need to create a secret key that the program will use to identify you’re account.
We'll then give our key a name to identify where our lookups are coming from:
It will then create some credentials to put into the program
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:
This will install the package. It is included in my example program.
We will the import pandas and smartystreet package:
We will then import a set of addresses from a spreadsheet:
We will convert the column to a python list just for convenience:
We can then put our credentials into the program and we will then connect it to their us address verification.
I will then provide it an address to see what it returns:
Match = “enhanced” is needed to return if the address is residential or commercial.
Recommended by LinkedIn
We then save the results to first_candidate
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
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
Where is what the displayed information looks like:
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:
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.
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
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.
Here is the return of all the results:
We can then filter some of the addresses for some items that may be higher risk.
We can see these two addresses are noted as being Residential
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.
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.