Installation
Install the SDK from PyPI:Initializing the Client
The merchant client is async and useshttpx.Request for request handling.
Configuration Options
The SDK enforces a singleton pattern per API key. Creating another client with the same key returns the existing instance.
Creating one with a different key raises an error unless you call
SupertabConnect.reset_instance() or pass reset=True.
Common Workflows
Handle a Protected Request
Usehandle_request() when you want the SDK to manage the full lifecycle:
- Extract a token from the
Authorization: License <token>header. - Verify the token against the Supertab JWKS.
- Record a license-usage event, plus an analytics event when
analytics_enabledis set. - If no token is present, run bot detection and apply the enforcement mode.
Framework Integration
Create anhttpx.Request from your framework request object, then translate the HandlerResult back to a framework response.
For example, in FastAPI:
Verify a Token and Record Usage
Useverify_and_record() when you need custom routing or response handling but still want usage and billing events recorded.
Verify Without Recording
Use the staticverify() method when you only need to check token validity and do not want analytics side effects.
Obtaining a License Token
Useobtain_license_token() when you are building a crawler or client that needs to access protected resources.
The SDK fetches the publisher’s license.xml, finds the best matching content rule, exchanges your client credentials
for a token, and caches tokens in memory until shortly before expiry.
usage value and the matching RSL content permits that usage without a token server, the function returns None
because no token is required.
Important Types
EnforcementMode
Enforcement modes determine what happens to a bot request. Non-bot traffic is always allowed.
DISABLED: No verification — every request passes through untouched.OBSERVE(Default): Tokens are verified and outcomes recorded. A bot with no token is allowed through with RSL signaling headers (Link,X-RSL-Status) indicating a license is required; a bot presenting an invalid token is still blocked.ENFORCE: Blocks any bot without a valid token —401 Unauthorized(missing or invalid token) or403 Forbidden(token valid but wrong audience).
DISABLED mode.
HandlerResult
Returned by handle_request():
{ "action": HandlerAction.ALLOW, "headers": ... }: The request should proceed. Apply returned headers if present.{ "action": HandlerAction.BLOCK, "status": ..., "body": ..., "headers": ... }: The request should be rejected with the provided response data.
RSLVerificationResult
Returned by verify() and verify_and_record():
Error Handling
The high-level helpers return framework-friendly result shapes rather than typed invalid-token reason codes:handle_request()returns aHandlerResultwithaction, and when blocked, responsestatus,body, andheaders.verify()andverify_and_record()returnRSLVerificationResult(valid=False, error=...).
error as a message for logs or responses. If your application needs to branch on a machine-readable reason,
call the lower-level verify_license_token() function and inspect InvalidLicenseToken.reason.
Common invalid-token reasons include:
missing_license_token: No license token was provided.invalid_license_header: The JWT header is malformed.invalid_license_algorithm: The token uses an unsupported signing algorithm.invalid_license_payload: The JWT payload is malformed.invalid_license_issuer: The token issuer is not recognized.license_signature_verification_failed: The token signature could not be verified.license_token_expired: The token has expired.invalid_license_audience: The token is valid but does not cover the requested URL.server_error: The SDK could not validate the token because of a platform-side or JWKS fetch error.
Tips and Pitfalls
Pass a bot detector for enforcement. By default,bot_detector is None, so requests without tokens are treated as non-bot traffic.
Use default_bot_detector or provide your own detector if you expect handle_request() to signal or block missing-token bots.
Apply returned headers. In OBSERVE mode, the SDK signals licensing requirements through response headers on allowed requests. If you drop those headers,
crawlers will not receive the correct RSL signal.
Use the async context manager. async with client: closes shared HTTP clients used for event recording and JWKS fetching.
For long-lived web apps, create one client at startup and close it during shutdown.
Cache behavior is in-memory. obtain_license_token() caches license.xml by origin and license tokens by client, token server,
and matched URL pattern. Process restarts clear that cache.