Tip
Need help? Join our Discord or email jesse@bentonow.com for personalized support.
The Bento Python SDK makes it quick and easy to build excellent email marketing and automation experiences in your Python applications. We provide powerful and customizable APIs that can be used out-of-the-box to manage subscribers, create custom fields and tags, send broadcasts, and more. We also expose low-level APIs so that you can build fully custom experiences.
Get started with our π integration guides, or π browse the SDK reference.
- Subscriber management: Easily add, update, and retrieve subscriber information.
- Custom fields and tags: Create and manage custom fields and tags for advanced segmentation.
- Batch operations: Perform bulk imports of subscribers, events, and emails.
- Broadcast management: Create and retrieve broadcast information.
- Advanced analytics: Access site and segment statistics.
- Experimental features: Utilize cutting-edge features like email validation, content moderation, and geolocation.
The Bento Python SDK requires Python 3.x and the Requests library. Bento Account for a valid SITE_UUID, BENTO_PUBLISHABLE_KEY & BENTO_SECRET_KEY.
Install the Bento SDK using pip:
pip install git+https://github.com/bentonow/bento-python-sdk.git
Initialize the Bento client:
from bento_api import BentoAPI
import os
bento = BentoAPI(
site_uuid=os.getenv('BENTO_SITE_UUID'),
username=os.getenv('BENTO_PUBLISHABLE_KEY'),
password=os.getenv('BENTO_SECRET_KEY')
)
Manage subscribers in your Bento account.
subscriber = bento.get_subscriber(email="user@example.com")
print(f"Subscriber: {subscriber}")
new_subscriber = bento.create_subscriber(email="newuser@example.com")
print(f"New subscriber: {new_subscriber}")
Perform bulk operations efficiently.
subscribers = [
{"email": "user1@example.com", "first_name": "User", "last_name": "One"},
{"email": "user2@example.com", "first_name": "User", "last_name": "Two"}
]
result = bento.batch_create_subscribers(subscribers)
print(f"Batch create subscribers result: {result}")
Manage email broadcasts.
broadcasts = bento.get_broadcasts()
print(f"Broadcasts: {broadcasts}")
Manage custom fields.
new_field = bento.create_field(key="favorite_color")
print(f"New field: {new_field}")
Manage tags for subscriber segmentation.
new_tag = bento.create_tag(name="new_customer")
print(f"New tag: {new_tag}")
Execute various commands on subscribers.
commands = [
{"command": "add_tag", "email": "user@example.com", "query": "new_tag"},
{"command": "remove_tag", "email": "user@example.com", "query": "old_tag"}
]
result = bento.execute_commands(commands)
print(f"Execute commands result: {result}")
Retrieve analytics data.
site_stats = bento.get_site_stats()
print(f"Site stats: {site_stats}")
Access cutting-edge features.
validation_result = bento.validate_email(
email="user@example.com",
name="John Doe",
user_agent="Mozilla/5.0",
ip="192.168.1.1"
)
print(f"Email validation result: {validation_result}")
- The SDK uses environment variables for authentication. Ensure these are set securely.
- Batch operations allow for efficient handling of multiple subscribers or events.
- Experimental features provide advanced capabilities but may be subject to changes.
- The SDK supports both email and UUID-based subscriber lookups.
- Always handle potential exceptions when making API calls.
We welcome contributions! Please see our contributing guidelines for details on how to submit pull requests, report issues, and suggest improvements.
The Bento SDK for Python is available as open source under the terms of the MIT License.