Skip to main content

Self-hosted communications platform SDK for email, push notifications, and SMS

Project description

SendFn Python SDK

Self-hosted communications platform SDK for email, push notifications, and SMS.

Installation

pip install sendfn

For email support (AWS SES):

pip install sendfn[email]

For push notification support:

pip install sendfn[push]

For all features:

pip install sendfn[all]

Quick Start

Email Sending

from sendfn import create_sendfn, SendfnConfig
from sendfn.models import EmailConfig, AwsSesConfig, SendEmailParams
from sendfn.database import MemoryAdapter

# Create configuration
config = SendfnConfig(
    database=MemoryAdapter(),
    email=EmailConfig(
        from_email="noreply@example.com",
        from_name="My App",
        aws_ses=AwsSesConfig(
            access_key_id="YOUR_ACCESS_KEY",
            secret_access_key="YOUR_SECRET_KEY",
            region="us-east-1",
        ),
    ),
)

# Create client
sendfn = create_sendfn(config)

# Send an email
transaction = await sendfn.send_email(
    SendEmailParams(
        user_id="user-123",
        to="user@example.com",
        subject="Welcome!",
        html="<h1>Welcome to our app!</h1>",
        text="Welcome to our app!",
    )
)

print(f"Email sent! Transaction ID: {transaction.id}")

Using Templates

from sendfn.models import EmailTemplate

# Register a custom template
template = EmailTemplate(
    id="welcome",
    name="Welcome Email",
    subject="Welcome to {{appName}}!",
    html="<h1>Hi {{userName}}!</h1><p>Welcome to {{appName}}.</p>",
    variables=["userName", "appName"],
)

await sendfn.register_template(template)

# Send email using template
transaction = await sendfn.send_email(
    SendEmailParams(
        user_id="user-123",
        to="user@example.com",
        template_id="welcome",
        template_data={
            "userName": "John",
            "appName": "My App",
        },
    )
)

Suppression List

# Check if email is suppressed
result = await sendfn.check_suppression_list("user@example.com")
if result["suppressed"]:
    print(f"Email is suppressed: {result['entry'].reason}")

# Add to suppression list
await sendfn.add_to_suppression_list(
    email="spam@example.com",
    reason="manual",
    source="admin-action",
)

# Remove from suppression list
await sendfn.remove_from_suppression_list("user@example.com")

Event Tracking

# Get events for an email transaction
events = await sendfn.get_email_events(transaction_id="...")

for event in events:
    print(f"{event.event_type} at {event.event_timestamp}")

Features

  • Email Sending - AWS SES support with attachments
  • Template Engine - Variable interpolation, conditionals, loops
  • Suppression Lists - Automatic bounce and complaint handling
  • Event Tracking - Track delivery, bounces, opens, clicks
  • Database Agnostic - Works with any database via adapters
  • Push Notifications - FCM and APNS support (coming soon)
  • SMS - SMS sending support (coming soon)

Configuration

Email Configuration

EmailConfig(
    from_email="noreply@example.com",  # Required
    from_name="My App",  # Optional
    reply_to="support@example.com",  # Optional
    aws_ses=AwsSesConfig(
        access_key_id="...",
        secret_access_key="...",
        region="us-east-1",
        configuration_set_name="my-config-set",  # Optional
    ),
)

Options

SendfnOptions(
    suppression_enabled=True,  # Enable suppression list checking
    retry_attempts=3,  # Number of retry attempts
    retry_delay=1000,  # Delay between retries (ms)
    event_tracking=True,  # Enable event tracking
)

Database Adapters

Memory Adapter (for testing)

from sendfn.database import MemoryAdapter

adapter = MemoryAdapter()

With Superfunctions DB

from superfunctions.db import create_adapter

adapter = create_adapter({
    "type": "postgres",
    "connection_string": "postgresql://...",
})

Development

# Install dependencies
make install

# Run tests
make test

# Lint code
make lint

# Format code
make format

License

MIT License - see LICENSE file for details.

Links

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

sendfn-0.0.1.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

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

sendfn-0.0.1-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file sendfn-0.0.1.tar.gz.

File metadata

  • Download URL: sendfn-0.0.1.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sendfn-0.0.1.tar.gz
Algorithm Hash digest
SHA256 651a9e5347fe7ec1ef2b57a872ea956f1c7609419cfb1c120ef3a6ed65c17f6a
MD5 859619e5df1c961b8f209b8177f68aa8
BLAKE2b-256 5c2d3c24858bee5f35eb9127db5747b0ee6f8a23c7921e188f1f653f142903ce

See more details on using hashes here.

File details

Details for the file sendfn-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sendfn-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sendfn-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e39418ce094bd161e9ad2d4600826d1857806da62ccf347162afcf765b198ed
MD5 deba85304b6e6e18a8af50ac1d5e96e6
BLAKE2b-256 9bc5db771fbb57b2e2d1ee9bbefbeaf5571552d6a6f4e95547131117573ba9ca

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