OneRouter Python SDK
Official Python SDK for OneRouter - Unified API for payments, SMS, email, and more.
Installation
pip install onerouter
Quick Start
from onerouter import OneRouter
client = OneRouter(api_key="unf_live_xxx")
# Create payment
order = await client.payments.create(
amount=500.00,
currency="INR"
)
print(f"Order ID: {order['transaction_id']}")
print(f"Checkout URL: {order['checkout_url']}")
Features
- Unified API: Single interface for Razorpay, PayPal, Twilio, Resend
- Async & Sync: Support for both async/await and synchronous code
- Automatic Retries: Built-in retry logic with exponential backoff
- Idempotency: Prevent duplicate requests automatically
- Type Hints: Full type support for IDE autocomplete
- Error Handling: Comprehensive exception hierarchy
Usage Examples
Async Usage (Recommended)
import asyncio
from onerouter import OneRouter
async def main():
async with OneRouter(api_key="unf_live_xxx") as client:
# Create payment
order = await client.payments.create(
amount=500.00,
currency="INR",
receipt="order_123"
)
# Get payment status
status = await client.payments.get(order['transaction_id'])
# Create refund
refund = await client.payments.refund(
payment_id=order['provider_order_id'],
amount=100.00 # Partial refund
)
asyncio.run(main())
Sync Usage
from onerouter import OneRouterSync
client = OneRouterSync(api_key="unf_live_xxx")
try:
order = client.payments.create(
amount=500.00,
currency="INR"
)
print(f"Order: {order['transaction_id']}")
finally:
client.close()
Send SMS (Twilio)
async with OneRouter(api_key="unf_live_xxx") as client:
# Send SMS
sms = await client.sms.send(
to="+1234567890",
body="Your verification code is 123456"
)
print(f"Message SID: {sms['message_id']}")
print(f"Status: {sms['status']}")
# Check delivery status
status = await client.sms.get(sms['message_id'])
print(f"Delivery status: {status['status']}")
Send Email (Resend)
async with OneRouter(api_key="unf_live_xxx") as client:
# Send email
email = await client.email.send(
to="user@example.com",
subject="Welcome to OneRouter!",
html_body="<h1>Welcome!</h1><p>Thanks for signing up.</p>",
from_email="hello@yourdomain.com" # Optional
)
print(f"Email ID: {email['email_id']}")
print(f"Status: {email['status']}")
Subscriptions
async with OneRouter(api_key="unf_live_xxx") as client:
# Create subscription
subscription = await client.subscriptions.create(
plan_id="plan_monthly_99",
customer_notify=True,
total_count=12
)
# Get subscription
sub_details = await client.subscriptions.get(subscription['id'])
# Cancel subscription
await client.subscriptions.cancel(
subscription_id=subscription['id'],
cancel_at_cycle_end=True
)
Payment Links
async with OneRouter(api_key="unf_live_xxx") as client:
# Create payment link
link = await client.payment_links.create(
amount=999.00,
description="Premium Plan",
customer_email="user@example.com"
)
print(f"Share this link: {link['short_url']}")
Error Handling
from onerouter import (
OneRouter,
AuthenticationError,
RateLimitError,
ValidationError,
APIError
)
async with OneRouter(api_key="unf_live_xxx") as client:
try:
order = await client.payments.create(amount=500.00)
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
except ValidationError as e:
print(f"Validation error: {e}")
except APIError as e:
print(f"API error ({e.status_code}): {e}")
Configuration
client = OneRouter(
api_key="unf_live_xxx",
base_url="https://api.onerouter.dev", # Optional: Custom API URL
timeout=30, # Optional: Request timeout (seconds)
max_retries=3 # Optional: Max retry attempts
)
API Reference
Payments
| Method | Description |
|---|---|
payments.create(amount, currency, ...) |
Create a payment order |
payments.get(transaction_id) |
Get payment details |
payments.refund(payment_id, amount) |
Create refund |
SMS
| Method | Description |
|---|---|
sms.send(to, body) |
Send SMS message |
sms.get(message_id) |
Get delivery status |
| Method | Description |
|---|---|
email.send(to, subject, html_body, ...) |
Send email |
email.get(email_id) |
Get email status |
Subscriptions
| Method | Description |
|---|---|
subscriptions.create(plan_id, ...) |
Create subscription |
subscriptions.get(subscription_id) |
Get subscription details |
subscriptions.cancel(subscription_id) |
Cancel subscription |
Payment Links
| Method | Description |
|---|---|
payment_links.create(amount, ...) |
Create payment link |
Testing
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=onerouter tests/
Requirements
- Python 3.8+
- httpx
- pydantic
Support
- Documentation: https://docs.onerouter.dev
- PyPI: https://pypi.org/project/onerouter/
- GitHub: https://github.com/onerouter/onerouter-python
- Email: support@onerouter.dev
License
MIT License - see LICENSE file for details.
Related
Metadata
Release files for onerouter 2.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| onerouter-2.0.6.tar.gz | 17.5 kB | Without provenance | Details for onerouter-2.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| onerouter-2.0.6-py3-none-any.whl | Python 3 | none | any | Details for onerouter-2.0.6-py3-none-any.whl |
Total release size: 37.9 kB
Release files / onerouter-2.0.6.tar.gz
| Download URL | onerouter-2.0.6.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5f0c79bee66461873b5a03519ebbccdfcb8d0ffa19d0b59073859d1c510ceb0
|
|
BLAKE2b-256 checksum How to use checksums |
556c5a8837510413da8eb99ce3369eb2d7c975954cc922f9d4d905a3ad146032
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / onerouter-2.0.6-py3-none-any.whl
| Download URL | onerouter-2.0.6-py3-none-any.whl |
|---|---|
| Size | 20.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd50a40a5e68c34cc5d2451a42c52699461b971aa2890bda30cb94e588fdb00e
|
|
BLAKE2b-256 checksum How to use checksums |
bb842f609deb9820a828a711a7fa0b63001e428bcf2ec8b407b98efada1d2566
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for onerouter 2.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.