diagrams-so is a typed Python client that covers every /api/v2 operation with one method per
endpoint. It has no hard dependencies (it uses requests if installed, otherwise the standard
library), and includes built-in retries, idempotency keys, streaming, and an async re-layout helper.
Install
Connect
Run this once per machine. You enter your email, we send a one-time code, and a browser opens where
you sign in and enter it; press Approve and the credential is stored for you at
~/.diagrams-so/credentials.json, shared with the MCP server and the TypeScript SDK:
Installing the package also puts a diagrams-so command on your PATH, so you can
connect from a terminal without writing any code and without needing Node:
CI and servers
Where no browser exists, set an environment variable. It always takes priority over a stored login:
Or pass the key explicitly. The order of resolution is an explicit api_key, then
DIAGRAMS_API_KEY, then a stored login. Use diagrams_so.logout() to remove the stored credential.
Quickstart
Load the key from an environment variable or secret manager. Never hard-code it or ship it in client-side code.
Authentication and plans
Pass your key from Settings → API Keys in your account. Every method works on both plans, with no
usage limit beyond the rate limit.
dgz_test_ keys run in test mode, with a lower rate limit. They are not a sandbox: they run real
generations on your account.
Create and change diagrams
Streaming generation
generate_stream yields (event, data) tuples. The diagram arrives only in the terminal complete
event. On Free its xml is None (see the Free plan).
Warnings and score
Async re-layout
relayout_and_wait starts the job and polls it to completion.
Prefer to poll yourself? Use client.relayout(d["id"]) then client.relayout_status(d["id"], job_id).
Read, versions, and export
Import, gallery, and prompts
Usage and account
Errors
Every non-2xx response raises DiagramsAPIError with code, status, and request_id.
Idempotency
Pass idempotency_key on create calls (generate, generate_stream, edit, fix) so a
retry replays the stored result for 24 hours instead of running twice.
list, search_gallery, and versions return {items, next_cursor, has_more}.
Configuration
Full method list
generate, generate_stream, list, get, update, delete, edit, fix, warnings,
relayout, relayout_status, relayout_and_wait, export, versions, get_version, revert,
import_diagram, search_gallery, fork, enhance_prompt, clarify_prompt, usage,
usage_history, me, meta. Each maps one-to-one to an endpoint in the
API reference.
The Free plan
Nothing runs out on either plan. On Free, the API keeps the draw.io XML on the server: diagram
replies have xml set to None, xml_withheld set to True, and an export_url for a watermarked
SVG. Asking for a "drawio" export raises DiagramsAPIError with code UPGRADE_REQUIRED (status
403).
See Plans & pricing.