Official Temp Mail API (https://temp-mail.io) Wrapper for Python.
Project description
Temp Mail Python Library
Official Python library for the Temp Mail API. Create temporary email addresses and receive emails programmatically.
Installation
pip install temp-mail
Quick Start
from tempmail import TempMailClient
# Initialize the client
client = TempMailClient("your-api-key")
# Create a temporary email address
email = client.create_email()
print(f"Your temporary email: {email.email}")
# Check for messages
messages = client.list_email_messages(email.email)
for message in messages:
print(f"From: {message.from_addr}")
print(f"Subject: {message.subject}")
print(f"Body: {message.body_text}")
Features
- Create temporary email addresses - Generate disposable emails instantly
- List available domains - Get domains you can use for email creation
- Receive emails - Fetch messages sent to your temporary addresses
- Get individual messages - Retrieve specific messages by ID
- Get message source code - Access raw email source
- Download attachments - Download email attachments
- Delete messages - Clean up individual messages
- Delete emails - Remove email addresses and all their messages
- Rate limit monitoring - Track your API usage
- Error handling - Comprehensive exception handling
- Type hints - Full typing support for better development experience
API Reference
TempMailClient
The main client class for interacting with the Temp Mail API.
from tempmail import TempMailClient
# Basic initialization
client = TempMailClient("your-api-key")
# With custom parameters
client = TempMailClient(
"your-api-key",
base_url="https://api.temp-mail.io",
timeout=30
)
Creating Email Addresses
# Create random email
email = client.create_email()
# Create with specific domain
email = client.create_email(domain="example.com")
# Create with specific email address
email = client.create_email(email="mytest@example.com")
# Create with domain type preference
from tempmail.models import DomainType
email = client.create_email(domain_type=DomainType.PREMIUM)
Listing Domains
domains = client.list_domains()
for domain in domains:
print(f"Domain: {domain.name}, Type: {domain.type.value}")
Managing Messages
# List all messages for an email
messages = client.list_email_messages("test@example.com")
for message in messages:
print(f"From: {message.from_addr}")
print(f"Subject: {message.subject}")
print(f"CC: {message.cc}")
print(f"Attachments: {len(message.attachments or [])}")
# Get a specific message
message = client.get_message("message-id")
# Get message source code
source_code = client.get_message_source_code("message-id")
# Download an attachment
attachment_data = client.download_attachment("attachment-id")
# Delete a message
client.delete_message("message-id")
# Delete an entire email address and all its messages
client.delete_email("test@example.com")
Rate Limiting
# Get current rate limit status
rate_limit = client.get_rate_limit()
print(f"Limit: {rate_limit.limit}")
print(f"Remaining: {rate_limit.remaining}")
print(f"Used: {rate_limit.used}")
print(f"Reset time: {rate_limit.reset}")
# Access last rate limit from any request
last_rate_limit = client.last_rate_limit
if last_rate_limit:
print(f"Last known remaining: {last_rate_limit.remaining}")
Error Handling
The library provides specific exception types for different error conditions:
from tempmail import (
TempMailError, # Base exception
AuthenticationError, # Invalid API key
RateLimitError, # Rate limit exceeded
ValidationError, # Invalid parameters
)
try:
client = TempMailClient("invalid-key")
email = client.create_email()
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded")
except ValidationError as e:
print(f"Invalid parameters: {e}")
except TempMailError as e:
print(f"API error: {e}")
Development
Setup
# Clone the repository
git clone https://github.com/temp-mail-io/temp-mail-python
cd temp-mail-python
# Install uv (recommended)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync --dev
Running Tests
uv run pytest tests/
Code Quality
# Run all pre-commit hooks
uv run pre-commit run --all-files
# Or run individual tools
uv run ruff check # Linting
uv run ruff format # Formatting
uv run mypy tempmail/ # Type checking
Complete Example
from tempmail import TempMailClient, AuthenticationError, RateLimitError
# Initialize client
client = TempMailClient("your-api-key")
try:
# Create a temporary email
email = client.create_email()
print(f"Created email: {email.email}")
print(f"TTL: {email.ttl} seconds")
# List available domains
domains = client.list_domains()
print(f"Available domains: {len(domains)}")
# Check for messages (would be empty initially)
messages = client.list_email_messages(email.email)
print(f"Messages: {len(messages)}")
# Check rate limit
rate_limit = client.get_rate_limit()
print(f"Requests remaining: {rate_limit.remaining}/{rate_limit.limit}")
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded")
except Exception as e:
print(f"Error: {e}")
License
MIT License—see LICENSE file for details.
Links
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 temp_mail-1.0.1.tar.gz.
File metadata
- Download URL: temp_mail-1.0.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dccb2a62dd2ab1c02450ebb2088c61dc6a6e878b21066d1216566247d8d2438a
|
|
| MD5 |
fa50cec7eb1d3a78c83a3dbb33216739
|
|
| BLAKE2b-256 |
747506a0af9bae7ee0f577aeeadc81f486ffe576e4cb6445dd2080249850e585
|
File details
Details for the file temp_mail-1.0.1-py3-none-any.whl.
File metadata
- Download URL: temp_mail-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21b32303dcdf83b790ee69353f28a9f54fe1cc92dbf7df6d6f2241082b22a1a0
|
|
| MD5 |
fa57628ba6f329dc91195719da4c418e
|
|
| BLAKE2b-256 |
0d933efdc1499de2963e96a4ab3a692572874ffcb9c1d964066db8c8e10c697d
|