ZeroBounce Python SDK

2.2.0 · active · verified Thu Apr 16

The `zerobouncesdk` is a Python library that provides an easy-to-use interface for interacting with the ZeroBounce email verification API. It allows developers to validate email addresses, check API usage, retrieve credit balance, and perform bulk email validation. The current version is 2.2.0, and it features a regular release cadence with frequent updates and occasional major versions that introduce new features and improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the ZeroBounce SDK with your API key, check your remaining credits, and perform a single email validation. It uses environment variables for secure API key handling and includes basic error checking.

import os
from zerobouncesdk import ZeroBounce, ZBException

API_KEY = os.environ.get('ZEROBOUNCE_API_KEY', 'YOUR_API_KEY')

if API_KEY == 'YOUR_API_KEY':
    print("Please set the ZEROBOUNCE_API_KEY environment variable or replace 'YOUR_API_KEY'.")
else:
    try:
        zero_bounce = ZeroBounce(API_KEY)
        # Get credit balance
        response = zero_bounce.get_credits()
        if response.get('success'):
            print(f"Remaining Credits: {response.get('credits')}")
        else:
            print(f"Error getting credits: {response.get('message')}")
            if response.get('errors'):
                for error in response.get('errors'):
                    print(f" - {error.get('field')}: {error.get('message')}")

        # Example: Validate a single email (replace with a real email for testing)
        email_to_validate = 'test@example.com'
        ip_address = '127.0.0.1'
        validation_response = zero_bounce.validate(email_to_validate, ip_address)
        if validation_response.get('success'):
            print(f"Validation for {email_to_validate}: Status = {validation_response.get('status')}, Sub Status = {validation_response.get('sub_status')}")
        else:
            print(f"Error validating {email_to_validate}: {validation_response.get('message')}")

    except ZBException as e:
        print(f"An SDK exception occurred: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →