pydot-ng: Python interface to Graphviz's Dot (Archived)

2.0.0 · abandoned · verified Wed Apr 15

Pydot-ng is an archived Python interface to Graphviz's Dot language, enabling programmatic creation, manipulation, and rendering of graphs. It was originally created to provide Python 2 and 3 compatibility as a fork of the original pydot. The last stable version is 2.0.0, released in October 2018. This project is no longer actively maintained, and users are strongly advised to use the actively developed `pydot` library instead.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple directed graph with nodes and edges using pydot-ng and save it as a PNG image. It includes important warnings about the project's archived status and the Graphviz system dependency. For new projects, use the 'pydot' library.

import pydot_ng as pydot
import os

# NOTE: pydot-ng is archived. It is highly recommended to use 'pydot' instead.
# For Graphviz to work, ensure it is installed on your system and 'dot' is in your PATH.
# On Linux: sudo apt-get install graphviz
# On macOS: brew install graphviz
# On Windows: Download from graphviz.org and add 'bin' to PATH.

# Create a graph
graph = pydot.Dot('my_graph', graph_type='digraph')

# Add nodes
node_a = pydot.Node('A', style='filled', fillcolor='red')
node_b = pydot.Node('B', style='filled', fillcolor='green')
node_c = pydot.Node('C', style='filled', fillcolor='blue')

graph.add_node(node_a)
graph.add_node(node_b)
graph.add_node(node_c)

# Add edges
graph.add_edge(pydot.Edge(node_a, node_b))
graph.add_edge(pydot.Edge(node_b, node_c, label='Connects'))

# Save the graph to a file
try:
    # Using a temporary file for demonstration
    output_file = 'quickstart_graph.png'
    graph.write_png(output_file)
    print(f"Graph saved to {output_file}")
except Exception as e:
    print(f"Error generating graph: {e}")
    print("Please ensure Graphviz is installed and its 'dot' executable is in your system's PATH.")

# Clean up the generated file for demonstration purposes (optional)
# if os.path.exists(output_file):
#     os.remove(output_file)

view raw JSON →