Python SDK for Contacted email API service
Project description
Contacted Python SDK
Official Python SDK for the Contacted API.
Getting Started
1. Get Your API Key
First, sign up and get your API key at https://contacted.io
2. Installation
pip install contacted
Quick Start
from contacted import ContactedAI
contacted = ContactedAI(api_key='your-api-key-here')
# Send a message
result = contacted.send({
'from': 'sender@example.com',
'to': 'receiver@example.com',
'prompt': 'Generate a personalized welcome email',
'data': {
'name': 'John Doe',
'link': 'https://example.com'
}
})
print('Message sent:', result)
Type Hints Support
The SDK includes comprehensive type hints for better IDE support:
from contacted import ContactedAI
from typing import Dict, Any
contacted = ContactedAI(api_key='your-api-key-here')
options: Dict[str, Any] = {
'from': 'sender@example.com',
'to': 'receiver@example.com',
'prompt': 'Generate email content',
'data': {'name': 'John'}
}
result = contacted.send(options)
API Reference
ContactedAI(api_key, base_url=None, timeout=30)
Creates a new ContactedAI client instance.
Parameters:
api_key(str, required): Your ContactedAI API keybase_url(str, optional): Custom API base URLtimeout(int, optional): Request timeout in seconds (default: 30)
contacted.send(options)
Send a message through the ContactedAI API.
Parameters:
from(str, required): Valid sender email addressto(str, required): Valid receiver email addressprompt(str, required): AI prompt (10-250 characters)data(dict, optional): Additional data for personalization
Validation Rules:
- Email addresses must be valid format
- Prompt must be 10-250 characters
- Data keys cannot contain spaces
- Data keys must be non-empty strings
Returns: dict - API response
Raises: ValueError - If validation fails or API error occurs
contacted.status()
Check the API status and health.
Returns: dict - Status information
Error Handling
The SDK provides detailed error messages for validation and API errors:
try:
contacted.send({
'from': 'invalid-email',
'to': 'user@example.com',
'prompt': 'short'
})
except ValueError as e:
print(f'Error: {e}')
# "Invalid 'from' email address format"
Examples
Basic Usage
from contacted import ContactedAI
import os
contacted = ContactedAI(api_key=os.getenv('CONTACTED_API_KEY'))
result = contacted.send({
'from': 'noreply@myapp.com',
'to': 'user@example.com',
'prompt': 'Create a welcome email for a new premium user',
'data': {
'username': 'john_doe',
'plan': 'premium',
'dashboard_url': 'https://app.myservice.com'
}
})
With Error Handling
try:
result = contacted.send(options)
print(f'✅ Email sent successfully: {result["id"]}')
except ValueError as e:
if 'Invalid' in str(e):
print(f'❌ Validation error: {e}')
else:
print(f'❌ API error: {e}')
Environment Variables
import os
from contacted import ContactedAI
# Use environment variable for API key
contacted = ContactedAI(
api_key=os.getenv('CONTACTED_API_KEY'),
timeout=60 # Custom timeout
)
License
MIT
Support
- 📧 Email: support@contacted.io
- 🐛 Issues: GitHub Issues
- 📖 Documentation: contacted.gitbook.io
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contacted-0.0.3.tar.gz.
File metadata
- Download URL: contacted-0.0.3.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7a402ad1dfbe9202493804964046c19e6ebd7eb7e6d1e3fca0e2597b825d9c1
|
|
| MD5 |
7df05706f598f8f64b769a38b7e46a47
|
|
| BLAKE2b-256 |
49cd5b400e3689b4d0eb0e91448c096acbd19fe01546517e26de2fcdbbaa45b5
|
File details
Details for the file contacted-0.0.3-py3-none-any.whl.
File metadata
- Download URL: contacted-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe3d44f95df07cf7adb3526a628c600d3ce0229679ac4efe7e4901a7464cd375
|
|
| MD5 |
bb31e49c8b98ab23d70d611b1f5a7488
|
|
| BLAKE2b-256 |
ae9b19e0b9941ed56ce6ae88e063f809ec29f851713fca4c85f62c21d865ce59
|