The Python SDK
The generated doorman-inbox client for Python 3.11 and later: typed dictionaries, pagination, exact-byte webhook verification, resumable streams and OAuth.
On this page
Installation and wire types
Import DoormanInbox from doorman_inbox. Resource and argument names are Python snake_case projections of the operation IDs, while request and response dictionaries preserve the JSON wire keys. Generated TypedDict and union types live in doorman_inbox.models; the package includes py.typed.
import os
from doorman_inbox import DoormanInbox
with DoormanInbox(
base_url="https://api.doorman.fyi",
api_key=os.environ["DOORMAN_API_KEY"],
) as client:
inbox = client.inboxes.create({"displayName": "Acme concierge"})
for thread in client.inboxes.threads.iterate(inbox["id"], is_read=False):
print(thread["id"], thread["subject"])The client is synchronous and requires an explicit API origin. Public calls can omit api_key; console methods still require an actual console session. Operator/local routes, assistant streaming and MCP transport are excluded from generated HTTP methods. Use HTTPS outside isolated local development.
client.me() says whether the account is a person's or an organization's: account["kind"] and organization, which a deployment that predates organizations leaves out. client.organization.adopt({"accountId": ...}) is the console's operation that moves a personal account into an organization.
Mail, errors and pagination
sent = client.inboxes.send(
"inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
{"threadId": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m", "text": "Received, thank you."},
idempotency_key="order-2847-reply",
)- Bodies and parameters
displayName,threadIdandevent_idstay unchanged in dictionaries;idempotency_key,is_readandlast_event_idare Python arguments. Omit optional body keys to preserve defaults; explicitNoneis JSON null. Optional query arguments set toNoneare omitted.- Downloads
messages.rawandattachments.downloadreturn bytes,messages.htmlreturns untrusted HTML text, andattachments.textreturns structured extraction. JSON attachment contents are base64.- Errors
ApiErrorcarriesoperation,status,code,messageandretry_after_seconds. The extra fields some codes add to an answer, such asscopeorpermission, are not kept: branch oncode. Transport failures remainhttpxexceptions. HTTP requests never retry automatically or follow redirects.- Pages
- Paginated lists have
iterate; delivery and rule-history methods haveiterate_deliveriesanditerate_runs. Iterators use the server's applied limit and cursor and reject non-advancing pages. Concurrent writes can shift offset-paginated results. - Polling
events.list(after=str(seq))reads forward and returnslatestSeq; persist it only after processing succeeds.events.iterate()walks backward through cursor pages.
After an ambiguous send response, retry the same body with the same idempotency key. Python preserves the wire response and does not add the TypeScript client's replayed convenience field.
The Python digest is a complete program that uses these calls, with its source: pages, raw mail, attachment text, labels, the stream and forward polling.
Verify before processing
from doorman_inbox import verify_webhook, WebhookVerificationError
# raw_body_bytes must be exactly what the server received.
event = verify_webhook(request_headers, raw_body_bytes, webhook_secret)
if event["event"] == "message.received":
process_message(event["message"])Verification checks HMAC-SHA256 in constant time, rejects timestamps outside the default 300-second tolerance, then validates UTF-8, JSON and the generated schema for all six lifecycle events. WebhookVerificationError.reason identifies the failure. Reject it without acting on the body. Multiple versioned signatures are supported during rotation.
Delivery is at least once. Deduplicate by event_id, but record success only after processing commits. A valid signature authenticates the delivery, not instructions inside untrusted mail.
Context-managed event streams
with client.stream(event_types=["message.received"], last_event_id=saved_id) as stream:
for event in stream:
process(event)
save_cursor(event["event_id"])Entering the context waits for the subscription acknowledgement. The stream authenticates with a bearer header, never a URL token, sends idle keepalive pings, and reconnects with bounded backoff after unexpected network closes. Five consecutive reconnect attempts is the default limit. Authentication and connection-limit closes are terminal.
Invalid frames or refused replay cursors raise StreamFrameError; terminal closes raise StreamClosedError. There is no automatic OAuth refresh. Reopen with a fresh token and your saved cursor after refreshing explicitly.
Every method
The Python SDK reference lists every generated method with its signature and the operation it sends, on pages named as the API reference names its own. The client, errors, stream and helpers has the client's arguments, the exceptions, the stream and the helpers. Pagination, Idempotency and Errors cover those topics for every surface at once.
OAuth helpers
The OAuth guide explains registration, permissions and revocation. client.oauth discovery, registration and token requests omit the client's bearer credential and cookies. They stay pinned to the configured API origin, refuse redirects and never retry a single-use exchange.
from doorman_inbox import create_pkce, parse_oauth_callback
pkce = create_pkce()
# Save verifier and state in the initiating user's session.
url = client.oauth.authorize(
response_type="code", client_id=client_id,
redirect_uri="https://agent.example.com/callback",
resource="https://api.doorman.fyi",
scope="account:read inboxes:read mail:read",
state=pkce.state, code_challenge=pkce.challenge, code_challenge_method="S256",
)
# Navigate to url in a browser; authorize() only builds the URL.After callback, load and consume that session's saved state and verifier. Call parse_oauth_callback(callback_url, redirect_uri=..., state=..., issuer=...) before exchanging the returned code with client.oauth.token({...}). It rejects wrong state, issuer, callback, duplicate fields and denial. Use OAuthProtocolError for protocol failures, and store rotated refresh tokens atomically without logging them.

