Appearance
Python SDK
Install
bash
pip install sendiventRequires Python 3.8+.
Quickstart
python
import os
from sendivent import Sendivent
client = Sendivent(os.environ['SENDIVENT_API_KEY'])
response = client \
.event('welcome') \
.to('user@example.com') \
.payload({'name': 'Alice'}) \
.send()
if not response.is_success():
print(response.error)Configuration
Set SENDIVENT_API_KEY in your environment. The SDK automatically routes requests to the correct API based on your key prefix: test_ → sandbox, live_ → production. See Sandbox vs Production.
Common tasks
Send with payload
python
client.event('order-shipped') \
.to('user@example.com') \
.payload({'order_id': '12345', 'tracking_url': 'https://...'}) \
.send()Send to a contact object
python
client.event('welcome') \
.to({
'email': 'user@example.com',
'name': 'Alice',
'id': 'user_123',
'plan': 'premium'
}) \
.send()See Contacts for identifier rules and meta fields.
Force a channel
python
client.event('verification') \
.channel('sms') \
.to('+46701234567') \
.send()See Routing.
Set language
python
client.event('welcome') \
.language('sv') \
.to('anders@example.com') \
.send()See Templates for language variants.
Send to multiple recipients
python
client.event('newsletter') \
.to(['user1@example.com', 'user2@example.com']) \
.payload({'subject': 'Monthly Update'}) \
.send()Override template settings
python
client.event('invoice') \
.to('user@example.com') \
.overrides({
'email': {
'subject': 'Your Invoice',
'reply_to': 'billing@yourcompany.com'
}
}) \
.send()Prevent duplicates
python
client.event('order-confirmation') \
.to('user@example.com') \
.idempotency_key('order-12345') \
.send()Fire-and-forget
Use send_async() to send without waiting for a response. The request is sent immediately and your code continues — no blocking.
python
client.event('welcome') \
.to('user@example.com') \
.send_async()
# Code continues immediately, notification sends in backgroundIdeal for non-critical notifications where you don't need delivery confirmation.
Response and delivery tracking
send() returns a response object. On success, it includes delivery identifiers you can look up in the dashboard Activity log.
python
response = client.event('welcome').to('user@example.com').send()
if response.is_success():
print(response.data)See Send API for the full response format.
Error handling
python
response = client.event('welcome').to('user@example.com').send()
if response.is_success():
print(response.data)
else:
print(f"Error: {response.error}")Methods
| Method | Description |
|---|---|
event(name) | Set event name |
to(recipient) | Set recipient(s) |
from_sender(sender) | Set custom sender (verified) |
payload(data) | Set template data |
channel(name) | Force channel (email, sms, slack) |
language(code) | Set language code |
overrides(dict) | Override template settings |
idempotency_key(key) | Prevent duplicate sends |
send() | Send synchronously |
send_async() | Send asynchronously |
Common pitfalls
- Using
test_key in production — lower rate limits and separate database (see Sandbox) - Forcing
smswithout a phone number — send fails (see Routing) - Blank template variables — you didn't send required
payload/metafields (see Templates)