graphviz-render is an HTTP server that makes PNG and SVG images from Graphviz DOT text.
133
graphviz-render is an HTTP server that makes PNG and SVG images from Graphviz DOT text.
docker compose up -d --build
| Environment variable | Default value | Description |
|---|---|---|
API_KEY | Empty | When API_KEY has a value, POST /render accepts only requests that have this value in the header X-API-Key. |
REQUEST_LIMIT | 1048576 | The maximum length of a request body, in bytes. |
TIME_LIMIT | 10 | The maximum time to make one image, in seconds. |
OUTPUT_LIMIT | 5242880 | The maximum length of one image file, in bytes. |
MESSAGE_LIMIT | 10000 | The maximum length of the Graphviz warnings and error messages in a response, in bytes. |
HEADER_LIMIT | 2048 | The maximum length of the X-Graphviz-Warnings header, in bytes. |
PROCESS_LIMIT | 4 | The maximum number of dot processes at the same time. Other requests wait. |
POST /renderThe request must have the header Content-Type: application/json.
When API_KEY has a value, the request must also have the header X-API-Key.
The request body is a JSON object with these fields:
| Field | Type | Necessary | Values |
|---|---|---|---|
dot | string | Yes | The DOT text. |
engine | string | No | dot, circo, fdp, neato, nop, nop1, nop2, osage, patchwork, sfdp, twopi. The default value is dot. |
format | string | No | png, svg. The default value is png. |
raw | boolean | No | true, false. The default value is false. |
When raw is false, the response is a JSON object:
| Field | Value |
|---|---|
output | The PNG or SVG file as base64 text. |
warnings | The Graphviz warnings. When there are no warnings, the value is an empty string. |
When raw is true, the response is the PNG or SVG file.
The Graphviz warnings are in the X-Graphviz-Warnings header.
The text of this header uses percent-encoding.
Error responses:
| Status | Body | Cause |
|---|---|---|
| 400 | {"error":"request","message":""} | The body is not a JSON object with correct fields, or the Content-Type header is not application/json. |
| 401 | {"error":"unauthorized"} | API_KEY has a value, and the X-API-Key header is missing or incorrect. |
| 413 | The text Content Too Large | The body is larger than REQUEST_LIMIT. |
| 422 | {"error":"graphviz","message":"<text>"} | Graphviz stops with an error, for example a syntax error. The message field contains the Graphviz error messages. |
| 422 | {"error":"time","message":""} | The time to make the image is more than TIME_LIMIT. The server stops the dot process. |
| 422 | {"error":"size","message":""} | The image is larger than OUTPUT_LIMIT. The server stops the dot process. |
| 422 | {"error":"memory","message":""} | A different process stops the dot process with the signal SIGKILL. In the container, the Linux kernel sends this signal at the memory limit. |
GET /healthThe response is 200 and {"status":"ok"}.
GET /openapi.jsonThe response is the OpenAPI description of the API.
GET /docs and GET /redoc show this description as web pages.
Get a PNG file as base64 text in JSON:
$ curl -s http://localhost:8000/render -H 'Content-Type: application/json' -d '{"dot": "digraph { a [shape=nosuchshape] }"}'
{"output":"iVBORw0KGgoAAAANSUhEUgAAAFMAAAA7CAYAAAAH...","warnings":"Warning: using box for unknown shape nosuchshape"}
The example shows only the start of the output value.
Write a PNG file to graph.png:
$ curl -s http://localhost:8000/render -H 'Content-Type: application/json' -d '{"dot": "digraph { a -> b }", "raw": true}' > graph.png
$ file graph.png
graph.png: PNG image data, 83 x 155, 8-bit/color RGBA, non-interlaced
Show the headers of an SVG response with two warnings:
$ curl -s -D - -o /dev/null http://localhost:8000/render -H 'Content-Type: application/json' -d '{"dot": "digraph { a [color=notacolor]; b [shape=nosuchshape] }", "format": "svg", "raw": true}'
HTTP/1.1 200 OK
date: Fri, 04 Dec 2026 10:26:32 GMT
server: uvicorn
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
x-content-type-options: nosniff
x-graphviz-warnings: Warning: using box for unknown shape nosuchshape%0AWarning: notacolor is not a known color.
content-length: 1065
content-type: image/svg+xml
Send DOT text with a syntax error:
$ curl -s -w '\n%{http_code}\n' http://localhost:8000/render -H 'Content-Type: application/json' -d '{"dot": "digraph { a -- b }"}'
{"error":"graphviz","message":"Error: <stdin>: syntax error in line 1 near '--'"}
422
With API_KEY: example-key in compose.yaml, send a request without the API key, and then a request with the API key:
$ curl -s -w '\n%{http_code}\n' http://localhost:8000/render -H 'Content-Type: application/json' -d '{"dot": "digraph { a -> b }"}'
{"error":"unauthorized"}
401
$ curl -s http://localhost:8000/render -H 'Content-Type: application/json' -H 'X-API-Key: example-key' -d '{"dot": "digraph { a -> b }", "raw": true}' > graph.png
$ file graph.png
graph.png: PNG image data, 83 x 155, 8-bit/color RGBA, non-interlaced
API_KEY.internal: true on its Docker network.Example:
services:
app:
image: example/app
networks:
- default
- graphviz
graphviz:
image: edgaras0x4e/graphviz-render:v0.1.0
environment:
API_KEY: example-key
mem_limit: 512m
memswap_limit: 512m
pids_limit: 64
networks:
- graphviz
networks:
graphviz:
internal: true
Start the tests with this command:
docker compose run --rm --build graphviz python -m unittest tests
The Dockerfile makes Graphviz 16.1.2 from its source release.
The license of the code in this repository is the MIT License.
docker pull edgaras0x4e/graphviz-render:latest