Installation
Install the SDK from PyPI:Initializing the Client
The merchant client is async and useshttpx.Request for request handling.
Configuration Options
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
api_key | str | Yes | — | Your Supertab Merchant API Key |
enforcement | EnforcementMode | No | SOFT | How to handle bots without a valid token |
bot_detector | BotDetector | None | No | None | Function that receives an httpx.Request and returns whether it is a bot |
debug | bool | No | False | Enables verbose SDK logging through Python logging |
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 an analytics event.
- 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 analytics and billing events.
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 when a bot is detected without a valid license token.
STRICT: Blocks the request immediately with a401 Unauthorized(missing or invalid token) or403 Forbidden(token valid but wrong audience).SOFT(Default): Allows the request but attaches RSL headers (Link,X-RSL-Status) to signal that a license is required.DISABLED: No enforcement, signaling, or analytics recording. Requests are allowed without licensing intervention.
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():
| Field | Type | Description |
|---|---|---|
valid | bool | Whether the token is valid for the requested resource |
error | str | None | Error message when invalid |
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 SOFT mode, the SDK signals licensing requirements through response headers. 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.
API Reference
Static and Module Functions
| Method | Description |
|---|---|
SupertabConnect.verify(*, token, resource_url, ...) | Verify a token without analytics recording |
obtain_license_token(*, client_id, client_secret, resource_url, ...) | Acquire a license token as a crawler client |
verify_license_token(token, request_url, supertab_base_url, ...) | Lower-level token verification with typed valid/invalid results |
SupertabConnect.reset_instance() | Clear the singleton, allowing fresh client initialization |
SupertabConnect.set_base_url(url) | Override the default Supertab Connect API base URL |
Instance Methods
| Method | Description |
|---|---|
handle_request(request) | Handle a request end-to-end: token extraction, verification, bot detection, enforcement, and analytics |
verify_and_record(*, token, resource_url, user_agent, ...) | Verify a token and record a usage event |
aclose() | Close SDK-managed async HTTP clients |