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 Github Repo.

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.1.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.1-py3-none-any.whl (39.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: diagramdsl-3.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 5ec4a9f7e7b477f3d58bc9849c76b4dba3f0a3337c3681b1ccf9141718b975f5
MD5 c08d0f7804e88f10419f088e32ba04e8
BLAKE2b-256 53c3e97c47231349ec886b03b3d3a4ee106e3be68018b90f358a54b6edf29833

See more details on using hashes here.

File details

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

File metadata

  • Download URL: diagramdsl-3.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4372f519e0168895c01e42b7c207656ca6ea37f6e9c54d02a8ee74daf56d6937
MD5 248e17ca8b8422be74bf17696f5800d5
BLAKE2b-256 ec19a4fa207204e63d08c9380ba440892e4b1b81acbe6d34d9cb6d4ec1b07c55

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