Skip to main content

Making diagrams easily.

Project description

ba: Making Diagrams Easily

ba is a simple yet powerful library for creating and visualizing directed graphs. It provides a flexible mini-language for defining nodes, edges, and their attributes, making it easy to create complex diagrams with minimal code.

Installation

pip install ba

Additionally, you'll need the GraphViz backend:

  • Mac: brew install graphviz
  • Linux: sudo apt-get install graphviz
  • Windows: Download from the GraphViz website

Quick Start

from ba import dgdisp

# Create a simple workflow diagram
diagram = dgdisp("""
    input -> [process] -> (output)
    [process] -> /log/
""")

# Display the diagram
diagram

Features

  • Simple syntax for defining multiple edges at once
  • Inline node formatting with shape mini-language
  • Bulk specification of node properties
  • Support for different graphviz engines

Mini-language Syntax

Edge Paths

node1 -> node2 -> node3

Many-to-many Connections

node1, node2 -> node3, node4, node5

Inline Node Formatting

[square_node] -> (circular_node) -> /parallelogram/

Common shape markers:

  • [name] - box
  • (name) - circle
  • /name/ - parallelogram
  • <name> - diamond
  • [[name]] - 3D box
  • ((name)) - double circle

Node Attributes

node1, node2: circle
special_node: {"shape": "box", "color": "red", "style": "filled"}

Raw GraphViz Statements

node1 [shape=box style=filled fillcolor=lightblue]

Default Settings

--dflt_node_attr: shape
--fillcolor: lightgrey

Examples

Basic Workflow

dgdisp("""
    key, wf: circle
    chk: doublecircle
    fv: {"shape": "plaintext", "fontcolor": "blue"}
    key -> wf -> [chunker] -> chk -> /featurizer/ -> fv
    fv -> ([model])
""")

Horizontal Layout

from ba import dgdisp

# Use the horizontal layout helper
dgdisp.h("""
    A -> B -> C
    B -> D -> E
""")

Choosing Different Engines

dgdisp("""
    A -> B -> C -> A
    B -> D -> E -> B
""", engine=dgdisp.engines.circo)

API Reference

Main Functions

  • dgdisp(commands, node_shapes=None, attrs_for_node=None, minilang=ModifiedDot, engine=None, **kwargs)
    Create a directed graph visualization using the mini-language.

  • horizontal_dgdisp(*args, **kwargs) or dgdisp.h(*args, **kwargs)
    Create a horizontally oriented directed graph.

Available Engines

  • dot - Hierarchical layout (default)
  • neato - Spring model layout
  • fdp - Force-directed placement
  • sfdp - Scalable force-directed placement
  • twopi - Radial layout
  • circo - Circular layout

Access via dgdisp.engines.dot, dgdisp.engines.neato, etc.

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

ba-0.0.6.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

ba-0.0.6-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file ba-0.0.6.tar.gz.

File metadata

  • Download URL: ba-0.0.6.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for ba-0.0.6.tar.gz
Algorithm Hash digest
SHA256 af0be62eb05624ca0d82805cbb18a77c0726ff76b00374f5a875f4a0adac6ff4
MD5 5793796ca6f120856912ec75a7e4d54b
BLAKE2b-256 56003279a36d09948ed42431e308bf90cfe47e9f3f1a3cff06436daa8d8e9568

See more details on using hashes here.

File details

Details for the file ba-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: ba-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for ba-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 47aa5493f216b95339c0bbe2a34964edbdac0bf4ea79dfb74e8183e5fe50b819
MD5 a8caa67d96af6408f7a476e0ea3b2ab7
BLAKE2b-256 62b494912dcc1735a25101eb54489e378ebb899d1fe253fc2ff310a7a7f0ac08

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