Official Python SDK for Wotp — WhatsApp OTP, self-hosted, one command.
Project description
wotp
Official Python SDK for Wotp — WhatsApp OTP, self-hosted, one command.
Installation
pip install wotp
Quick Start
from wotp import create_client
client = create_client("http://localhost:54321", "wotp_anon_xxx")
# Send an OTP
resp = client.send_otp("+212600000000")
print(f"Token: {resp.token}, expires at: {resp.expires_at}")
# Verify the code entered by the user
result = client.verify_otp(resp.token, "483920")
# Send a text message
text_res = client.send_text("+212600000000", "Hello world")
# Send a media message
media_res = client.send_media("+212600000000", url="https://example.com/image.png")
# List chats
chats = client.get_chats()
print(f"Verified: {result.verified}")
API Reference
create_client(url, api_key, **options)
Creates a new Wotp client instance.
| Parameter | Type | Description |
|---|---|---|
url |
str |
Base URL of your Wotp instance |
api_key |
str |
Your anon or service API key |
max_retries |
int |
Max retries on transient errors (default: 3) |
retry_delay |
float |
Base delay in seconds between retries (default: 0.5) |
timeout |
float |
Request timeout in seconds (default: 10.0) |
client.send_otp(phone)
Send an OTP to the given phone number.
- Parameters:
phone— E.164 formatted phone number - Returns:
SendOTPResponsewith.tokenand.expires_at - Raises:
RateLimitError
client.verify_otp(token, code)
Verify an OTP code against a previously issued token.
- Parameters:
token— fromsend_otp,code— the user-entered code - Returns:
VerifyOTPResponsewith.verified,.phone,.attempts_remaining - Raises:
ExpiredTokenError,InvalidCodeError
client.health()
Check the health of the Wotp instance.
- Returns:
HealthResponsewith.status,.phone,.uptime_seconds
Error Handling
The SDK raises typed exceptions for business failures:
from wotp import create_client, RateLimitError, ExpiredTokenError, InvalidCodeError
client = create_client("http://localhost:54321", "wotp_anon_xxx")
try:
result = client.verify_otp(token, code)
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except ExpiredTokenError:
print("Token expired — request a new OTP")
except InvalidCodeError as e:
print(f"Wrong code. {e.attempts_remaining} attempts left")
| Exception | When |
|---|---|
RateLimitError |
Phone/IP exceeded rate limit (HTTP 429) |
ExpiredTokenError |
Token has expired (HTTP 410 or expired_token) |
InvalidCodeError |
Wrong OTP code (HTTP 400 + invalid_code) |
WotpError |
Base class for all SDK errors |
Context Manager
The client can be used as a context manager to ensure proper cleanup:
with create_client("http://localhost:54321", "wotp_anon_xxx") as client:
resp = client.send_otp("+212600000000")
Auto-Retry
Transient errors (502, 503, 504, network timeouts) are automatically retried with exponential backoff. Business errors are never retried.
Requirements
- Python ≥ 3.10
- A running Wotp instance
License
MIT — see LICENSE for details.
Project details
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 wotp-1.0.0.tar.gz.
File metadata
- Download URL: wotp-1.0.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
336a36f3c314f146eb97e59517c19d3cbc0bdb60ef040e4d5c466fd1724c7af2
|
|
| MD5 |
396099eb691c1dbf664dc404dbf8b03e
|
|
| BLAKE2b-256 |
9063f00a54a3f7bdcbd3881b98e42315dd4f9d19bfbf8c6ee51a905ef0911d91
|
Provenance
The following attestation bundles were made for wotp-1.0.0.tar.gz:
Publisher:
release.yml on raucheacho/wotp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wotp-1.0.0.tar.gz -
Subject digest:
336a36f3c314f146eb97e59517c19d3cbc0bdb60ef040e4d5c466fd1724c7af2 - Sigstore transparency entry: 2170804081
- Sigstore integration time:
-
Permalink:
raucheacho/wotp@e3f3a97b7622899f63d4eeee5d626f71eccbf9b6 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/raucheacho
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3f3a97b7622899f63d4eeee5d626f71eccbf9b6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file wotp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: wotp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee0aedd6774d58c65d27bdaebab9217412964d477b204d031c583799261b67cc
|
|
| MD5 |
e5d6b896a0a163a9efa8504bf554cb34
|
|
| BLAKE2b-256 |
51716787992765d248db58fe88d1c036e069b81a023dcfd296fe3154a4526e9f
|
Provenance
The following attestation bundles were made for wotp-1.0.0-py3-none-any.whl:
Publisher:
release.yml on raucheacho/wotp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wotp-1.0.0-py3-none-any.whl -
Subject digest:
ee0aedd6774d58c65d27bdaebab9217412964d477b204d031c583799261b67cc - Sigstore transparency entry: 2170804132
- Sigstore integration time:
-
Permalink:
raucheacho/wotp@e3f3a97b7622899f63d4eeee5d626f71eccbf9b6 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/raucheacho
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3f3a97b7622899f63d4eeee5d626f71eccbf9b6 -
Trigger Event:
push
-
Statement type: