Lob Python Client Library (v4.x)

4.5.4 · maintenance · verified Wed Apr 15

The `lob` Python client library provides bindings for the Lob.com API, enabling programmatic access to services like mail, print, and address verification. This registry entry specifically covers the 4.x series of the library. While still maintained for critical fixes, new major versions (5.x and above) are released under a separate PyPI package, `lob-python`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Lob client and create an address object using the `lob` (v4.x) package. Ensure your Lob API key is set as an environment variable named `LOB_API_KEY`. You can obtain test API keys from your Lob dashboard.

import os
import lob

# Get your API key from environment variables
lob.api_key = os.environ.get('LOB_API_KEY', '')

# For demonstration, ensure a valid API key is present
if not lob.api_key:
    print("Error: LOB_API_KEY environment variable not set.")
    print("Please set it with your Lob Test API key (e.g., test_****************).")
    exit(1)

try:
    # Create a simple address
    address = lob.Address.create(
        name='Joe Smith',
        address_line1='123 Main St',
        address_city='San Francisco',
        address_state='CA',
        address_zip='94107',
        address_country='US'
    )

    print(f"Successfully created Address ID: {address.id}")
    print(f"Address Line 1: {address.address_line1}")
    print(f"Address City: {address.address_city}")
    print(f"Address State: {address.address_state}")

except lob.LobError as e:
    print(f"Lob API Error: {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →