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

Uploaded Python 3

File details

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

File metadata

  • Download URL: renderdag-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 bc474583ab450c155c788d07bd6e5400c81105a787e13f720d42496b90fe8f5b
MD5 470aa199742325858d5fde4f6cb5fa30
BLAKE2b-256 36806d8316097b96553402943adc0dc2c32f23ed1c2ea435431cafd98de648e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: renderdag-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89f67da5e045e42a08b7e7c4024a4601467ae68b4280d5187bdbc7f04084c95a
MD5 731b3e50fbdb227207c3aa1a52aa6fe3
BLAKE2b-256 64293ac771a191bd0509d988941ac21e77752e27e05309a0927c4e0b5e510dd9

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