Skip to main content

Official Python SDK for SendLayer API

Project description

SendLayer Logo

SendLayer Python SDK

The official Python SDK for interacting with the SendLayer API, providing a simple and intuitive interface for sending emails, managing webhooks, and retrieving email events.

MIT licensed

Installation

pip install sendlayer

Quick Start

from sendlayer import SendLayer

# Initialize the email client with your API key
sendlayer = SendLayer("your-api-key")

# Send an email
response = sendlayer.Emails.send(
    sender="sender@example.com",
    to="recipient@example.com",
    subject="Test Email",
    text="This is a test email"
)

Features

  • Email Module: Send emails with support for HTML/text content, attachments, CC/BCC, and templates
  • Webhooks Module: Create, retrieve, and delete webhooks for various email events
  • Events Module: Retrieve email events with filtering options
  • Error Handling: Custom exceptions for better error management
  • Type Hints: Full type support for better IDE integration

Documentation

Email Module

Send emails using the SendLayer module:

from sendlayer import SendLayer

sendlayer = SendLayer(api_key='your-api-key')


# Send a complex email
response = sendlayer.Emails.send(
    sender={"email": "sender@example.com", "name": "Paulie Paloma"},
    to=[
        {'email': 'recipient1@example.com', 'name': 'Recipient 1'},
        {'email': 'recipient2@example.com', 'name': 'Recipient 2'}
    ],
    subject='Complex Email',
    html='<p>This is a <strong>test email</strong>!</p>',
    text='This is a test email!',
    cc=[{'email': 'cc@example.com', 'name': 'CC Recipient'}],
    bcc=[{'email': 'bcc@example.com', 'name': 'BCC Recipient'}],
    reply_to=[{'email': 'reply@example.com', 'name': 'Reply To'}],
    attachments=[{
        'path': 'path/to/file.pdf',
        'type': 'application/pdf',
    }]
)

Webhooks Module

from sendlayer import SendLayer

sendlayer = SendLayer(api_key='your-api-key')

# Create a webhook
# Webhook event options: bounce, click, open, unsubscribe, complaint, delivery

webhook = sendlayer.Webhooks.create(
    url='https://your-domain.com/webhook',
    event='open'
)

# Get all webhooks
webhooks = sendlayer.Webhooks.get()

# Delete a webhook
sendlayer.Webhooks.delete(webhook_id=123)

Events Module

from sendlayer import SendLayer
from datetime import datetime, timedelta

sendlayer = SendLayer(api_key='your-api-key')

# Get all events
events = sendlayer.Events.get()

# Get filtered events
events = sendlayer.Events.get(
    start_date=datetime.now() - timedelta(hours=4),
    end_date=datetime.now(),
    event='opened'
)

Error Handling

The SDK provides custom exceptions for better error handling:

from sendlayer import (
    SendLayerError,
    SendLayerAPIError,
)

try:
    response = sendlayer.Emails.send(...)
except SendLayerError as e:
    print(f"API error: {e.status_code} - {e.message}")
except SendLayerError:
    print("An unexpected error occurred")

More Details

To learn more about using the SendLayer SDK, be sure to check our Developer Documentation.

License

MIT License - see LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sendlayer-1.0.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sendlayer-1.0.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file sendlayer-1.0.0.tar.gz.

File metadata

  • Download URL: sendlayer-1.0.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for sendlayer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 23e0650cf8aea4a4f12617dc761835b256ed502443ffd5592ff1db1edad8c409
MD5 9b929081bfc9a8f7309817512d68a768
BLAKE2b-256 1afadb1a4f92980973146cf3147e94c6cf869e5d60b9b88a4a2b483459532a08

See more details on using hashes here.

File details

Details for the file sendlayer-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sendlayer-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for sendlayer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9616bb47260dd1c11d02068a280044943f1ddd1ad5761f3209c769c5f10c761d
MD5 e93bfc85ca75c0a7cc7aa80d66849c08
BLAKE2b-256 5f63dd958ad11010021e377171a725b94ec0c50b7043b2deb7e069f8ae98561b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page