Installation
Install the EasyOTP Python SDK using pip:Quick Start
Initialization
Create a new EasyOTP client instance with your API key:Configuration Options
string
Base URL for the API. Defaults to
https://app.easyotp.dev/api/v1.Methods
send()
Send a verification code via SMS, Email, or Voice.Parameters
string
required
Communication channel. Must be one of:
sms, email, or voicestring
required
Recipient address:
- For SMS/Voice: E.164 formatted phone number (e.g.,
+1234567890) - For Email: Valid email address (e.g.,
[email protected])
string
Custom message template. Use
{code} as a placeholder for the verification code.Default: "Your verification code is: {code}"string
Email subject line (only used when
channel is email)Default: "Your Verification Code"int
Code expiration time in seconds. Must be between 60 and 3600.Default:
300 (5 minutes)string
Custom verification code. Must be a numeric string between 4-10 digits.If not provided, a code will be automatically generated.
Returns
bool
Always
True for successful requestsstr
Unique identifier for this verification. Use this when calling
verify().str
ISO 8601 timestamp when the code expires
str
Unique request identifier for debugging
verify()
Verify a code that was previously sent.Parameters
string
required
The verification ID returned from the
send() methodstring
required
The verification code to check. Must be a numeric string between 4-10 digits.
Returns
bool
Always
True for successful requests (even if the code is invalid)bool
True if the code was correct and not expired, False otherwisestr
Human-readable result message. Possible values:
"Code verified successfully""Invalid code""Code expired""Code already used"
str
Unique request identifier for debugging
Examples
Complete Verification Flow
Sending via Different Channels
Error Handling
The SDK raises exceptions for failed requests. Always wrap API calls in try-except blocks:Flask Integration Example
Django Integration Example
Error Handling
The SDK raises custom exceptions for different error types:Exception Classes
EasyOTPError: Base exception for all SDK errorsAuthenticationError: Raised for 401 errors (invalid API key)InsufficientCreditsError: Raised for 402 errors (insufficient credits)ForbiddenError: Raised for 403 errors (API key disabled)NotFoundError: Raised for 404 errors (verification not found)RateLimitError: Raised for 429 errors (rate limit exceeded)ServerError: Raised for 500 errors (internal server error)
Error Object Properties
All exceptions include:message: Human-readable error messagestatus_code: HTTP status coderequest_id: Unique request identifier for debuggingretry_after: Seconds to wait before retrying (for rate limit errors)
Common Error Codes
Type Hints
The SDK includes type hints for better IDE support:Best Practices
Rate limiting: The SDK automatically handles rate limit responses. Check for
retry_after in exception objects to inform users when they can retry.Additional Resources
PyPI Package
View on PyPI
API Reference
Complete REST API documentation
Quickstart Guide
Get started in 5 minutes
Support
Get help from our team