The Python client isn’t on PyPI yet. Until it is, use the TypeScript client or the HTTP API directly. Once it is,
pip install hotkey-sdk.hotkey.
Hotkey("hk_live_…", base_url=...) takes the key and host instead. base_url is https://console.hotkey.so by default, and HOTKEY_BASE_URL sets it too. with Hotkey() as hotkey: closes its connections at the end.
Objects come back as plain dicts, typed as TypedDicts in hotkey.types (Browser, Ask, Event …), so browser["id"] works and your type checker knows the fields.
One browser per end user
get_or_create makes the browser, or, when one already has that external_id (409 browser_exists), returns that one. The same steps with webhooks are in the package’s examples/per_end_user.py, and on One browser per end user.
Async
AsyncHotkey has the same methods, awaited. A list method returns a pager: await it for one page, or async for over it for every item.
What the client does for you
- Idempotency keys. Every
POSTandPATCHcarries anIdempotency-Key. The client makes one per call and sends the same key with each retry of that call, so a retry never makes a second browser or ask. Passidempotency_key="browser-user_829"to choose it. - Retries. A 429 or 503 (
rate_limited,browsers_busy,server_busy,restarting) means nothing ran: the client waits itsRetry-Afterand sends it again. So does 409idempotency_key_in_use. A lost connection, a timeout, or a 500, 502 or 504 is tried again with backoff only when that is safe: aGET, or a write with its key.max_retriesis 3; aRetry-Afterlonger thanmax_retry_wait(60 s) is raised instead of waited out. The wrong-key lockout (429too_many_attempts) is never retried. - Timeouts. Each try gives up after
timeout, 90 s by default, since a wake may wait 20 s for a place. - Paging. Iterating over a list goes through every page;
.datais the page itself.
on_response is called after every try, retries included, for logs and metrics.
Errors
Every error answer is raised as a subclass ofHotkeyError chosen by status, with the fields of the error body: InvalidRequestError (400, 405), AuthenticationError (401), PlanLimitError (402), PermissionDeniedError (403), NotFoundError (404), ConflictError (409), RateLimitError (429), UpstreamError (502), BusyError (503), InternalServerError (other 5xx), and APIConnectionError when no answer came (code is connection_failed or timeout).
status, type, code, param, request_id, retry_after and body, the whole error object with the fields some codes add (browser on browser_exists, limit on browsers_busy). Branch on code.
Lists
events.follow() reads the log as it grows, from now or after an event id you kept:
Updates
Arguments left atNone are not sent. Inside metadata, None removes that key, as the API’s null does. To clear a field itself, pass CLEAR:
Webhooks
Pass the raw body, before any JSON parsing, theHotkey-Signature header and the endpoint’s secret:
verify_signature answers True or False instead. sign_payload(body, secret) makes a header for your receiver’s own tests. The same functions are on the client as hotkey.webhooks.
Every method
hotkey.request(method, path, query=..., body=...) calls any other route with the same retries and errors.