Python
Python SDK for Poodle’s email sending API.
Table of Contents
Section titled “Table of Contents”Installation
Section titled “Installation”pip install poodle-python
Quick Start
Section titled “Quick Start”from poodle import PoodleClient
# Initialize the clientclient = PoodleClient("your-api-key")
# Send an emailtry: response = client.send_email( subject="Hello from Poodle!", html_content="<h1>Hello World</h1>", text_content="Hello World" # Optional plain text version ) print(f"Success: {response['message']}")except PoodleError as e: print(f"Error: {e.message}") if e.status_code: print(f"Status Code: {e.status_code}") if e.details: print(f"Details: {e.details}")
Features
Section titled “Features”- Intuitive API: Get started in minutes.
- Detailed Errors: Understand and debug issues quickly with PoodleError objects.
- Flexible Content: Send rich HTML or plain text emails easily.
- Connection Pooling: Optimize performance with connection pooling.
- Type Hints: Better IDE support with type hints.
- Context Manager: Proper resource cleanup with context manager.
Examples
Section titled “Examples”Initialize with Custom Options
Section titled “Initialize with Custom Options”client = PoodleClient( api_key="your-api-key", base_url="https://custom.api.url", # Optional custom API URL timeout=60.0 # Optional custom timeout in seconds)
Send HTML-only Email
Section titled “Send HTML-only Email”response = client.send_email( subject="HTML Email", html_content="<h1>Hello</h1><p>This is an HTML email</p>")
Send Plain Text Email
Section titled “Send Plain Text Email”response = client.send_email( subject="Plain Text Email", text_content="Hello! This is a plain text email.")
Using as Context Manager
Section titled “Using as Context Manager”with PoodleClient("your-api-key") as client: response = client.send_email( subject="Test Email", text_content="Hello World" )
Error Handling
Section titled “Error Handling”try: response = client.send_email(...)except PoodleError as e: print(f"An API Error occurred: {e.message}") if e.status_code == 429: # Rate limit exceeded # The PoodleError __str__ method will format this nicely. # e.details will contain the specific error string from the API. print(str(e)) if e.details: print(f"Rate limit details: {e.details}") elif e.status_code == 400: # Validation error print(f"Validation error: {e.message}") if e.details: print(f"Validation details: {e.details}") elif e.status_code: print(f"Status Code: {e.status_code}") if e.details: print(f"Error details: {e.details}") else: # Network error or other non-HTTP error (e.details will be None) print(f"Error: {e}")
API Reference
Section titled “API Reference”PoodleClient
Section titled “PoodleClient”Constructor
Section titled “Constructor”PoodleClient( api_key: str, base_url: Optional[str] = None, timeout: Optional[float] = None)
api_key
: Your Poodle API key (required)base_url
: Optional custom API base URLtimeout
: Optional custom timeout for API requests in seconds
Methods
Section titled “Methods”send_email
Section titled “send_email”send_email( from_email: str, to_email: str, subject: str, html_content: Optional[str] = None, text_content: Optional[str] = None) -> Dict[str, Any]
Sends an email using the Poodle API.
Parameters:
from_email
: The sender’s email addressto_email
: The recipient’s email addresssubject
: The email subject linehtml_content
: Optional HTML content for the emailtext_content
: Optional plain text content for the email
Returns: A dictionary containing at least:
success
: Boolean indicating successmessage
: Success message from the API
Raises:
PoodleError
: If the API request fails or returns an error
PoodleError
Section titled “PoodleError”Custom exception class for Poodle-related errors.
Attributes:
message
: Human-readable error message (from APImessage
field)status_code
: HTTP status code from the API (if applicable)details
: Optional string containing additional error details from the API (from APIerror
field, orNone
)
Development
Section titled “Development”Setup Development Environment
Section titled “Setup Development Environment”- Clone the repository:
git clone https://github.com/usepoodle/poodle-python.gitcd poodle-python
- Install development dependencies:
pip install poetrypoetry install
Running Tests
Section titled “Running Tests”poetry run pytest
Code Style
Section titled “Code Style”This project uses:
- Black for code formatting
- Flake8 for linting
- MyPy for type checking
To check code style:
poetry run black .poetry run flake8poetry run mypy poodle
Contributing
Section titled “Contributing”Contributions are welcome! Please read our Contributing Guide for details on the process for submitting pull requests and our Code of Conduct.
License
Section titled “License”This project is licensed under the MIT License - see the LICENSE file for details.