Client Configuration
This page covers all configuration options for the VaultSandbox Python client.
Basic Configuration
Section titled “Basic Configuration”Creating a Client
Section titled “Creating a Client”from vaultsandbox import VaultSandboxClient
async with VaultSandboxClient( base_url="https://mail.example.com", api_key="your-api-key",) as client: # Use client... passConfiguration Options
Section titled “Configuration Options”Required Options
Section titled “Required Options”api_key
Section titled “api_key”Type: str
Description: API key for authentication
Example:
api_key="vs_1234567890abcdef..."Best practices:
- Store in environment variables
- Never commit to version control
- Rotate periodically
Optional Options
Section titled “Optional Options”base_url
Section titled “base_url”Type: str
Default: "https://smtp.vaultsandbox.com"
Description: Base URL of your VaultSandbox Gateway
Examples:
base_url="https://mail.example.com"base_url="http://localhost:3000" # Local developmentRequirements:
- Must include protocol (
https://orhttp://) - Should not include trailing slash
- Must be accessible from your application
timeout
Section titled “timeout”Type: int (milliseconds)
Default: 30000
Description: HTTP request timeout in milliseconds
Examples:
timeout=30000 # 30 seconds (default)timeout=60000 # 60 seconds for slow networkstimeout=10000 # 10 seconds for fast networksstrategy
Section titled “strategy”Type: DeliveryStrategyType
Default: DeliveryStrategyType.AUTO
Description: Email delivery strategy
Options:
DeliveryStrategyType.AUTO- Automatically choose best strategy (tries SSE first, falls back to polling)DeliveryStrategyType.SSE- Server-Sent Events for real-time deliveryDeliveryStrategyType.POLLING- Poll for new emails at intervals
Examples:
from vaultsandbox import DeliveryStrategyType
strategy=DeliveryStrategyType.AUTO # Recommendedstrategy=DeliveryStrategyType.SSE # Force SSEstrategy=DeliveryStrategyType.POLLING # Force pollingWhen to use each:
AUTO: Most use cases (recommended)SSE: When you need real-time, low-latency deliveryPOLLING: When SSE is blocked by firewall/proxy
max_retries
Section titled “max_retries”Type: int
Default: 3
Description: Maximum retry attempts for failed HTTP requests
Examples:
max_retries=3 # Defaultmax_retries=5 # More resilientmax_retries=0 # No retriesretry_delay
Section titled “retry_delay”Type: int (milliseconds)
Default: 1000
Description: Base delay between retry attempts (uses exponential backoff)
Examples:
retry_delay=1000 # 1s, 2s, 4s, ...retry_delay=500 # 500ms, 1s, 2s, ...retry_delay=2000 # 2s, 4s, 8s, ...retry_on_status_codes
Section titled “retry_on_status_codes”Type: tuple[int, ...]
Default: (408, 429, 500, 502, 503, 504)
Description: HTTP status codes that trigger a retry
Example:
retry_on_status_codes=(408, 429, 500, 502, 503, 504) # Defaultretry_on_status_codes=(500, 502, 503) # Only server errorsretry_on_status_codes=() # Never retrypolling_interval
Section titled “polling_interval”Type: int (milliseconds)
Default: 2000
Description: Polling interval when using polling strategy
Examples:
polling_interval=2000 # Poll every 2 seconds (default)polling_interval=5000 # Poll every 5 secondspolling_interval=500 # Poll every 500ms (aggressive)Considerations:
- Lower = more responsive, more API calls
- Higher = less API calls, slower detection
- Subject to rate limiting
polling_max_backoff
Section titled “polling_max_backoff”Type: int (milliseconds)
Default: 30000
Description: Maximum backoff delay for polling strategy
Examples:
polling_max_backoff=30000 # 30 seconds max (default)polling_max_backoff=60000 # 60 seconds maxsse_reconnect_interval
Section titled “sse_reconnect_interval”Type: int (milliseconds)
Default: 5000
Description: Initial delay before SSE reconnection attempt
Examples:
sse_reconnect_interval=5000 # Defaultsse_reconnect_interval=1000 # Faster reconnectionsse_reconnect_interval=10000 # Slower reconnectionNote: Uses exponential backoff (5s, 10s, 20s, …)
sse_max_reconnect_attempts
Section titled “sse_max_reconnect_attempts”Type: int
Default: 10
Description: Maximum SSE reconnection attempts before giving up
Examples:
sse_max_reconnect_attempts=10 # Defaultsse_max_reconnect_attempts=100 # Keep trying longersse_max_reconnect_attempts=3 # Give up quicklyConfiguration Examples
Section titled “Configuration Examples”Production Configuration
Section titled “Production Configuration”import osfrom vaultsandbox import VaultSandboxClient, DeliveryStrategyType
async with VaultSandboxClient( # Required api_key=os.environ["VAULTSANDBOX_API_KEY"], base_url=os.environ["VAULTSANDBOX_URL"],
# Recommended production settings strategy=DeliveryStrategyType.AUTO, max_retries=5, retry_delay=2000, sse_reconnect_interval=5000, sse_max_reconnect_attempts=10,) as client: # Use client... passCI/CD Configuration
Section titled “CI/CD Configuration”import osfrom vaultsandbox import VaultSandboxClient, DeliveryStrategyType
async with VaultSandboxClient( api_key=os.environ["VAULTSANDBOX_API_KEY"], base_url=os.environ["VAULTSANDBOX_URL"],
# Faster polling for CI strategy=DeliveryStrategyType.AUTO, polling_interval=1000, # Poll every second max_retries=3, retry_delay=500,) as client: # Use client... passDevelopment Configuration
Section titled “Development Configuration”from vaultsandbox import VaultSandboxClient, DeliveryStrategyType
async with VaultSandboxClient( base_url="http://localhost:3000", api_key="dev-api-key",
# Aggressive settings for fast feedback strategy=DeliveryStrategyType.POLLING, # More reliable in dev polling_interval=500, # Very responsive max_retries=1, # Fail fast) as client: # Use client... passHigh-Reliability Configuration
Section titled “High-Reliability Configuration”import osfrom vaultsandbox import VaultSandboxClient, DeliveryStrategyType
async with VaultSandboxClient( api_key=os.environ["VAULTSANDBOX_API_KEY"], base_url=os.environ["VAULTSANDBOX_URL"],
# Maximum reliability max_retries=10, retry_delay=2000, retry_on_status_codes=(408, 429, 500, 502, 503, 504), sse_reconnect_interval=1000, sse_max_reconnect_attempts=100,) as client: # Use client... passEnvironment Variables
Section titled “Environment Variables”Store configuration in environment variables:
.env File
Section titled “.env File”VAULTSANDBOX_URL=https://mail.example.comVAULTSANDBOX_API_KEY=vs_1234567890abcdef...Usage with python-dotenv
Section titled “Usage with python-dotenv”import osfrom dotenv import load_dotenvfrom vaultsandbox import VaultSandboxClient
load_dotenv() # Load .env file
async with VaultSandboxClient( api_key=os.environ["VAULTSANDBOX_API_KEY"], base_url=os.environ.get("VAULTSANDBOX_URL", "https://smtp.vaultsandbox.com"),) as client: # Use client... passUsage without python-dotenv
Section titled “Usage without python-dotenv”import osfrom vaultsandbox import VaultSandboxClient
async with VaultSandboxClient( api_key=os.environ["VAULTSANDBOX_API_KEY"], base_url=os.environ.get("VAULTSANDBOX_URL", "https://smtp.vaultsandbox.com"),) as client: # Use client... passContext Manager
Section titled “Context Manager”The client is designed to be used as an async context manager, which ensures proper cleanup:
async with VaultSandboxClient(api_key=api_key) as client: inbox = await client.create_inbox() # Use inbox...# Client is automatically closed hereManual Close
Section titled “Manual Close”If you can’t use the context manager, call close() manually:
client = VaultSandboxClient(api_key=api_key)
try: inbox = await client.create_inbox() # Use inbox...finally: await client.close()What close() Does
Section titled “What close() Does”- Terminates all active SSE connections
- Stops all polling operations
- Cleans up resources
Note: close() does NOT delete inboxes from the server. Inboxes expire based on their TTL. Use delete_all_inboxes() to explicitly delete inboxes.
Strategy Selection Guide
Section titled “Strategy Selection Guide”Auto (Recommended)
Section titled “Auto (Recommended)”Use when: You want optimal performance with automatic fallback
Behavior:
- Tries SSE first
- Falls back to polling if SSE fails
- Automatically reconnects on errors
Pros:
- Best of both worlds
- No manual configuration needed
- Resilient to network issues
Cons:
- Slightly more complex internally
SSE (Server-Sent Events)
Section titled “SSE (Server-Sent Events)”Use when: You need real-time, low-latency delivery
Behavior:
- Persistent connection to server
- Push-based email notification
- Instant delivery
Pros:
- Real-time delivery (no polling delay)
- Efficient (no repeated HTTP requests)
- Deterministic tests
Cons:
- Requires persistent connection
- May be blocked by some proxies/firewalls
- More complex error handling
Polling
Section titled “Polling”Use when: SSE is blocked or unreliable
Behavior:
- Periodic HTTP requests for new emails
- Pull-based email retrieval
- Configurable interval
Pros:
- Works in all network environments
- No persistent connection required
- Simple and predictable
Cons:
- Delay based on polling interval
- More HTTP requests
- Less efficient than SSE
Best Practices
Section titled “Best Practices”Security
Section titled “Security”Do:
import os
# Use environment variablesasync with VaultSandboxClient( api_key=os.environ["VAULTSANDBOX_API_KEY"], base_url=os.environ["VAULTSANDBOX_URL"],) as client: passDon’t:
# Hard-code credentialsasync with VaultSandboxClient( api_key="vs_1234567890...", # Never do this base_url="https://mail.example.com",) as client: passResource Management
Section titled “Resource Management”Do:
async with VaultSandboxClient(api_key=api_key) as client: await run_tests(client)# Client automatically closedDon’t:
client = VaultSandboxClient(api_key=api_key)await run_tests(client)# Forgot to close, resources leakError Handling
Section titled “Error Handling”Do:
from vaultsandbox import ApiError, NetworkError
try: inbox = await client.create_inbox()except ApiError as e: print(f"API error ({e.status_code}): {e.message}")except NetworkError as e: print(f"Network error: {e}")Next Steps
Section titled “Next Steps”- Core Concepts: Inboxes - Learn about inboxes
- Managing Inboxes - Common inbox operations
- Testing Patterns - Integrate with your tests
- API Reference: Client - Full API documentation