Skip to main content

LessOTP Inbound Phone Authentication client SDK for Python. WhatsApp and Telegram channels.

Project description

LessOTP Python SDK

Client for the LessOTP Inbound Phone Authentication API (Python 3.8+).

Supported channels:

  • WhatsApp — inbound /START {code} phone verification.
  • Telegram — bot /start {code} plus the official Share phone number button.

Install

pip install lessotp-sdk

Usage

import os
from lessotp_sdk import LessOTPClient, parse_verified_webhook

# production (default)
client = LessOTPClient(api_key=os.environ["LESSOTP_API_KEY"])

# staging
staging = LessOTPClient(
    api_key=os.environ["LESSOTP_STAGING_API_KEY"],
    environment="staging",
)

# WhatsApp strict (legacy-compatible)
whatsapp_strict = client.auth_request("6281234567890")
print(whatsapp_strict.channel, whatsapp_strict.wa_link)

# WhatsApp frictionless (legacy-compatible)
whatsapp_frictionless = client.auth_request()

# Telegram strict
telegram_strict = client.request_telegram_auth("6281234567890")
print(telegram_strict.telegram_link, telegram_strict.telegram_text)

# Telegram frictionless: user shares phone via Telegram contact button
telegram_frictionless = client.request_auth(channel="telegram")

# per-call override
one_off = client.request_telegram_auth("6281234567890", environment="staging")

# webhook verification
event = parse_verified_webhook(
    request.get_data(as_text=True),
    request.headers.get("X-Signature"),
    os.environ["LESSOTP_WEBHOOK_SECRET"],
)
if event is None:
    return "bad signature", 403
print(event.channel, event.request_id, event.phone_number)
if event.channel == "telegram":
    print(event.telegram_user_id, event.telegram_username)

API

LessOTPClient(api_key, environment='production', base_url='https://api.lessotp.com', timeout_seconds=10)

Parameters follow the same order as the Go SDK: api_key → environment → base_url → timeout.

Option Default Description
api_key required App API key.
environment "production" "production" or "staging".
base_url https://api.lessotp.com API host.
timeout_seconds 10 HTTP timeout.

client.auth_request(phone_number=None, environment=None) -> AuthRequestResult

WhatsApp convenience method (legacy-compatible).

client.request_telegram_auth(phone_number=None, environment=None) -> AuthRequestResult

Telegram short-hand. Strict when phone_number is supplied; frictionless when omitted.

client.request_auth(channel='whatsapp', phone_number=None, environment=None) -> AuthRequestResult

Multi-channel call. channel must be 'whatsapp' or 'telegram'.

Telegram note: LessOTP only accepts phone numbers shared through Telegram's official contact-sharing button. The platform verifies the shared contact belongs to the Telegram sender.

verify_webhook_signature(raw_body, signature_header, secret) -> bool

Constant-time HMAC-SHA256 verification. Accepts raw hex and sha256= prefixed values.

parse_verified_webhook(raw_body, signature_header, secret) -> VerificationSuccess | None

Returns the parsed payload if the signature is valid; None otherwise.

VerificationSuccess includes a channel field ('whatsapp' or 'telegram'). Telegram payloads also include telegram_user_id and telegram_username.

Errors

Raises LessOTPError on transport, auth, or payload problems.

Tests

python -m pip install -e ".[test]"
python -m pytest

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

lessotp_sdk-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

lessotp_sdk-0.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file lessotp_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: lessotp_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for lessotp_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e0b7ded810cb55f081a89ac4c115c502191996ae206b8eb5059a4e2ff0ba5dc0
MD5 bfca63b035a8d0a072fd240186bb91ed
BLAKE2b-256 dbe4b4e0bd1d7fade4a55188366d1bcfb2d589019c6c7879df25c99de488f664

See more details on using hashes here.

File details

Details for the file lessotp_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: lessotp_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for lessotp_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a114616f0cedaefe1db17c6ed004fdc9b2d782319caca87fbc2b80dc24c8094
MD5 3cedcd5a29f0e581d7c695bfbe32c6fd
BLAKE2b-256 5b2bba8b7eb25aed440a66873122ddea416e89bb1db401fc97b949d50e30596a

See more details on using hashes here.

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