Python - Getting Started
This guide will help you get up and running with the Mailblock Python SDK in just a few minutes.Prerequisites
- Python 3.8 or higher
- A Mailblock API key from MailBlock
Installation
Install the SDK using pip:Basic Setup
First follow the steps from: Basic Setup Import and initialize the SDK with your API key:Sending Your First Email
Here’s how to send a simple email using the fluent builder pattern:EmailData
class directly:
Using Method Chaining
The SDK also supports a fluent, chainable API:Sending HTML Emails
You can send rich HTML emails instead of plain text:EmailData
:
Sending to Multiple Recipients
Send emails to multiple people with CC and BCC support:Scheduling Emails
Schedule emails to be sent at a future date and time:EmailData
:
Managing Scheduled Emails
Canceling Scheduled Emails
Cancel scheduled emails before they’re sent:Updating Scheduled Emails
Modify scheduled emails before they’re sent:Environment Configuration
For production applications, use environment variables for your API key:Debug Mode
Enable debug mode during development to see detailed logs:- Request details and timing
- API responses
- Error information
- Performance metrics
Custom Logger
You can also provide your own logger:Type Safety Support
The SDK includes full type hints and works great with mypy:Context Manager Support
Use the SDK with context managers for proper resource cleanup:Error Handling
The SDK uses a consistent response format and exception hierarchy:Advanced Usage
Bulk Email Sending
Send multiple emails efficiently with async:Installation Options
Install specific extras based on your needs:Next Steps
Now that you’ve sent your first email with Python, you might want to:- Explore the full API reference
- See more examples
- Learn about advanced error handling
- Check out async/await patterns
- Set up proper logging for production
Need Help?
- 💬 GitHub Issues
- 📧 Email support: contact@block-forge.de
- 📚 Full Documentation
- 🐍 PyPI Package
Key Differences from Node.js
- Use
from_email
instead offrom
(Python keyword conflict) - Use
send_sync()
for synchronous operations,send()
for async - Import specific classes:
from mailblock import MailBlock, EmailData
- Exception handling with try/catch using Python exception classes
- Context managers supported with
with
statement - Full type hints support for IDEs and mypy