Skip to main content

Step-based diagram renderer for AI agents — Python server and client.

Project description

diagramdsl

Step-based diagram renderer for AI agents — Python server and client.

DiagramDSL lets AI agents construct diagrams incrementally by emitting structured JSON. The Python package wraps the JavaScript renderer in a Playwright-powered headless server, exposing two HTTP endpoints that any agent or application can call.

Install

pip install diagramdsl
playwright install chromium

Quickstart

1. Generate an auth token

diagramdsl token
# f47ac10b-58cc-4372-a567-0e02b2c3d479

Store it in an environment variable:

export DIAGRAMDSL_AUTH_TOKEN=f47ac10b-58cc-4372-a567-0e02b2c3d479

2. Start the server

import os
from diagramdsl import DiagramDSLServer

server = DiagramDSLServer(
    port=8421,
    host="127.0.0.1",
    auth=os.environ["DIAGRAMDSL_AUTH_TOKEN"],
)
server.start()

Or via CLI:

diagramdsl serve --port 8421

3. Render a diagram

import os
from diagramdsl import DiagramDSL

class FileTool(DiagramDSL):
    def save(self, png_bytes: bytes) -> str:
        path = "/tmp/diagram.png"
        with open(path, "wb") as f:
            f.write(png_bytes)
        return path

tool = FileTool(host="http://localhost:8421", auth=os.environ["DIAGRAMDSL_AUTH_TOKEN"])

path = tool.render({
    "1": { "node": "circle", "label": "Start", "attributes": { "background": "#fff7ed" } },
    "2": { "node": "box",    "label": "Process", "connect": { "from": "1", "direction": "right" } },
    "3": { "node": "circle", "label": "End",   "connect": { "from": "2", "direction": "right" } },
})

print(path)  # /tmp/diagram.png

Endpoints

Method Path Description
GET /info DSL rules and schema — inject into agent system prompts
POST /render Render a steps object → PNG image
GET /docs/{type} Schema for a specific shape, edge, or direction
GET /health Health check (no auth required)

All endpoints except /health require Authorization: Bearer <token>.

Documentation

Full documentation at docs.diagramdsl.dev.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diagramdsl-3.0.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diagramdsl-3.0.0-py3-none-any.whl (39.4 kB view details)

Uploaded Python 3

File details

Details for the file diagramdsl-3.0.0.tar.gz.

File metadata

  • Download URL: diagramdsl-3.0.0.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for diagramdsl-3.0.0.tar.gz
Algorithm Hash digest
SHA256 9ced28a59072e483e8b5505ded126b5057c607ebe0c686626294488adc388589
MD5 4d29bacf1433c6c5fbfe81d69f90c196
BLAKE2b-256 431b560e9d0029b6daf36f5889b73d9ae9bf85fe22adf2008399224503aec4bd

See more details on using hashes here.

File details

Details for the file diagramdsl-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: diagramdsl-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 39.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for diagramdsl-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50589cbca8ada7381b2dc1dc6f84dc1117f2ae4a38ee450b3ddc03d12df96b52
MD5 f20ee615ec6b93be1f7ef6c9e06e68e7
BLAKE2b-256 3e05ada30d3f9a334cfa722faafb431c84a9f673f75ff1fc14196bd55749eca7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page