Skip to main content

Pydot _flow_ makes it a little easier to assemble simple flowing graphs using Pydot.

Project description

Pydot flow

PyPI version Python versions License: MIT

A flowing application programming interface for creating Graphviz visualizations using Pydot.

Introduction

Pydot flow makes it a little easier to assemble simple flowing graphs using Pydot.

You can, for example, use flow to construct a graph programmatically at each step of a data transformation pipeline - visually documenting a data transformation.

Example

In this hypothetical copy-and-paste example a graph is constructed using the flow API.

Implementation

# 0. Import dependencies.
import random
import pydot
from pydot_flow import Chart
from IPython.display import Image


# 1. Define a function for creating a random color code.
def random_color():
    "Generate a random color."
    return "#" + hex(random.randint(0, 0xFFFFFF))[2:].rjust(6, "0")


# 2. Create a Pydot flow Chart.
chart = Chart(
    rankdir="TB",
    splines="true",
    label="Chart",
    labelloc="t",
    fontname="Sans",
    pad=0.2,
    ratio=0.5,
    graph_type="graph",
)

# 3. Set Node defaults.
chart.get_graph().set_node_defaults(style="filled")

# 4. Create the first Node and name it Node 1.
node_1 = chart.create_node(
    src_node_attrs={
        "label": "Node 1",
        "shape": "diamond",
        "color": random_color(),
    }
)

# 5. Flow from Node 1 to Node 2a.
node_2a = node_1.flow(
    src_port="s",
    dst_node_attrs={
        "label": "Node 2a",
        "shape": "oval",
        "color": random_color(),
    },
    edge_attrs={"label": "Edge 1-2a"},
)

# 6. Flow from Node 2a to 3a.
node_3a = node_2a.flow(
    src_port="s",
    dst_node_attrs={
        "label": "Node 3a",
        "shape": "square",
        "color": random_color(),
    },
    edge_attrs={"label": "Edge 2a-3a"},
)

# 7. Return to Node 1 and flow to Node 2b.
node_2b = node_1.flow(
    src_port="s",
    dst_node_attrs={
        "label": "Node 2b",
        "shape": "rectangle",
        "color": random_color(),
    },
    edge_attrs={"label": "Edge 1-2b"},
)

# 8. Flow from Node 2b to Node 2c.
node_2c = node_2b.flow(
    src_port="e",
    dst_node_attrs={
        "label": "Node 2c",
        "shape": "circle",
        "color": random_color(),
    },
    edge_attrs={"label": "Edge 2b-2c"},
    graph=pydot.Subgraph(rank="same"),
)

# 9. Return to Node 2b and flow to Node 3b.
node_3b = node_2b.flow(
    src_port="s",
    dst_node_attrs={
        "label": "Node 3b",
        "shape": "triangle",
        "color": random_color(),
    },
    edge_attrs={"label": "Edge 2b-3b"},
)

# 10. Flow from Node 3b to Node 2c - reference Node 2c by name.
node_3b.flow(
    src_port="n",
    dst_node_attrs={"name": node_2c.get_name()},
    edge_attrs={"label": "Edge 3b-2c"},
)

# 11. Save the graph image to a file.
chart.get_graph().write_png("output.png")

# 12. Output an image in a Jupyter Notebook.
Image(chart.get_graph().create_png(prog="dot"))

Output

Output

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

pydot_flow-0.4.0.tar.gz (122.6 kB view details)

Uploaded Source

Built Distribution

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

pydot_flow-0.4.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pydot_flow-0.4.0.tar.gz.

File metadata

  • Download URL: pydot_flow-0.4.0.tar.gz
  • Upload date:
  • Size: 122.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for pydot_flow-0.4.0.tar.gz
Algorithm Hash digest
SHA256 06c0bddd331f4492f8d6609fece0ab3466ed2d03c48f08c9ce1cbe9e8794b25d
MD5 bd385d8fef11ab82c5b841faeb167fc8
BLAKE2b-256 2918e816d3b90bc52ebba845f8f2178aa3ef4b4959ef44e08aa321460a98d0e0

See more details on using hashes here.

File details

Details for the file pydot_flow-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pydot_flow-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for pydot_flow-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 645079473d3fbef78463a9f336d9705c73a28482afba544ed76da24615ee3c59
MD5 31c4b108e9ce47d6b41f686ef0ede181
BLAKE2b-256 632db28a43716fa8110dbd2f9daa9cc26c2b693a1187e9f84b4f7f212c202d9d

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