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
Metadata
Release files for baleotp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| baleotp-0.1.0.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| baleotp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.1 kB
Release files / baleotp-0.1.0.tar.gz
| Download URL | baleotp-0.1.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eeb4ac7551dc2c8c7e5f66dbf37019ad343334d0bf310f7bcd4ca349d3127763
|
|
BLAKE2b-256 checksum How to use checksums |
72fae38c39615d96bd81a02a8b195032719d0e9e6688931c98e1ab15daf584e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / baleotp-0.1.0-py3-none-any.whl
| Download URL | baleotp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02f718e6958a83638e01d7d7ca59a448ccc935c7241fe5dd002dacafb349e820
|
|
BLAKE2b-256 checksum How to use checksums |
e4815d250078bc8667f59be22ed777af21581cf2c872f0deeee9173e034b3bb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|