Skip to main content

Render directed acyclic graphs (DAGs) as text, ported from sapling-renderdag

Project description

renderdag

A Python port of Meta's sapling-renderdag Rust library for rendering directed acyclic graphs (DAGs) as text.

Renderers

ASCII — basic characters, compact:

o    E  merge commit
|\
o |  D
| |
| o  C  branch
|/
o  B
|
o  A

ASCII Large — wider spacing, easier to read:

o     E  merge commit
|\
| \
o  |  D
|  |
|  o  C  branch
| /
|/
o  B
|
o  A

Box Drawing — Unicode line-drawing characters:

o    E  merge commit
├─╮
o │  D
│ │
│ o  C  branch
├─╯
o  B
│
o  A

Install

pip install renderdag
# or
uv add renderdag

Usage

from renderdag import Ancestor, GraphRowRenderer

renderer = GraphRowRenderer().output().build_box_drawing()

# Render rows top-down (most recent commit first)
print(renderer.next_row("C", [Ancestor.parent("B")], "o", "C  latest"))
print(renderer.next_row("B", [Ancestor.parent("A")], "o", "B"))
print(renderer.next_row("A", [], "o", "A  root"))

The API follows a row-at-a-time model: call next_row() for each node in topological order (heads first), passing the node identifier, its parents as Ancestor values, a glyph string, and a message. The renderer tracks column state and returns the formatted string for that row.

Ancestor types

  • Ancestor.parent(node) — direct parent (solid line)
  • Ancestor.ancestor(node) — indirect ancestor (dotted line)
  • Ancestor.anonymous() — unknown/missing parent (terminator ~)

Builder options

# ASCII renderer
renderer = GraphRowRenderer().output().build_ascii()

# ASCII Large with taller rows
renderer = GraphRowRenderer().output().with_min_row_height(3).build_ascii_large()

# Box Drawing with square corners instead of curved
renderer = GraphRowRenderer().output().build_box_drawing().with_square_glyphs()

# Reserve a column for a node before it appears
renderer.reserve("some-node")

Development

Requires uv and just.

just demo          # see example output from all renderers
just test          # run all tests
just test-fast     # skip Rust cross-validation
just test-xval     # run only Rust cross-validation

License

MIT. This is a derivative work of sapling-renderdag by Meta Platforms, Inc. See LICENSE for details.

Note: this library was created using LLMs.

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

renderdag-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

renderdag-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file renderdag-0.1.0.tar.gz.

File metadata

  • Download URL: renderdag-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for renderdag-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4c2dcd072c0174d3f0402c3eeeb13bff25942b71520b47b3157c0f6ceca988a6
MD5 161adfe7a95f36f82dc1e80ab2efe45c
BLAKE2b-256 7e910567d61020b8e035961a190330818f0ff0aebf04f2c58c6846d1f194fe3f

See more details on using hashes here.

File details

Details for the file renderdag-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: renderdag-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for renderdag-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a531e1e18f94466804725ee0b7fa0396bbed322894b9a929b8dcc4c67d30709
MD5 04e7933b84d5596010f746b4951a3314
BLAKE2b-256 59b86d95e304c1debe0d82955a6a19923678862f7796cc3c2ca3f5b0c0df1eb7

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