Skip to main content

Official Python SDK for the Safwatech OTP / verification platform (OTP, TOTP, magic links, silent push, WebAuthn).

Project description

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.

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

safwatech_otp-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safwatech_otp-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file safwatech_otp-0.1.0.tar.gz.

File metadata

  • Download URL: safwatech_otp-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for safwatech_otp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd15d0813e9b5a738154dda1876b86f47edf16924005da0878613956761a8fcb
MD5 0d78ee2a40083d4270dda869f4e0990d
BLAKE2b-256 8c742a33e7fc5b3ecd9c5f5fe04f358d06719b732bb3736aab56b1fcf550ef4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for safwatech_otp-0.1.0.tar.gz:

Publisher: publish.yml on safwatech/otp-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file safwatech_otp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: safwatech_otp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for safwatech_otp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ae0e7f6e9caef9790168ec8c5b622a21e44581fdd240f4554acee9d73ded829
MD5 f6e882d64b4c8b10d2d1f913a428dc7a
BLAKE2b-256 dc5ddde5bacb96021497400f70adf86f23dec8e66723a3f51c1b9b0d31f0875f

See more details on using hashes here.

Provenance

The following attestation bundles were made for safwatech_otp-0.1.0-py3-none-any.whl:

Publisher: publish.yml on safwatech/otp-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page