{"id":872,"library":"graphviz","title":"Graphviz Python Interface","description":"The `graphviz` library provides a simple pure-Python interface for generating and rendering graph descriptions in the DOT language, which is used by the Graphviz graph-drawing software. It allows users to programmatically create directed and undirected graphs, add nodes and edges, apply attributes for styling, and then render them into various output formats (e.g., PDF, PNG, SVG). The current version is 0.21, and the project maintains an active release cadence with regular updates and Python version support.","status":"active","version":"0.21","language":"python","source_language":"en","source_url":"https://github.com/xflr6/graphviz","tags":["graph","visualization","dot","graphviz","diagram","data science"],"install":[{"cmd":"pip install graphviz","lang":"bash","label":"Install Python package"},{"cmd":"sudo apt install graphviz","lang":"bash","label":"Install Graphviz (Debian/Ubuntu)"},{"cmd":"sudo dnf install graphviz","lang":"bash","label":"Install Graphviz (Fedora/RHEL)"},{"cmd":"brew install graphviz","lang":"bash","label":"Install Graphviz (macOS Homebrew)"},{"cmd":"choco install graphviz","lang":"bash","label":"Install Graphviz (Windows Chocolatey)"}],"dependencies":[{"reason":"Required for rendering graph descriptions into images or other output formats. The Python `graphviz` library generates DOT language files, which are then processed by the native Graphviz executables (e.g., `dot`). Users must ensure `dot` is in their system's PATH.","package":"Graphviz (system-level)"}],"imports":[{"note":"For creating undirected graphs.","symbol":"Graph","correct":"from graphviz import Graph"},{"note":"For creating directed graphs.","symbol":"Digraph","correct":"from graphviz import Digraph"},{"note":"Commonly used for direct access to Graph and Digraph via `graphviz.Graph` or `graphviz.Digraph`.","symbol":"graphviz","correct":"import graphviz"}],"quickstart":{"code":"import graphviz\n\ndot = graphviz.Digraph('MyGraph', comment='A Simple Directed Graph')\n\n# Add nodes\ndot.node('A', 'Node A')\ndot.node('B', 'Node B')\ndot.node('C', 'Node C')\n\n# Add edges\ndot.edge('A', 'B', label='connects')\ndot.edge('B', 'C', label='leads to')\ndot.edge('C', 'A', label='cycles back')\n\n# Render and view the graph\ndot.render('my_simple_graph', view=True, format='png')","lang":"python","description":"This example demonstrates how to create a directed graph, add nodes and edges, and then render it to a PNG file which is automatically opened for viewing. The `Digraph` class is used for directed graphs, and `Graph` for undirected ones. The `render()` method saves the graph to a file and, with `view=True`, opens it using the system's default viewer."},"warnings":[{"fix":"Install the native Graphviz software for your OS (e.g., via `apt`, `dnf`, Homebrew, or official installers) and verify that its `bin` directory is correctly added to your system's PATH. Test by running `dot -V` in your terminal. Restart any IDEs or terminals after updating PATH.","message":"The `graphviz` Python package is a wrapper for the external Graphviz command-line tools. It is crucial to install the Graphviz software separately on your operating system and ensure its executables (e.g., `dot`, `neato`) are accessible in your system's PATH environment variable. Failure to do so will result in `graphviz.exceptions.ExecutableNotFound` errors.","severity":"breaking","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to Python 3.9 or higher if you intend to use `graphviz` version 0.21 or newer. Check the changelog for specific version compatibility if targeting older `graphviz` releases.","message":"Python 3.8 support was dropped in `graphviz` version 0.21. Previous versions (e.g., 0.20.2) dropped Python 3.7 support. Ensure your Python environment meets the minimum version requirement (currently Python 3.9+ for v0.21).","severity":"breaking","affected_versions":"0.21+"},{"fix":"Use raw string literals (e.g., `label=r'hello\\nworld'`) for strings containing backslashes. For literal quotes, simply use `label='\"'` as of version 0.14+, which handles the escaping automatically. Refer to the 'Backslash escapes' section in the official user guide for detailed examples.","message":"Handling backslash escapes and special characters (like quotes) within DOT language strings, especially for `label` attributes, can be tricky. Prior to version 0.14, using `\\\"` for a literal quote could break the internal quoting mechanism. Raw string literals (`r'...'`) are often recommended to simplify backslash handling.","severity":"gotcha","affected_versions":"<0.14 (breaking change), all versions (general complexity)"},{"fix":"Utilize DOT attributes like `overlap`, `nodesep`, `ranksep`, `rankdir`, `splines`, or explicitly set node ranks to fine-tune the layout. For complex layouts, consider creating invisible nodes/edges to guide the layout engine or using subgraphs.","message":"Default graph layouts can sometimes result in overlapping nodes or edges, or an undesirable ordering. This is often due to the graph layout algorithms trying to optimize for compactness or other factors without specific user guidance.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T20:36:50.186Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Install the `graphviz` Python package using pip: `pip install graphviz`.","cause":"The Python `graphviz` package is not installed in the active Python environment or the environment in which you are running your code.","error":"ModuleNotFoundError: No module named 'graphviz'"},{"fix":"1. Install the Graphviz system software from the official Graphviz website (graphviz.org/download/).\n2. Add the `bin` directory of your Graphviz installation to your system's PATH environment variable. For example, on Windows, this might be `C:\\Program Files\\Graphviz\\bin` or `C:\\Program Files (x86)\\Graphviz\\bin`. On Linux/macOS, ensure it's in a standard PATH location like `/usr/local/bin` or ensure it's installed via a package manager (`sudo apt-get install graphviz` for Debian-based systems, `brew install graphviz` for macOS).\n3. Restart your terminal or IDE to ensure the updated PATH is recognized. Alternatively, you can set the `GRAPHVIZ_DOT` environment variable in your script to the exact path of the `dot` executable.","cause":"The Python `graphviz` library is a wrapper around the Graphviz system software, and this error occurs when the underlying Graphviz executable (like `dot`) is not installed on your system or its location is not added to your system's PATH environment variable.","error":"graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH"},{"fix":"1. Review your DOT graph source code for any syntax errors or inconsistencies. Print `dot.source` to inspect the generated DOT code. \n2. Try rendering to a different output format (e.g., SVG, PDF) to see if the issue is specific to PNG or the viewer for that format. For example: `dot.format = 'svg'`.\n3. Ensure your Graphviz system installation is complete and healthy by running `dot -V` in your terminal and checking for any warnings or errors. For complex diagrams, ensure all necessary Graphviz tools/layout engines are installed (e.g., `graphviz-dev` on Linux).","cause":"This error indicates that the `dot` executable was found and executed, but it failed to process the graph description or generate the output, often due to invalid DOT language syntax in your graph definition, or issues with the Graphviz installation itself, such as missing dependencies for a specific output format.","error":"graphviz.backend.CalledProcessError: Command '['dot', '-Tpng']' returned non-zero exit status 1"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.21","cli_name":"","cli_version":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","installed_version":"0.21","pypi_latest":"0.21","is_stale":false,"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.09,"mem_mb":3.2,"disk_size":"18.2M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":3.2,"disk_size":"18.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.06,"mem_mb":3.2,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":3.2,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.14,"mem_mb":3.7,"disk_size":"20.1M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":3.7,"disk_size":"20.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.13,"mem_mb":3.7,"disk_size":"21M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":3.7,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.12,"mem_mb":3.6,"disk_size":"11.9M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":3.6,"disk_size":"11.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0.12,"mem_mb":3.6,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":3.6,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.11,"mem_mb":3.8,"disk_size":"11.7M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.11,"mem_mb":3.8,"disk_size":"11.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.13,"mem_mb":3.8,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.11,"mem_mb":3.8,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.07,"mem_mb":3.1,"disk_size":"17.7M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":3.1,"disk_size":"17.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.07,"mem_mb":3.1,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"graphviz","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":3.1,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}