safwatech-otp
Official Python SDK for the Safwatech OTP / verification platform — OTP (push / SMS / email / WhatsApp), TOTP authenticator (RFC 6238) with backup codes, magic links, silent push approval, and WebAuthn / passkeys.
pip install safwatech-otp
Requires Python ≥ 3.9. Single runtime dependency: requests.
Quick start
from safwatech_otp import OTPClient
client = OTPClient(
api_key="sk_test_…", # or sk_live_…
base_url="https://otp.safwatech.com.ly",
)
sent = client.send_otp("+218911234567", channel="sms", reference_id="order-42")
# When using a sandbox key, the response includes the otp_code so you can
# round-trip without hitting a real SMS provider:
if code := sent["result"].get("otp_code"):
client.verify_otp("+218911234567", code, reference_id="order-42")
API keys are issued from the client portal. sk_test_* keys put the call in
sandbox mode — no real delivery, no quota consumption, responses are
stamped with X-Sandbox: true.
Response envelope
All endpoints return a JSON envelope; OTPClient returns the decoded body
verbatim so you can read the platform's payload structure directly:
{
"status": "success",
"result": {...} # endpoint-specific
}
Errors raise OTPClientError with the HTTP status, decoded payload, and
the Retry-After value when present:
from safwatech_otp import OTPClientError
try:
client.send_otp("+218911234567")
except OTPClientError as exc:
if exc.status == 429:
time.sleep(exc.retry_after or 1)
...
Methods
| Surface | Methods |
|---|---|
| OTP | send_otp · verify_otp · get_status · usage |
| Scheduled | schedule_otp · cancel_scheduled · list_scheduled |
| TOTP | enroll_totp · verify_totp · totp_status · unenroll_totp · generate_backup_codes |
| Magic links | send_magic_link · get_magic_link · cancel_magic_link · wait_for_magic_link |
| Silent push auth | request_auth · get_auth_request · cancel_auth_request · wait_for_auth |
| WebAuthn / passkeys | webauthn_register · webauthn_authenticate · get_webauthn · cancel_webauthn · wait_for_webauthn |
The wait_for_* helpers poll the matching get_* endpoint until the request
reaches a terminal state (e.g. consumed | expired | cancelled for magic
links) or the timeout elapses; they return the final polled response.
Verifying webhooks
from safwatech_otp import verify_webhook
if not verify_webhook(
raw_body=request.body,
secret="the callback_secret you set on your service",
signature_header=request.headers.get("X-Webhook-Signature", ""),
timestamp_header=request.headers.get("X-Webhook-Timestamp", ""),
):
abort(401)
The header format is X-Webhook-Signature: v1=<hex> over "{timestamp}.{body}"
(HMAC-SHA256). A 300 s tolerance window is enforced by default.
Examples & docs
- Live API reference: https://otp.safwatech.com.ly/docs
- Runnable scripts:
sdks/examples/in the source repo (python_example.py,magic_link.py,silent_auth.py,totp_enroll.py,webauthn.py,verify_webhook.py).
Development
pip install -e ".[test]"
pytest
License
MIT. See LICENSE.
Metadata
Release files for safwatech-otp 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 | Provenance | Actions |
|---|---|---|---|---|
| safwatech_otp-0.1.0.tar.gz | 7.4 kB | With provenance | Details for safwatech_otp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safwatech_otp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for safwatech_otp-0.1.0-py3-none-any.whl |
Total release size: 15.9 kB
Release files / safwatech_otp-0.1.0.tar.gz
| Download URL | safwatech_otp-0.1.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd15d0813e9b5a738154dda1876b86f47edf16924005da0878613956761a8fcb
|
|
BLAKE2b-256 checksum How to use checksums |
8c742a33e7fc5b3ecd9c5f5fe04f358d06719b732bb3736aab56b1fcf550ef4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 14, 2026.
Transparency logRelease files / safwatech_otp-0.1.0-py3-none-any.whl
| Download URL | safwatech_otp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7ae0e7f6e9caef9790168ec8c5b622a21e44581fdd240f4554acee9d73ded829
|
|
BLAKE2b-256 checksum How to use checksums |
dc5ddde5bacb96021497400f70adf86f23dec8e66723a3f51c1b9b0d31f0875f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 14, 2026.
Transparency logSecurity for safwatech-otp 0.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for safwatech_otp-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 14, 2026.
Transparency logA 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.