SmartyStreets Python SDK

5.7.0 · active · verified Thu Apr 16

The SmartyStreets Python SDK is an official library designed to simplify access to SmartyStreets APIs for Python developers. It provides ready-made data structures and handles the underlying HTTP complexities. The library is currently at version 5.7.0, released on April 1, 2026, and is actively maintained with regular updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to validate a US street address using the SmartyStreets Python SDK. It initializes credentials using environment variables, builds a US Street API client, creates an address lookup, sends it, and prints the validated address details and geocoding information.

import os
from smartystreets_python_sdk import BasicAuthCredentials, ClientBuilder, exceptions
from smartystreets_python_sdk.us_street import Lookup

# It is recommended to store your SmartyStreets Auth ID and Auth Token in environment variables.
# Example: export SMARTY_AUTH_ID='YOUR_AUTH_ID'
# Example: export SMARTY_AUTH_TOKEN='YOUR_AUTH_TOKEN'
auth_id = os.environ.get('SMARTY_AUTH_ID', '')
auth_token = os.environ.get('SMARTY_AUTH_TOKEN', '')

if not auth_id or not auth_token:
    print('Please set SMARTY_AUTH_ID and SMARTY_AUTH_TOKEN environment variables.')
    exit(1)

try:
    credentials = BasicAuthCredentials(auth_id, auth_token)
    # The ClientBuilder can be used to build clients for various SmartyStreets APIs.
    # For US Street Address API, use build_us_street_api_client().
    client = ClientBuilder(credentials).build_us_street_api_client()

    # Create a Lookup object for the address you want to validate.
    lookup = Lookup()
    lookup.street = "1600 Amphitheatre Pkwy"
    lookup.city = "Mountain View"
    lookup.state = "CA"
    lookup.zipcode = "94043"

    # Send the lookup to the SmartyStreets API.
    client.send_lookup(lookup)

    if not lookup.result or not lookup.result.candidates:
        print("No candidates found for the address. It might be invalid.")
    else:
        first_candidate = lookup.result.candidates[0]
        print(f"Validated Address: {first_candidate.delivery_line_1}, {first_candidate.last_line}")
        print(f"Components: City={first_candidate.components.city_name}, State={first_candidate.components.state_abbreviation}, ZIP={first_candidate.components.zipcode}")
        if first_candidate.metadata.latitude and first_candidate.metadata.longitude:
            print(f"Latitude: {first_candidate.metadata.latitude}, Longitude: {first_candidate.metadata.longitude}")

except exceptions.SmartyException as e:
    print(f"SmartyStreets API error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →