HUB
Sign inSign up

edgaras0x4e/graphviz-render

By edgaras0x4e

•Updated about 15 hours ago

graphviz-render is an HTTP server that makes PNG and SVG images from Graphviz DOT text.

Image
API management
Data science
Web analytics
0

133

edgaras0x4e/graphviz-render repository overview

⁠graphviz-render

graphviz-render is an HTTP server that makes PNG and SVG images from Graphviz DOT text.

⁠Start the server

docker compose up -d --build

⁠Environment variables

Environment variableDefault valueDescription
API_KEYEmptyWhen API_KEY has a value, POST /render accepts only requests that have this value in the header X-API-Key.
REQUEST_LIMIT1048576The maximum length of a request body, in bytes.
TIME_LIMIT10The maximum time to make one image, in seconds.
OUTPUT_LIMIT5242880The maximum length of one image file, in bytes.
MESSAGE_LIMIT10000The maximum length of the Graphviz warnings and error messages in a response, in bytes.
HEADER_LIMIT2048The maximum length of the X-Graphviz-Warnings header, in bytes.
PROCESS_LIMIT4The maximum number of dot processes at the same time. Other requests wait.

⁠API

⁠POST /render

The 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:

FieldTypeNecessaryValues
dotstringYesThe DOT text.
enginestringNodot, circo, fdp, neato, nop, nop1, nop2, osage, patchwork, sfdp, twopi. The default value is dot.
formatstringNopng, svg. The default value is png.
rawbooleanNotrue, false. The default value is false.

When raw is false, the response is a JSON object:

FieldValue
outputThe PNG or SVG file as base64 text.
warningsThe 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:

StatusBodyCause
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.
413The text Content Too LargeThe 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 /health

The response is 200 and {"status":"ok"}.

⁠GET /openapi.json

The response is the OpenAPI description of the API. GET /docs and GET /redoc show this description as web pages.

⁠Examples

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

⁠Recommendations

  • Do not publish the port. Connect the server and the services that send requests to a private Docker network.
  • When external services send requests to the server, set API_KEY.
  • To stop internet access from the container, set internal: true on its Docker network.
  • Set a memory limit and a process limit for the container.

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

⁠Tests

Start the tests with this command:

docker compose run --rm --build graphviz python -m unittest tests

⁠Versions

The Dockerfile⁠ makes Graphviz 16.1.2 from its source release.

⁠License

The license of the code in this repository is the MIT License⁠.

⁠Source code

Edgaras0x4E/graphviz-render⁠

Tag summary
Recent tags
Content type
Image
Digest
sha256:753e4f1c2…
Size
69.3 MB
Last updated
about 15 hours ago
docker pull edgaras0x4e/graphviz-render:latest