Name | pydot JSON |
Version |
3.0.2
JSON |
| download |
home_page | None |
Summary | Python interface to Graphviz's Dot |
upload_time | 2024-09-25 19:20:49 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT |
keywords |
graphviz
dot
graphs
visualization
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
<!--
SPDX-FileCopyrightText: 2024 pydot contributors
SPDX-License-Identifier: MIT
-->
![CI](https://github.com/pydot/pydot/actions/workflows/CI.yml/badge.svg)
[![Coverage](https://raw.githubusercontent.com/pydot/pydot/python-coverage-comment-action-data/badge.svg)](https://htmlpreview.github.io/?https://github.com/pydot/pydot/blob/python-coverage-comment-action-data/htmlcov/index.html)
[![PyPI](https://img.shields.io/pypi/v/pydot.svg)](https://pypi.org/project/pydot/)
[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-purple.svg)](https://github.com/astral-sh/ruff)
# Pydot
`pydot` is a Python interface to Graphviz and its DOT language. You can use `pydot` to create, read, edit, and visualize graphs.
- It's made in pure Python, with only one dependency – pyparsing – other than Graphviz itself.
- It's compatible with `networkx`, which can convert its graphs to `pydot`.
To see what Graphviz is capable of, check the [Graphviz Gallery](https://graphviz.org/gallery/)!
## Dependencies
- [`pyparsing`][pyparsing]: used only for *loading* DOT files, installed automatically during `pydot` installation.
- GraphViz: used to render graphs in a variety of formats, including PNG, SVG, PDF, and more.
Should be installed separately, using your system's [package manager][pkg], something similar (e.g., [MacPorts][mac]), or from [its source][src].
## Installation
- Latest release, from [PyPI][pypi]:
```bash
pip install pydot
```
- Current development code, from this repository:
```bash
pip install git+https://github.com/pydot/pydot.git
```
- Development installation, to modify the code or contribute changes:
```bash
# Clone the repository
git clone https://github.com/pydot/pydot
cd pydot
# (Optional: create a virtual environment)
python3 -m venv _venv
. ./_venv/bin/activate
# Make an editable install of pydot from the source tree
pip install -e .
```
## Quickstart
### 1. Input
No matter what you want to do with `pydot`, you'll need some input to start with. Here are the common ways to get some data to work with.
#### Import a graph from an existing DOT file
Let's say you already have a file `example.dot` (based on an [example from Wikipedia][wiki_example]):
```dot
graph my_graph {
bgcolor="yellow";
a [label="Foo"];
b [shape=circle];
a -- b -- c [color=blue];
}
```
You can read the graph from the file in this way:
```python
import pydot
graphs = pydot.graph_from_dot_file("example.dot")
graph = graphs[0]
```
#### Parse a graph from an existing DOT string
Use this method if you already have a string describing a DOT graph:
```python
import pydot
dot_string = """graph my_graph {
bgcolor="yellow";
a [label="Foo"];
b [shape=circle];
a -- b -- c [color=blue];
}"""
graphs = pydot.graph_from_dot_data(dot_string)
graph = graphs[0]
```
#### Create a graph from scratch using pydot objects
This is where the cool stuff starts. Use this method if you want to build new graphs with Python code.
```python
import pydot
graph = pydot.Dot("my_graph", graph_type="graph", bgcolor="yellow")
# Add nodes
my_node = pydot.Node("a", label="Foo")
graph.add_node(my_node)
# Or, without using an intermediate variable:
graph.add_node(pydot.Node("b", shape="circle"))
# Add edges
my_edge = pydot.Edge("a", "b", color="blue")
graph.add_edge(my_edge)
# Or, without using an intermediate variable:
graph.add_edge(pydot.Edge("b", "c", color="blue"))
```
You can use these basic building blocks in your Python program
to dynamically generate a graph. For example, start with a
basic `pydot.Dot` graph object, then loop through your data
as you add nodes and edges. Use values from your data as labels to
determine shapes, edges and so on. This allows you to easily create
visualizations of thousands of related objects.
#### Convert a NetworkX graph to a pydot graph
NetworkX has conversion methods for pydot graphs:
```python
import networkx
import pydot
# See NetworkX documentation on how to build a NetworkX graph.
graph = networkx.drawing.nx_pydot.to_pydot(my_networkx_graph)
```
### 2. Edit
You can now further manipulate your graph using pydot methods:
Add more nodes and edges:
```python
graph.add_edge(pydot.Edge("b", "d", style="dotted"))
```
Edit attributes of graphs, nodes and edges:
```python
graph.set_bgcolor("lightyellow")
graph.get_node("b")[0].set_shape("box")
```
### 3. Output
Here are three different output options:
#### Generate an image
If you just want to save the image to a file, use one of the `write_*` methods:
```python
graph.write_png("output.png")
```
If you need to further process the image output, the `create_*` methods will get you a Python `bytes` object:
```python
output_graphviz_svg = graph.create_svg()
```
#### Retrieve the DOT string
There are two different DOT strings you can retrieve:
- The "raw" pydot DOT: This is generated the fastest and will
usually still look quite similar to the DOT you put in. It is
generated by pydot itself, without calling Graphviz.
```python
# As a string:
output_raw_dot = graph.to_string()
# Or, save it as a DOT-file:
graph.write_raw("output_raw.dot")
```
- The Graphviz DOT: You can use it to check how Graphviz lays out
the graph before it produces an image. It is generated by
Graphviz.
```python
# As a bytes literal:
output_graphviz_dot = graph.create_dot()
# Or, save it as a DOT-file:
graph.write_dot("output_graphviz.dot")
```
#### Convert to a NetworkX graph
NetworkX has a conversion method for pydot graphs:
```python
my_networkx_graph = networkx.drawing.nx_pydot.from_pydot(graph)
```
### More help
For more help, see the docstrings of the various pydot objects and
methods. For example, `help(pydot)`, `help(pydot.Graph)` and
`help(pydot.Dot.write)`.
More [documentation contributions welcome][contrib].
## Troubleshooting
### Enable logging
`pydot` uses Python's standard `logging` module. To see the logs,
assuming logging has not been configured already:
>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> import pydot
DEBUG:pydot:pydot initializing
DEBUG:pydot:pydot <version>
DEBUG:pydot.core:pydot core module initializing
DEBUG:pydot.dot_parser:pydot dot_parser module initializing
**Warning**: When `DEBUG` level logging is enabled, `pydot` may log the
data that it processes, such as graph contents or DOT strings. This can
cause the log to become very large or contain sensitive information.
### Advanced logging configuration
- Check out the [Python logging documentation][log] and the
[`logging_tree`][log_tree] visualizer.
- `pydot` does not add any handlers to its loggers, nor does it setup
or modify your root logger. The `pydot` loggers are created with the
default level `NOTSET`.
- `pydot` registers the following loggers:
- `pydot`: Parent logger. Emits a few messages during startup.
- `pydot.core`: Messages related to pydot objects, Graphviz execution
and anything else not covered by the other loggers.
- `pydot.dot_parser`: Messages related to the parsing of DOT strings.
## License
Distributed under the [MIT license][MIT].
The module [`pydot._vendor.tempfile`][tempfile]
is based on the Python 3.12 standard library module
[`tempfile.py`][tempfile-src],
Copyright © 2001-2023 Python Software Foundation. All rights reserved.
Licensed under the terms of the [Python-2.0][Python-2.0] license.
## Contacts
Current maintainer(s):
- Łukasz Łapiński <lukaszlapinski7 (at) gmail (dot) com>
Past maintainers:
- Sebastian Kalinowski <sebastian (at) kalinowski (dot) eu> (GitHub: @prmtl)
- Peter Nowee <peter (at) peternowee (dot) com> (GitHub: @peternowee)
Original author: Ero Carrera <ero (dot) carrera (at) gmail (dot) com>
[wiki_dot]: https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29
[networkx]: https://github.com/networkx/networkx
[pydot_gh]: https://github.com/pydot/pydot
[wiki_example]: https://en.wikipedia.org/w/index.php?title=DOT_(graph_description_language)&oldid=1003001464#Attributes
[contrib]: https://github.com/pydot/pydot/issues/130
[pypi]: https://pypi.org/project/pydot/
[pyparsing]: https://github.com/pyparsing/pyparsing
[pkg]: https://en.wikipedia.org/wiki/Package_manager
[mac]: https://www.macports.org
[src]: https://gitlab.com/graphviz/graphviz
[log]: https://docs.python.org/3/library/logging.html
[log_tree]: https://pypi.org/project/logging_tree/
[MIT]: https://github.com/pydot/pydot/blob/main/LICENSES/MIT.txt
[Python-2.0]: https://github.com/pydot/pydot/blob/main/LICENSES/Python-2.0.txt
[tempfile]: https://github.com/pydot/pydot/blob/main/src/pydot/_vendor/tempfile.py
[tempfile-src]: https://github.com/python/cpython/blob/8edfa0b0b4ae4235bb3262d952c23e7581516d4f/Lib/tempfile.py
Raw data
{
"_id": null,
"home_page": null,
"name": "pydot",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Peter Nowee <peter@peternowee.com>, \u0141ukasz <lukaszlapinski7@gmail.com>",
"keywords": "graphviz, dot, graphs, visualization",
"author": null,
"author_email": "Ero Carrera <ero.carrera@gmail.com>, Peter Nowee <peter@peternowee.com>, \u0141ukasz <lukaszlapinski7@gmail.com>, \"FeRD (Frank Dana)\" <ferdnyc@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/85/10/4e4da8c271540dc35914e927546cbb821397f0f9477f4079cd8732946699/pydot-3.0.2.tar.gz",
"platform": null,
"description": "<!--\nSPDX-FileCopyrightText: 2024 pydot contributors\n\nSPDX-License-Identifier: MIT\n-->\n\n![CI](https://github.com/pydot/pydot/actions/workflows/CI.yml/badge.svg)\n[![Coverage](https://raw.githubusercontent.com/pydot/pydot/python-coverage-comment-action-data/badge.svg)](https://htmlpreview.github.io/?https://github.com/pydot/pydot/blob/python-coverage-comment-action-data/htmlcov/index.html)\n[![PyPI](https://img.shields.io/pypi/v/pydot.svg)](https://pypi.org/project/pydot/)\n[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-purple.svg)](https://github.com/astral-sh/ruff)\n\n# Pydot\n\n`pydot` is a Python interface to Graphviz and its DOT language. You can use `pydot` to create, read, edit, and visualize graphs.\n\n- It's made in pure Python, with only one dependency \u2013 pyparsing \u2013 other than Graphviz itself.\n- It's compatible with `networkx`, which can convert its graphs to `pydot`.\n\nTo see what Graphviz is capable of, check the [Graphviz Gallery](https://graphviz.org/gallery/)!\n\n## Dependencies\n\n- [`pyparsing`][pyparsing]: used only for *loading* DOT files, installed automatically during `pydot` installation.\n- GraphViz: used to render graphs in a variety of formats, including PNG, SVG, PDF, and more.\n Should be installed separately, using your system's [package manager][pkg], something similar (e.g., [MacPorts][mac]), or from [its source][src].\n\n## Installation\n\n- Latest release, from [PyPI][pypi]:\n\n ```bash\n pip install pydot\n ```\n\n- Current development code, from this repository:\n\n ```bash\n pip install git+https://github.com/pydot/pydot.git\n ```\n\n- Development installation, to modify the code or contribute changes:\n\n ```bash\n # Clone the repository\n git clone https://github.com/pydot/pydot\n cd pydot\n\n # (Optional: create a virtual environment)\n python3 -m venv _venv\n . ./_venv/bin/activate\n\n # Make an editable install of pydot from the source tree\n pip install -e .\n ```\n\n## Quickstart\n\n### 1. Input\n\nNo matter what you want to do with `pydot`, you'll need some input to start with. Here are the common ways to get some data to work with.\n\n#### Import a graph from an existing DOT file\n\nLet's say you already have a file `example.dot` (based on an [example from Wikipedia][wiki_example]):\n\n```dot\ngraph my_graph {\n bgcolor=\"yellow\";\n a [label=\"Foo\"];\n b [shape=circle];\n a -- b -- c [color=blue];\n}\n```\n\nYou can read the graph from the file in this way:\n\n```python\nimport pydot\n\ngraphs = pydot.graph_from_dot_file(\"example.dot\")\ngraph = graphs[0]\n```\n\n#### Parse a graph from an existing DOT string\n\nUse this method if you already have a string describing a DOT graph:\n\n```python\nimport pydot\n\ndot_string = \"\"\"graph my_graph {\n bgcolor=\"yellow\";\n a [label=\"Foo\"];\n b [shape=circle];\n a -- b -- c [color=blue];\n}\"\"\"\n\ngraphs = pydot.graph_from_dot_data(dot_string)\ngraph = graphs[0]\n```\n\n#### Create a graph from scratch using pydot objects\n\nThis is where the cool stuff starts. Use this method if you want to build new graphs with Python code.\n\n```python\nimport pydot\n\ngraph = pydot.Dot(\"my_graph\", graph_type=\"graph\", bgcolor=\"yellow\")\n\n# Add nodes\nmy_node = pydot.Node(\"a\", label=\"Foo\")\ngraph.add_node(my_node)\n# Or, without using an intermediate variable:\ngraph.add_node(pydot.Node(\"b\", shape=\"circle\"))\n\n# Add edges\nmy_edge = pydot.Edge(\"a\", \"b\", color=\"blue\")\ngraph.add_edge(my_edge)\n# Or, without using an intermediate variable:\ngraph.add_edge(pydot.Edge(\"b\", \"c\", color=\"blue\"))\n```\n\nYou can use these basic building blocks in your Python program\nto dynamically generate a graph. For example, start with a\nbasic `pydot.Dot` graph object, then loop through your data\nas you add nodes and edges. Use values from your data as labels to\ndetermine shapes, edges and so on. This allows you to easily create\nvisualizations of thousands of related objects.\n\n#### Convert a NetworkX graph to a pydot graph\n\nNetworkX has conversion methods for pydot graphs:\n\n```python\nimport networkx\nimport pydot\n\n# See NetworkX documentation on how to build a NetworkX graph.\ngraph = networkx.drawing.nx_pydot.to_pydot(my_networkx_graph)\n```\n\n### 2. Edit\n\nYou can now further manipulate your graph using pydot methods:\n\nAdd more nodes and edges:\n\n```python\ngraph.add_edge(pydot.Edge(\"b\", \"d\", style=\"dotted\"))\n```\n\nEdit attributes of graphs, nodes and edges:\n\n```python\ngraph.set_bgcolor(\"lightyellow\")\ngraph.get_node(\"b\")[0].set_shape(\"box\")\n```\n\n### 3. Output\n\nHere are three different output options:\n\n#### Generate an image\n\nIf you just want to save the image to a file, use one of the `write_*` methods:\n```python\ngraph.write_png(\"output.png\")\n```\n\nIf you need to further process the image output, the `create_*` methods will get you a Python `bytes` object:\n```python\noutput_graphviz_svg = graph.create_svg()\n```\n\n#### Retrieve the DOT string\n\nThere are two different DOT strings you can retrieve:\n\n- The \"raw\" pydot DOT: This is generated the fastest and will\n usually still look quite similar to the DOT you put in. It is\n generated by pydot itself, without calling Graphviz.\n\n ```python\n # As a string:\n output_raw_dot = graph.to_string()\n # Or, save it as a DOT-file:\n graph.write_raw(\"output_raw.dot\")\n ```\n\n- The Graphviz DOT: You can use it to check how Graphviz lays out\n the graph before it produces an image. It is generated by\n Graphviz.\n\n ```python\n # As a bytes literal:\n output_graphviz_dot = graph.create_dot()\n # Or, save it as a DOT-file:\n graph.write_dot(\"output_graphviz.dot\")\n ```\n\n#### Convert to a NetworkX graph\n\nNetworkX has a conversion method for pydot graphs:\n\n```python\nmy_networkx_graph = networkx.drawing.nx_pydot.from_pydot(graph)\n```\n\n### More help\n\nFor more help, see the docstrings of the various pydot objects and\nmethods. For example, `help(pydot)`, `help(pydot.Graph)` and\n`help(pydot.Dot.write)`.\n\nMore [documentation contributions welcome][contrib].\n\n## Troubleshooting\n\n### Enable logging\n\n`pydot` uses Python's standard `logging` module. To see the logs,\nassuming logging has not been configured already:\n\n >>> import logging\n >>> logging.basicConfig(level=logging.DEBUG)\n >>> import pydot\n DEBUG:pydot:pydot initializing\n DEBUG:pydot:pydot <version>\n DEBUG:pydot.core:pydot core module initializing\n DEBUG:pydot.dot_parser:pydot dot_parser module initializing\n\n**Warning**: When `DEBUG` level logging is enabled, `pydot` may log the\ndata that it processes, such as graph contents or DOT strings. This can\ncause the log to become very large or contain sensitive information.\n\n### Advanced logging configuration\n\n- Check out the [Python logging documentation][log] and the\n [`logging_tree`][log_tree] visualizer.\n- `pydot` does not add any handlers to its loggers, nor does it setup\n or modify your root logger. The `pydot` loggers are created with the\n default level `NOTSET`.\n- `pydot` registers the following loggers:\n - `pydot`: Parent logger. Emits a few messages during startup.\n - `pydot.core`: Messages related to pydot objects, Graphviz execution\n and anything else not covered by the other loggers.\n - `pydot.dot_parser`: Messages related to the parsing of DOT strings.\n\n\n## License\n\nDistributed under the [MIT license][MIT].\n\nThe module [`pydot._vendor.tempfile`][tempfile]\nis based on the Python 3.12 standard library module\n[`tempfile.py`][tempfile-src],\nCopyright \u00a9 2001-2023 Python Software Foundation. All rights reserved.\nLicensed under the terms of the [Python-2.0][Python-2.0] license.\n\n\n## Contacts\n\nCurrent maintainer(s): \n- \u0141ukasz \u0141api\u0144ski <lukaszlapinski7 (at) gmail (dot) com>\n\nPast maintainers:\n- Sebastian Kalinowski <sebastian (at) kalinowski (dot) eu> (GitHub: @prmtl)\n- Peter Nowee <peter (at) peternowee (dot) com> (GitHub: @peternowee)\n\nOriginal author: Ero Carrera <ero (dot) carrera (at) gmail (dot) com>\n\n\n[wiki_dot]: https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29\n[networkx]: https://github.com/networkx/networkx\n[pydot_gh]: https://github.com/pydot/pydot\n[wiki_example]: https://en.wikipedia.org/w/index.php?title=DOT_(graph_description_language)&oldid=1003001464#Attributes\n[contrib]: https://github.com/pydot/pydot/issues/130\n[pypi]: https://pypi.org/project/pydot/\n[pyparsing]: https://github.com/pyparsing/pyparsing\n[pkg]: https://en.wikipedia.org/wiki/Package_manager\n[mac]: https://www.macports.org\n[src]: https://gitlab.com/graphviz/graphviz\n[log]: https://docs.python.org/3/library/logging.html\n[log_tree]: https://pypi.org/project/logging_tree/\n[MIT]: https://github.com/pydot/pydot/blob/main/LICENSES/MIT.txt\n[Python-2.0]: https://github.com/pydot/pydot/blob/main/LICENSES/Python-2.0.txt\n[tempfile]: https://github.com/pydot/pydot/blob/main/src/pydot/_vendor/tempfile.py\n[tempfile-src]: https://github.com/python/cpython/blob/8edfa0b0b4ae4235bb3262d952c23e7581516d4f/Lib/tempfile.py\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python interface to Graphviz's Dot",
"version": "3.0.2",
"project_urls": {
"Bug Tracker": "https://github.com/pydot/pydot/issues",
"Changelog": "https://github.com/pydot/pydot/blob/main/ChangeLog",
"Homepage": "https://github.com/pydot/pydot"
},
"split_keywords": [
"graphviz",
" dot",
" graphs",
" visualization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a7e4463fd46922e0b0b369305662f85f1c70dcc1cde1584906cf8defed8308a3",
"md5": "52b8f4a90b5a9d7538fabc2577fc267d",
"sha256": "99cedaa55d04abb0b2bc56d9981a6da781053dd5ac75c428e8dd53db53f90b14"
},
"downloads": -1,
"filename": "pydot-3.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "52b8f4a90b5a9d7538fabc2577fc267d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 35773,
"upload_time": "2024-09-25T19:20:47",
"upload_time_iso_8601": "2024-09-25T19:20:47.656629Z",
"url": "https://files.pythonhosted.org/packages/a7/e4/463fd46922e0b0b369305662f85f1c70dcc1cde1584906cf8defed8308a3/pydot-3.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "85104e4da8c271540dc35914e927546cbb821397f0f9477f4079cd8732946699",
"md5": "0ae2f28420f32164eb37a3cd7d92380d",
"sha256": "9180da540b51b3aa09fbf81140b3edfbe2315d778e8589a7d0a4a69c41332bae"
},
"downloads": -1,
"filename": "pydot-3.0.2.tar.gz",
"has_sig": false,
"md5_digest": "0ae2f28420f32164eb37a3cd7d92380d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 167979,
"upload_time": "2024-09-25T19:20:49",
"upload_time_iso_8601": "2024-09-25T19:20:49.975216Z",
"url": "https://files.pythonhosted.org/packages/85/10/4e4da8c271540dc35914e927546cbb821397f0f9477f4079cd8732946699/pydot-3.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-25 19:20:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pydot",
"github_project": "pydot",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "pydot"
}