pydot-ng: Python interface to Graphviz's Dot (Archived)
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
- breaking The pydot-ng project is archived and read-only. It is no longer maintained. Users should migrate to the actively developed `pydot` library (PyPI: `pydot`, GitHub: `pydot/pydot`).
- gotcha Graphviz (the underlying graph visualization software) must be installed separately on your system, and its executable files (e.g., `dot`, `neato`) must be accessible via your system's PATH environment variable. Pydot-ng (and pydot) will not work without a correctly configured Graphviz installation.
- deprecated pydot-ng was a fork of pydot to support both Python 2 and 3. The original `pydot` project has since been updated to support Python 3+ and the `pydot-ng` repository explicitly directs users to `pydot`. Continued use of `pydot-ng` may lead to compatibility issues with newer Python versions or lack of bug fixes.
- gotcha Older versions of pydot-ng might have issues locating Graphviz executables, particularly on Windows, sometimes looking for `.bat` files instead of `.exe`.
Install
-
pip install pydot-ng
Imports
- pydot_ng
import pydot
import pydot_ng
- Graph
from pydot_ng import Graph
- Node
from pydot_ng import Node
- Edge
from pydot_ng import Edge
Quickstart
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)