Async client for sending OTPs via Bale API
Project description
BaleOTP
BaleOTP is a Python asynchronous client for sending OTPs (One-Time Passwords) through the Bale AI OTP API.
✨ New Features (0.1.0)
- Auto OTP Generation: Now automatically generates 6-digit OTP codes when none is provided
- Enhanced Result Object: Get both OTP code and full API response in a structured way
- Improved Error Handling: More specific exception classes for different error scenarios
- Better Phone Number Normalization: Supports more phone number formats
- Full Async Support: Works seamlessly in both synchronous and asynchronous contexts
📦 Installation
pip install --upgrade baleotp
🚀 Basic Usage
Sending OTP with auto-generated code:
from baleotp import OTPClient
client = OTPClient("your_client_id", "your_client_secret")
result = client.send_otp("09123456789") # No OTP provided = auto-generate
print(f"Sent OTP code: {result.code}")
print(f"Full response: {result.response}")
Sending with custom OTP:
result = client.send_otp("09123456789", 123456)
print(f"Used OTP code: {result.code}")
🔧 Advanced Usage
Async/Await Support:
import asyncio
from baleotp import OTPClient
async def main():
client = OTPClient("your_client_id", "your_client_secret")
result = await client.send_otp("09123456789")
print(result.code)
asyncio.run(main())
Available Exceptions:
from baleotp import (
InvalidClientError,
BadRequestError,
InvalidPhoneNumberError,
UserNotFoundError,
InsufficientBalanceError,
RateLimitExceededError
)
try:
client.send_otp("invalid_number")
except InvalidPhoneNumberError as e:
print(f"Phone number error: {e}")
📝 Phone Number Formats Supported
All these formats work:
09123456789989123456789+989123456789912345678900989123456789(non-standard but handled)
📜 License
MIT
BaleOTP یک کلاینت پایتونی غیرهمزمان برای ارسال رمزهای یکبار مصرف (OTP) از طریق API بله است.
✨ قابلیتهای جدید (نسخه 0.1.0)
- تولید خودکار کد: در صورت عدم ارائه کد، به صورت خودکار یک کد ۶ رقمی تولید میکند
- نتیجه ساختاریافته: دریافت همزمان کد و پاسخ کامل سرور در یک شیء سازمانیافته
- مدیریت خطاهای پیشرفته: کلاسهای خطای تخصصی برای سناریوهای مختلف
- پشتیبانی از فرمتهای بیشتر شماره تلفن
- پشتیبانی کامل از برنامههای ناهمزمان
🛠️ مثالهای پیشرفته
استفاده غیرهمزمان:
from baleotp import OTPClient
client = OTPClient("UserName", "PassWord")
result = client.send_otp("09123456789") # تولید خودکار کد
print(f"کد ارسال شده: {result.code}")
print(f"پاسخ سرور: {result.response}")
مدیریت خطاها:
from baleotp import InvalidPhoneNumberError
try:
client.send_otp("شماره نادرست")
except InvalidPhoneNumberError:
print("شماره تلفن نامعتبر است")
📞 فرمتهای شماره تلفن پشتیبانی شده
همه این فرمتها قابل استفاده هستند:
09123456789989123456789+989123456789912345678900989123456789(غیراستاندارد اما پشتیبانی میشود)
⚖️ مجوز
MIT
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 baleotp-0.1.0.tar.gz.
File metadata
- Download URL: baleotp-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb4ac7551dc2c8c7e5f66dbf37019ad343334d0bf310f7bcd4ca349d3127763
|
|
| MD5 |
19836c4f838b7151ab99fdedd3631bde
|
|
| BLAKE2b-256 |
72fae38c39615d96bd81a02a8b195032719d0e9e6688931c98e1ab15daf584e6
|
File details
Details for the file baleotp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: baleotp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02f718e6958a83638e01d7d7ca59a448ccc935c7241fe5dd002dacafb349e820
|
|
| MD5 |
5fc9c797437ea4e52411595a5180c587
|
|
| BLAKE2b-256 |
e4815d250078bc8667f59be22ed777af21581cf2c872f0deeee9173e034b3bb2
|