SmashSend Python SDK - Official Python client for SmashSend API
Project description
SmashSend Python SDK
Official Python client for the SmashSend API.
Installation
pip install smashsend
Usage
from smashsend import SmashSend, EmailAddress, EmailSendOptions
# Initialize the client
client = SmashSend(api_key="your-api-key")
# Send an email
email = EmailSendOptions(
to=[EmailAddress(email="recipient@example.com", name="Recipient Name")],
from_=EmailAddress(email="sender@example.com", name="Sender Name"),
subject="Hello from SmashSend!",
text="This is a test email sent using the SmashSend Python SDK.",
html="<p>This is a test email sent using the <strong>SmashSend Python SDK</strong>.</p>"
)
response = client.emails.send(email)
print(f"Email sent! ID: {response.id}")
# List contacts
contacts = client.contacts.list(limit=10, offset=0)
for contact in contacts["contacts"]:
print(f"Contact: {contact.email}")
print(f"Total contacts: {contacts['pagination']['total']}")
# Create a webhook
webhook = client.webhooks.create(
url="https://your-domain.com/webhook",
events=["email.sent", "email.delivered"]
)
print(f"Webhook created! ID: {webhook.id}")
Features
- Full support for SmashSend API v1
- Type hints and validation using Pydantic
- Automatic retries for failed requests
- Comprehensive error handling
- Debug mode for request/response logging
API Resources
Emails
send(options: EmailSendOptions) -> EmailSendResponseget(email_id: str) -> EmailSendResponselist(page: int = 1, per_page: int = 10, status: Optional[str] = None, tag: Optional[str] = None) -> Dict[str, List[EmailSendResponse]]
Contacts
create(options: ContactCreateOptions) -> Contactget(contact_id: str) -> Contactupdate(contact_id: str, options: ContactCreateOptions) -> Contactdelete(contact_id: str) -> Nonelist(limit: int = 10, offset: int = 0) -> Dict[str, List[Contact]]
Webhooks
create(options: WebhookCreateOptions) -> Webhookget(webhook_id: str) -> Webhookupdate(webhook_id: str, options: WebhookCreateOptions) -> Webhookdelete(webhook_id: str) -> Nonelist(page: int = 1, per_page: int = 10, status: Optional[str] = None) -> Dict[str, List[Webhook]]
Error Handling
The SDK provides specific exception classes for different types of errors:
from smashsend import (
SmashSendError,
APIError,
AuthenticationError,
NetworkError,
RateLimitError,
TimeoutError
)
try:
response = client.emails.send(email)
except AuthenticationError as e:
print(f"Authentication failed: {e.message}")
except RateLimitError as e:
print(f"Rate limit exceeded: {e.message}")
except APIError as e:
print(f"API error: {e.message} (status: {e.status_code})")
except NetworkError as e:
print(f"Network error: {e.message}")
except TimeoutError as e:
print(f"Request timed out: {e.message}")
Configuration
The client can be configured with various options:
client = SmashSend(
api_key="your-api-key",
options={
"base_url": "https://api.smashsend.com",
"max_retries": 3,
"timeout": 30000, # milliseconds
"api_version": "v1"
}
)
# Set custom headers
client.set_headers({"X-Custom-Header": "value"})
# Enable debug mode
client.set_debug_mode(True)
# Change API version
client.set_api_version("v2")
Development
- Clone the repository:
git clone https://github.com/smashsend/smashsend-python.git
cd smashsend-python
- Install development dependencies:
pip install -e ".[dev]"
- Run tests:
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smashsend-0.1.0.tar.gz.
File metadata
- Download URL: smashsend-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e60ccce2fc328ffa4866e21449c8b21c8bb4147f4694aafe20d274a8676a0c3
|
|
| MD5 |
125adbea9fbcabeea04962325d332cd5
|
|
| BLAKE2b-256 |
ed0b14c52229dd7762b3824b0ac89b57e11ab1e285dec1132de008db114ad461
|
File details
Details for the file smashsend-0.1.0-py3-none-any.whl.
File metadata
- Download URL: smashsend-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c43306baf2204627596e4adb358b33cdbfd0bce38bd5909a65451fe4f5c745fc
|
|
| MD5 |
b5a76be73e1e77f558c4d3ebc18cabd4
|
|
| BLAKE2b-256 |
dbd8ce880e8671efa2497f75bc286b358d333d1ea2af06f5f05322518dcd56f2
|