Skip to content

Python API

This page lists the primary public Python APIs for a WHIP Service. Source under whip-sdk/python/src is authoritative.

PackageAPIDescription
tirtcxauthEd25519TokenIssuerCreate a token issuer
tirtcxauthEd25519TokenVerifierCreate a token verifier
tirtcxauthverify_bearerVerify an HTTP bearer token
tirtcxinit / startInitialize and start TiRTC
tirtcxWhipAcceptorCreate an authentication-independent acceptor
tirtcxWhipAcceptor.whip_acceptAccept an SDP Offer and create a WHIP Session
tirtcxWhipSessionOwn a pending or connected session
tirtcxConnAn established TiRTC connection object. Handles media exchange, commands, and connection events.
whipechoHTTPAdapterCreate an embeddable Echo HTTP adapter
whipechoObserverReceive Echo session, media, failure, and dropped-event notifications

Token APIs

Ed25519TokenIssuer.issue(service, access_key, device_id, raw_query, ttl_seconds) returns a reusable delegation token. The token contains no nonce. The complete query is canonicalized into its scope.

verify_bearer(authorization, service, raw_query, verifier) returns status 200 and claims on success, 401 for a missing token, 403 for an invalid token, or 500 for missing service configuration.

WhipSession

APIDescription
answer_sdpSDP Answer bytes
wait_conn(timeout)Wait for and return the same Conn
close()Idempotently close a pending or connected session

Conn

Events use queue.Queue. A zero buffer disables the queue; enabled queues have a minimum capacity of four. events.audio, events.video, events.message, events.command, events.errors, and events.disconnected carry events. done is a threading.Event, and error contains the terminal error.

Send operations include send_audio, send_video, send_message, send_command, request_key_frame, and audio/video subscription methods.

HTTPAdapter

APIDescription
try_handle_post(raw_query, content_type, body)Handle Echo POST; return None for ordinary requests
serve_delete(session_id)Delete an Echo session
stats()Return a statistics snapshot
shutdown()Reject new sessions and close active sessions

The Stats snapshot contains active sessions, accept and connection failures, media totals, send failures, dropped events, and totals grouped by close reason. Observer callbacks may run on multiple session threads; implementations must return quickly and be thread-safe.

TiRTC WHIP