Zero Bounce Python SDK
This SDK contains methods for interacting easily with ZeroBounce API.
More information about ZeroBounce you can find in the official documentation.
INSTALLATION
pip install zerobouncesdk
USAGE
Import the sdk in your file:
from zerobouncesdk import ZeroBounce
Initialize the sdk with your api key:
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
Examples
Then you can use any of the SDK methods, for example:
-
Check how many credits you have left on your account
from zerobouncesdk import ZeroBounce
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
response = zero_bounce.get_credits()
print("ZeroBounce get_credits response: " + str(response))
-
Check your API usage for a given period of time
from datetime import datetime
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
start_date = datetime(2019, 8, 1);
end_date = datetime(2019, 9, 1);
try:
response = zero_bounce.get_api_usage(start_date, end_date)
print("ZeroBounce get_api_usage response: " + str(response))
except ZBException as e:
print("ZeroBounce get_api_usage error: " + str(e))
-
Gather insights into your subscribers' overall email engagement
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
email = "valid@example.com";
try:
response = zero_bounce.get_activity(email)
print("ZeroBounce get_activity response: " + str(response))
except ZBException as e:
print("ZeroBounce get_activity error: " + str(e))
-
Identify the correct email format when you provide a name and email domain
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
domain = "example.com"
first_name = "John"
middle_name = "Quill"
last_name = "Doe"
try:
response = zero_bounce.guess_format(domain, first_name, middle_name, last_name)
print("ZeroBounce guess format response: " + response)
except ZBException as e:
print("ZeroBounce guess format error: " + str(e))
-
Validate an email address
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
email = "<EMAIL_ADDRESS>"
ip_address = "127.0.0.1"
try:
response = zero_bounce.validate(email, ip_address)
print("ZeroBounce validate response: " + str(response))
except ZBException as e:
print("ZeroBounce validate error: " + str(e))
-
Validate a batch of up to 100 emails at a time
from zerobouncesdk import ZeroBounce, ZBException, ZBValidateBatchElement
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
email_batch = [
ZBValidateBatchElement("valid@example.com", "127.0.0.1"),
ZBValidateBatchElement("invalid@example.com"),
]
try:
response = zero_bounce.validate_batch(email_batch)
print("ZeroBounce validate_batch response: " + str(response))
except ZBException as e:
print("ZeroBounce validate_batch error: " + str(e))
-
The sendFile API allows user to send a file for bulk email validation
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_path = './email_file.csv'
email_address_column = 1
return_url = "https://domain.com/called/after/processing/request"
first_name_column = None
last_name_column = None
gender_column = None
ip_address_column = None
has_header_row = False
remove_duplicate = True
try:
response = zero_bounce.send_file(
file_path,
email_address_column,
return_url,
first_name_column,
last_name_column,
gender_column,
ip_address_column,
has_header_row,
remove_duplicate,
)
print("ZeroBounce send_file response: " + str(response))
except ZBException as e:
print("ZeroBounce send_file error: " + str(e))
-
Check the status of a file uploaded via sendFile method
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_id = "<FILE_ID>"
try:
response = zero_bounce.file_status(file_id)
print("ZeroBounce file_status response: " + str(response))
except ZBException as e:
print("ZeroBounce file_status error: " + str(e))
-
The getfile API allows users to get the validation results file for the file been submitted using sendFile API
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_id="<FILE_ID>"
local_download_path = "./dwnld_file.csv"
try:
response = zero_bounce.get_file(file_id, local_download_path)
print("ZeroBounce get_file response: " + str(response))
except ZBException as e:
print("ZeroBounce get_file error: " + str(e))
-
Delete the file that was submitted using sendFile API. File can be deleted only when its status is Complete
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_id="<FILE_ID>"
try:
response = zero_bounce.delete_file(file_id)
print("ZeroBounce delete_file response: " + str(response))
except ZBException as e:
print("ZeroBounce delete_file error: " + str(e))
AI Scoring API
-
The scoringSendFile API allows user to send a file for bulk email scoring
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_path = './email_file.csv'
email_address_column = 1
return_url = "https://domain.com/called/after/processing/request"
has_header_row = False
remove_duplicate = True
try:
response = zero_bounce.scoring_send_file(
file_path,
email_address_column,
return_url,
has_header_row,
remove_duplicate,
)
print("ZeroBounce send_file response: " + str(response))
except ZBException as e:
print("ZeroBounce send_file error: " + str(e))
-
Check the status of a file uploaded via scoringSendFile method
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_id = "<FILE_ID>"
try:
response = zero_bounce.scoring_file_status(file_id)
print("ZeroBounce file_status response: " + str(response))
except ZBException as e:
print("ZeroBounce file_status error: " + str(e))
-
The scoring scoringGetFile API allows users to get the validation results file for the file been submitted using scoring scoringSendFile API
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_id="<FILE_ID>"
local_download_path = "./dwnld_file.csv"
try:
response = zero_bounce.scoring_get_file(file_id, local_download_path)
print("ZeroBounce get_file response: " + str(response))
except ZBException as e:
print("ZeroBounce get_file error: " + str(e))
-
Delete the file that was submitted using scoringSendFile API. File can be deleted only when its status is Complete
from zerobouncesdk import ZeroBounce, ZBException
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
file_id="<FILE_ID>"
try:
response = zero_bounce.scoring_delete_file(file_id)
print("ZeroBounce delete_file response: " + str(response))
except ZBException as e:
print("ZeroBounce delete_file error: " + str(e))