Official Python SDK for Verifly - Inbound 2FA Verification System with HMAC-SHA256 Authentication
Project description
Verifly Python SDK
Official Python SDK for Verifly - Inbound 2FA Verification System
⚠️ Important: This SDK uses HMAC-SHA256 signature authentication. Both API key and secret key are required.
Features
- ✅ HMAC-SHA256 Authentication - Secure API requests with cryptographic signatures
- ✅ Multi-channel Verification - SMS, WhatsApp, Email, Voice Call support
- ✅ Webhook Verification - Verify incoming webhook signatures
- ✅ Type Hints - Full type annotations for better IDE support
- ✅ Error Handling - Comprehensive error classes
- ✅ Session Management - Create, track, and manage verification sessions
- ✅ Balance Inquiry - Check account balance and transaction history
Installation
pip install verifly-sdk
Quick Start
from verifly import Verifly
# Initialize client (BOTH keys required)
verifly = Verifly(
api_key='your-api-key',
secret_key='your-secret-key'
)
# Create verification session
session = verifly.verification.create(
phone='5551234567',
methods=['sms', 'whatsapp']
)
print(f"Session ID: {session['sessionId']}")
print(f"Iframe URL: {session['iframeUrl']}")
Configuration
Required Keys
| Key | Purpose | Required | How to Get |
|---|---|---|---|
| API Key | Identify your application | ✅ REQUIRED | Dashboard → Application → API Key |
| Secret Key | HMAC signature generation | ✅ REQUIRED | Dashboard → Application → Secret Key |
from verifly import Verifly
# ✅ Basic configuration (both keys required)
verifly = Verifly(
api_key='your-api-key',
secret_key='your-secret-key'
)
# ✅ With additional options
verifly = Verifly(
api_key='your-api-key',
secret_key='your-secret-key',
timeout=60, # Request timeout in seconds
debug=True # Enable debug logging
)
Usage
Create Verification Session
# Multi-method verification
session = verifly.verification.create(
phone='5551234567',
methods=['sms', 'whatsapp', 'call']
)
# Email verification
session = verifly.verification.create(
email='user@example.com',
methods=['email']
)
# With custom data (returned in webhooks)
session = verifly.verification.create(
phone='5551234567',
methods=['sms', 'whatsapp'],
lang='tr',
webhook_url='https://mysite.com/webhook',
timeout=5,
data={'userId': '12345', 'orderId': 'ORD-789'} # Max 100KB
)
Response:
{
'sessionId': 'abc123...',
'iframeUrl': 'https://www.verifly.net/verify/iframe/abc123...',
'expiresAt': '2025-01-14T20:00:00.000Z',
'allowedMethods': ['sms', 'whatsapp'],
'method': None, # or 'sms' if only one method
'status': 'pending'
}
Get Session Status
status = verifly.verification.get('session-id')
if status['status'] == 'verified':
print('Verification successful!')
print(f"Verified at: {status['verifiedAt']}")
Response:
{
'sessionId': 'abc123...',
'status': 'verified',
'method': 'sms',
'verificationCode': '123456',
'recipientContact': '5551234567',
'verifiedAt': '2025-01-14T19:55:00.000Z'
}
Select Verification Method
If multiple methods are available, select one.
verifly.verification.select_method(
session_id='session-id',
method='sms',
recipient_contact='5551234567' # If not provided in create
)
Cancel Verification Session
Cancel an active verification session (user can retry later).
verifly.verification.cancel('session-id')
Abort Verification Session
Permanently abort a verification session (cannot be retried).
verifly.verification.abort('session-id')
Difference:
cancel()- Temporary cancellation, user can restartabort()- Permanent abort, session is completely terminated
Get Balance
Get account balance and recent transactions.
balance = verifly.verification.get_balance()
print(f"Balance: {balance['balance']} {balance['currency']}")
print(f"Recent transactions: {balance['recentTransactions']}")
Response:
{
'balance': 1500.00,
'currency': 'TRY',
'userId': '...',
'email': 'user@example.com',
'recentTransactions': [
{
'type': 'credit',
'amount': 500,
'description': 'Balance added',
'createdAt': '2025-01-14T...'
}
# ... more transactions
]
}
Webhooks
Verify Webhook Signature
Verify that a webhook request actually came from Verifly.
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/webhook/verifly', methods=['POST'])
def verifly_webhook():
# Get headers
signature = request.headers.get('X-Signature')
timestamp = request.headers.get('X-Timestamp')
# Get payload
payload = request.get_json()
# Verify signature
is_valid = verifly.webhook.verify(payload, signature, timestamp)
if not is_valid:
return jsonify({'error': 'Invalid signature'}), 401
# Process webhook
if payload['event'] == 'verification.success':
session_id = payload['sessionId']
custom_data = payload.get('customData') # Your custom data from create()
print(f"Verification completed: {session_id}")
print(f"Custom data: {custom_data}")
return jsonify({'success': True})
Construct Event (Auto-verify)
try:
event = verifly.webhook.construct_event(payload, signature, timestamp)
# Event is verified, safe to use
print(f"Event type: {event['event']}")
except ValueError as e:
print(f"Invalid webhook: {e}")
Error Handling
The SDK uses exceptions for error handling (standard Python practice).
Try-Except Pattern
from verifly import Verifly, AuthenticationError, InsufficientBalanceError, ValidationError
try:
session = verifly.verification.create(
phone='5551234567',
methods=['sms']
)
print('✅ Success:', session)
except AuthenticationError as e:
print(f'❌ Authentication failed: {e}')
# Check your API key and secret key
except InsufficientBalanceError as e:
print(f'❌ Insufficient balance: {e}')
print(f'Balance data: {e.balance_data}')
# User needs to add balance
except ValidationError as e:
print(f'❌ Validation error: {e}')
# Fix input parameters
except Exception as e:
print(f'❌ Unknown error: {e}')
Error Types
| Error Class | HTTP Status | Description |
|---|---|---|
AuthenticationError |
401 | Invalid API key or secret key |
ValidationError |
400 | Invalid request parameters |
InsufficientBalanceError |
402 | Not enough account balance |
NotFoundError |
404 | Session or resource not found |
RateLimitError |
429 | Too many requests |
ServerError |
500 | Server error |
Helper Function (Optional)
If you prefer {'success': bool, 'error': str} format:
def safe_verify(phone):
try:
session = verifly.verification.create(
phone=phone,
methods=['sms', 'whatsapp']
)
return {'success': True, 'data': session}
except Exception as e:
return {
'success': False,
'error': str(e),
'error_type': type(e).__name__
}
# Usage
result = safe_verify('5551234567')
if result['success']:
print('✅', result['data'])
else:
print('❌', result['error'])
Framework Integration
Flask
from flask import Flask, request, jsonify
from verifly import Verifly
app = Flask(__name__)
verifly = Verifly(api_key='...', secret_key='...')
@app.route('/verify/create', methods=['POST'])
def create_verification():
try:
data = request.get_json()
session = verifly.verification.create(
phone=data.get('phone'),
methods=['sms', 'whatsapp']
)
return jsonify({'success': True, 'data': session})
except Exception as e:
return jsonify({'success': False, 'error': str(e)}), 400
Django
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from verifly import Verifly
import json
verifly = Verifly(api_key='...', secret_key='...')
@csrf_exempt
def create_verification(request):
if request.method == 'POST':
try:
data = json.loads(request.body)
session = verifly.verification.create(
phone=data.get('phone'),
methods=['sms', 'whatsapp']
)
return JsonResponse({'success': True, 'data': session})
except Exception as e:
return JsonResponse({'success': False, 'error': str(e)}, status=400)
FastAPI
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from verifly import Verifly
app = FastAPI()
verifly = Verifly(api_key='...', secret_key='...')
class VerifyRequest(BaseModel):
phone: str
methods: list[str] = ['sms', 'whatsapp']
@app.post('/verify/create')
async def create_verification(request: VerifyRequest):
try:
session = verifly.verification.create(
phone=request.phone,
methods=request.methods
)
return {'success': True, 'data': session}
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
API Reference
Verifly
Constructor
Verifly(api_key, secret_key, timeout=30, debug=False)
Methods
set_secret_key(secret_key)- Update secret keyset_debug(enabled)- Enable/disable debug mode
Verification
Methods
create(phone=None, email=None, methods=None, lang=None, webhook_url=None, redirect_url=None, timeout=None, data=None)- Create verification sessionget(session_id)- Get session statusselect_method(session_id, method, recipient_contact=None)- Select verification methodcancel(session_id)- Cancel session (temporary)abort(session_id)- Abort session (permanent)get_balance()- Get account balance and transactions
Webhook
Methods
verify(payload, signature, timestamp)- Verify webhook signaturegenerate_signature(payload, timestamp)- Generate signature (for testing)construct_event(payload, signature, timestamp)- Construct verified event object
Support
- 📧 Email: info@verifly.net
- 🌐 Website: https://www.verifly.net
- 📚 Documentation: https://www.verifly.net/docs
- 🐛 Issues: https://github.com/tlgsn/verifly-python-sdk/issues
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Made with ❤️ by SOCIFLY SOFTWARE LTD.
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 verifly_sdk-1.0.1.tar.gz.
File metadata
- Download URL: verifly_sdk-1.0.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffe64b8522435cb5d40f63d212cc5933662e033e53cebbf82d831ceace36e7e5
|
|
| MD5 |
f713af9022a522826d27fb5e081bbc44
|
|
| BLAKE2b-256 |
2e826ff2d168a109f625e79219cfdc8eeb9e05466fbad5a1c56e523d35a7e955
|
File details
Details for the file verifly_sdk-1.0.1-py3-none-any.whl.
File metadata
- Download URL: verifly_sdk-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c643c8d059fd5daf772bd606ee5d38c835d7720aeab6124c9a041237b9e9eae7
|
|
| MD5 |
890a60dff74ac3430b03ae5ca9f2c19f
|
|
| BLAKE2b-256 |
1caef469885d46a8cb5afdb19378e027f436639e52239a4b8118cd1a9da8fed3
|