Skip to main content

A Python client for the Shoutbox Email API

Project description

Shoutbox.net Developer API - Python Library

Shoutbox.net is a Developer API designed to send transactional emails at scale. This documentation covers all Python integration methods, from direct API calls to full framework integration.

Integration Methods

There are four main ways to integrate with Shoutbox in Python:

  1. Direct API calls (minimal dependencies)
  2. Using our Python library with pip
  3. SMTP integration
  4. Web framework integration (Flask/Django)

1. Direct API Integration (Minimal Dependencies)

If you want minimal dependencies, you can make direct API calls using requests:

import requests

# Your API key from Shoutbox.net
api_key = 'your-api-key-here'

# Prepare email data
data = {
    'from': 'sender@example.com',
    'to': 'recipient@example.com',
    'subject': 'Test Email',
    'html': '<h1>Hello!</h1><p>This is a test email.</p>',
    'name': 'Sender Name',
    'reply_to': 'reply@example.com'
}

# Make the API call
response = requests.post(
    'https://api.shoutbox.net/send',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json=data
)

# Handle the response
if response.status_code >= 200 and response.status_code < 300:
    print("Email sent successfully!")
else:
    print(f"Failed to send email. Status code: {response.status_code}")

Direct API Features

  • Minimal dependencies (only requests)
  • Simple implementation
  • Full control over the request
  • Lightweight integration
  • Suitable for simple implementations

2. Python Library with pip

Installation

pip install shoutbox

2.1 API Client Usage

The API client provides an object-oriented interface to the REST API:

from shoutbox import ShoutboxClient, Email, EmailAddress, Attachment

# Initialize client
api_key = os.getenv('SHOUTBOX_API_KEY') or 'your-api-key-here'
client = ShoutboxClient(api_key)

try:
    # Basic email
    email = Email(
        from_email="sender@example.com",
        to="recipient@example.com",
        subject="Test Email",
        html="<h1>Hello!</h1><p>This is a test email.</p>",
        reply_to="reply@example.com"
    )

    client.send(email)
    
    # Email with attachment
    with open('document.pdf', 'rb') as f:
        attachment = Attachment(
            filename='document.pdf',
            content=f.read(),
            content_type='application/pdf'
        )

    email_with_attachment = Email(
        from_email="sender@example.com",
        to="recipient@example.com",
        subject="Test Email with Attachment",
        html="<h1>Hello!</h1><p>This email includes an attachment.</p>",
        attachments=[attachment]
    )

    client.send(email_with_attachment)

except Exception as e:
    print(f"Error: {str(e)}")

2.2 SMTP Client Usage

The SMTP client provides an alternative way to send emails:

from shoutbox import SMTPClient, Email

client = SMTPClient('your-api-key-here')

try:
    # Multiple recipients
    email = Email(
        from_email="sender@example.com",
        to=["recipient1@example.com", "recipient2@example.com"],
        subject="Test Email",
        html="<h1>Hello!</h1><p>This is a test email.</p>",
        headers={
            'X-Custom-Header': 'Custom Value',
            'X-Priority': '1'
        }
    )

    client.send(email)

except Exception as e:
    print(f"Error: {str(e)}")

Library Features

  • Type-safe email options
  • Built-in error handling
  • File attachment support
  • Custom headers support
  • Multiple recipient types (to, cc, bcc)
  • Choice between API and SMTP clients

3. Web Framework Integration

Flask Integration

from flask import Flask
from shoutbox import ShoutboxClient, Email

app = Flask(__name__)
client = ShoutboxClient(api_key='your-api-key')

@app.route('/send-email', methods=['POST'])
def send_email():
    email = Email(
        from_email="your-app@domain.com",
        to=request.json['to'],
        subject=request.json['subject'],
        html=request.json['html']
    )
    
    result = client.send(email)
    return {'success': True}

Django Integration

  1. Add configuration to settings.py:
SHOUTBOX_API_KEY = 'your-api-key'
  1. Usage example:
from shoutbox import ShoutboxClient, Email

client = ShoutboxClient()

def send_notification(request):
    email = Email(
        from_email="your-app@domain.com",
        to="recipient@example.com",
        subject="Notification",
        html="<h1>New notification</h1>"
    )
    
    client.send(email)
    return JsonResponse({'success': True})

Development

  1. Clone the repository:
git clone https://github.com/shoutboxnet/shoutbox-python.git
  1. Install dependencies:
pip install -r requirements-dev.txt
  1. Run tests:
make test

Support

  • GitHub Issues for bug reports
  • Email support for critical issues
  • Documentation for guides and examples
  • Regular updates and maintenance

License

This library is licensed under the MIT License. See the 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

shoutbox_tluyben-0.1.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

shoutbox_tluyben-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file shoutbox_tluyben-0.1.0.tar.gz.

File metadata

  • Download URL: shoutbox_tluyben-0.1.0.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for shoutbox_tluyben-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a8d9c693898b1b7c6b2416e1f2dfe2f650900c7fe61cfa283bfe200f43ddbae4
MD5 ef2fe5739f49c35f559955a5210e5f8f
BLAKE2b-256 fa29ec1a7d00fb8417d1b219c15b9ba76e3e0f742c8b1dce3d85ad58e23b0b94

See more details on using hashes here.

File details

Details for the file shoutbox_tluyben-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shoutbox_tluyben-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad0a21c46bdabf5dc2397f105e86cc5a09bd3648d07ff612b9ed15e5c2887f7b
MD5 62b40282162f203cd923a10bdf3966ef
BLAKE2b-256 a148a994c662506904a8e8c4aaab14819afb0d80e2ea6e1666a97f6b87c8baee

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