pydot


Namepydot JSON
Version 2.0.0 PyPI version JSON
download
home_page
SummaryPython interface to Graphviz's Dot
upload_time2023-12-30 20:00:16
maintainer
docs_urlNone
author
requires_python>=3.7
licenseCopyright (c) 2014 Carlos Jenkins Copyright (c) 2014 Lance Hepler Copyright (c) 2004 Ero Carrera Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords graphviz dot graphs visualization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build Status](https://www.travis-ci.com/pydot/pydot.svg?branch=master)](https://www.travis-ci.com/pydot/pydot)
[![PyPI](https://img.shields.io/pypi/v/pydot.svg)](https://pypi.org/project/pydot/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)


About
=====

`pydot`:

  - is an interface to [Graphviz][1]
  - can parse and dump into the [DOT language][2] used by GraphViz,
  - is written in pure Python,

and [`networkx`][3] can convert its graphs to `pydot`.

Development occurs at [GitHub][11], where you can report issues and
contribute code.


Examples
========

The examples here will show you the most common input, editing and
output methods.

Input
-----

No matter what you want to do with `pydot`, it will need some input to
start with. Here are 3 common options:

1. Import a graph from an existing DOT-file.

    Use this method if you already have a DOT-file describing a graph,
    for example as output of another program. Let's say you already
    have this `example.dot` (based on an [example from Wikipedia][12]):

    ```dot
    graph my_graph {
       bgcolor="yellow";
       a [label="Foo"];
       b [shape=circle];
       a -- b -- c [color=blue];
    }
    ```

    Just read the graph from the DOT-file:

    ```python
    import pydot

    graphs = pydot.graph_from_dot_file("example.dot")
    graph = graphs[0]
    ```

2. or: Parse a graph from an existing DOT-string.

    Use this method if you already have a DOT-string describing a
    graph in a Python variable:

    ```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]
    ```

3. or: Create a graph from scratch using pydot objects.

    Now this is where the cool stuff starts. Use this method if you
    want to build new graphs from Python.

    ```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"))
    ```

    Imagine using these basic building blocks from your Python program
    to dynamically generate a graph. For example, start out with a
    basic `pydot.Dot` graph object, then loop through your data while
    adding nodes and edges. Use values from your data as labels, to
    determine shapes, edges and so forth. This way, you can easily
    build visualizations of thousands of interconnected items.

4. or: 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)
    ```

Edit
----

You can now further manipulate your graph using pydot methods:

- Add further nodes and edges:

  ```python
  graph.add_edge(pydot.Edge("b", "d", style="dotted"))
  ```

- Edit attributes of graph, nodes and edges:

  ```python
  graph.set_bgcolor("lightyellow")
  graph.get_node("b")[0].set_shape("box")
  ```

Output
------

Here are 3 different output options:

1. Generate an image.

    To generate an image of the graph, use one of the `create_*()` or
    `write_*()` methods.

    - If you need to further process the output in Python, the
      `create_*` methods will get you a Python bytes object:

      ```python
      output_graphviz_svg = graph.create_svg()
      ```

    - If instead you just want to save the image to a file, use one of
      the `write_*` methods:

      ```python
      graph.write_png("output.png")
      ```

2. 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")
      ```

3. Convert to a NetworkX graph.

    Here as well, 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][13].


Installation
============

From [PyPI][4] using [`pip`][5]:

`pip install pydot`

From source:

`python setup.py install`


Dependencies
============

- [`pyparsing`][6]: used only for *loading* DOT files,
  installed automatically during `pydot` installation.

- GraphViz: used to render graphs as PDF, PNG, SVG, etc.
  Should be installed separately, using your system's
  [package manager][7], something similar (e.g., [MacPorts][8]),
  or from [its source][9].


License
=======

Distributed under an [MIT license][10].


Contacts
========

Maintainers:
- Sebastian Kalinowski <sebastian@kalinowski.eu> (GitHub: @prmtl)
- Peter Nowee <peter@peternowee.com> (GitHub: @peternowee)

Original author: Ero Carrera <ero.carrera@gmail.com>


[1]: https://www.graphviz.org
[2]: https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29
[3]: https://github.com/networkx/networkx
[4]: https://pypi.python.org/pypi
[5]: https://github.com/pypa/pip
[6]: https://github.com/pyparsing/pyparsing
[7]: https://en.wikipedia.org/wiki/Package_manager
[8]: https://www.macports.org
[9]: https://gitlab.com/graphviz/graphviz
[10]: https://github.com/pydot/pydot/blob/master/LICENSE
[11]: https://github.com/pydot/pydot
[12]: https://en.wikipedia.org/w/index.php?title=DOT_(graph_description_language)&oldid=1003001464#Attributes
[13]: https://github.com/pydot/pydot/issues/130

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pydot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "Peter Nowee <peter@peternowee.com>",
    "keywords": "graphviz,dot,graphs,visualization",
    "author": "",
    "author_email": "Ero Carrera <ero.carrera@gmail.com>, Peter Nowee <peter@peternowee.com>",
    "download_url": "https://files.pythonhosted.org/packages/d7/2f/482fcbc389e180e7f8d7e7cb06bc5a7c37be6c57939dfb950951d97f2722/pydot-2.0.0.tar.gz",
    "platform": null,
    "description": "[![Build Status](https://www.travis-ci.com/pydot/pydot.svg?branch=master)](https://www.travis-ci.com/pydot/pydot)\n[![PyPI](https://img.shields.io/pypi/v/pydot.svg)](https://pypi.org/project/pydot/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n\nAbout\n=====\n\n`pydot`:\n\n  - is an interface to [Graphviz][1]\n  - can parse and dump into the [DOT language][2] used by GraphViz,\n  - is written in pure Python,\n\nand [`networkx`][3] can convert its graphs to `pydot`.\n\nDevelopment occurs at [GitHub][11], where you can report issues and\ncontribute code.\n\n\nExamples\n========\n\nThe examples here will show you the most common input, editing and\noutput methods.\n\nInput\n-----\n\nNo matter what you want to do with `pydot`, it will need some input to\nstart with. Here are 3 common options:\n\n1. Import a graph from an existing DOT-file.\n\n    Use this method if you already have a DOT-file describing a graph,\n    for example as output of another program. Let's say you already\n    have this `example.dot` (based on an [example from Wikipedia][12]):\n\n    ```dot\n    graph my_graph {\n       bgcolor=\"yellow\";\n       a [label=\"Foo\"];\n       b [shape=circle];\n       a -- b -- c [color=blue];\n    }\n    ```\n\n    Just read the graph from the DOT-file:\n\n    ```python\n    import pydot\n\n    graphs = pydot.graph_from_dot_file(\"example.dot\")\n    graph = graphs[0]\n    ```\n\n2. or: Parse a graph from an existing DOT-string.\n\n    Use this method if you already have a DOT-string describing a\n    graph in a Python variable:\n\n    ```python\n    import pydot\n\n    dot_string = \"\"\"graph my_graph {\n        bgcolor=\"yellow\";\n        a [label=\"Foo\"];\n        b [shape=circle];\n        a -- b -- c [color=blue];\n    }\"\"\"\n\n    graphs = pydot.graph_from_dot_data(dot_string)\n    graph = graphs[0]\n    ```\n\n3. or: Create a graph from scratch using pydot objects.\n\n    Now this is where the cool stuff starts. Use this method if you\n    want to build new graphs from Python.\n\n    ```python\n    import pydot\n\n    graph = pydot.Dot(\"my_graph\", graph_type=\"graph\", bgcolor=\"yellow\")\n\n    # Add nodes\n    my_node = pydot.Node(\"a\", label=\"Foo\")\n    graph.add_node(my_node)\n    # Or, without using an intermediate variable:\n    graph.add_node(pydot.Node(\"b\", shape=\"circle\"))\n\n    # Add edges\n    my_edge = pydot.Edge(\"a\", \"b\", color=\"blue\")\n    graph.add_edge(my_edge)\n    # Or, without using an intermediate variable:\n    graph.add_edge(pydot.Edge(\"b\", \"c\", color=\"blue\"))\n    ```\n\n    Imagine using these basic building blocks from your Python program\n    to dynamically generate a graph. For example, start out with a\n    basic `pydot.Dot` graph object, then loop through your data while\n    adding nodes and edges. Use values from your data as labels, to\n    determine shapes, edges and so forth. This way, you can easily\n    build visualizations of thousands of interconnected items.\n\n4. or: Convert a NetworkX graph to a pydot graph.\n\n    NetworkX has conversion methods for pydot graphs:\n\n    ```python\n    import networkx\n    import pydot\n\n    # See NetworkX documentation on how to build a NetworkX graph.\n\n    graph = networkx.drawing.nx_pydot.to_pydot(my_networkx_graph)\n    ```\n\nEdit\n----\n\nYou can now further manipulate your graph using pydot methods:\n\n- Add further nodes and edges:\n\n  ```python\n  graph.add_edge(pydot.Edge(\"b\", \"d\", style=\"dotted\"))\n  ```\n\n- Edit attributes of graph, nodes and edges:\n\n  ```python\n  graph.set_bgcolor(\"lightyellow\")\n  graph.get_node(\"b\")[0].set_shape(\"box\")\n  ```\n\nOutput\n------\n\nHere are 3 different output options:\n\n1. Generate an image.\n\n    To generate an image of the graph, use one of the `create_*()` or\n    `write_*()` methods.\n\n    - If you need to further process the output in Python, the\n      `create_*` methods will get you a Python bytes object:\n\n      ```python\n      output_graphviz_svg = graph.create_svg()\n      ```\n\n    - If instead you just want to save the image to a file, use one of\n      the `write_*` methods:\n\n      ```python\n      graph.write_png(\"output.png\")\n      ```\n\n2. Retrieve the DOT string.\n\n    There 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\n3. Convert to a NetworkX graph.\n\n    Here as well, NetworkX has a conversion method for pydot graphs:\n\n    ```python\n    my_networkx_graph = networkx.drawing.nx_pydot.from_pydot(graph)\n    ```\n\nMore help\n---------\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][13].\n\n\nInstallation\n============\n\nFrom [PyPI][4] using [`pip`][5]:\n\n`pip install pydot`\n\nFrom source:\n\n`python setup.py install`\n\n\nDependencies\n============\n\n- [`pyparsing`][6]: used only for *loading* DOT files,\n  installed automatically during `pydot` installation.\n\n- GraphViz: used to render graphs as PDF, PNG, SVG, etc.\n  Should be installed separately, using your system's\n  [package manager][7], something similar (e.g., [MacPorts][8]),\n  or from [its source][9].\n\n\nLicense\n=======\n\nDistributed under an [MIT license][10].\n\n\nContacts\n========\n\nMaintainers:\n- Sebastian Kalinowski <sebastian@kalinowski.eu> (GitHub: @prmtl)\n- Peter Nowee <peter@peternowee.com> (GitHub: @peternowee)\n\nOriginal author: Ero Carrera <ero.carrera@gmail.com>\n\n\n[1]: https://www.graphviz.org\n[2]: https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29\n[3]: https://github.com/networkx/networkx\n[4]: https://pypi.python.org/pypi\n[5]: https://github.com/pypa/pip\n[6]: https://github.com/pyparsing/pyparsing\n[7]: https://en.wikipedia.org/wiki/Package_manager\n[8]: https://www.macports.org\n[9]: https://gitlab.com/graphviz/graphviz\n[10]: https://github.com/pydot/pydot/blob/master/LICENSE\n[11]: https://github.com/pydot/pydot\n[12]: https://en.wikipedia.org/w/index.php?title=DOT_(graph_description_language)&oldid=1003001464#Attributes\n[13]: https://github.com/pydot/pydot/issues/130\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2014 Carlos Jenkins Copyright (c) 2014 Lance Hepler Copyright (c) 2004 Ero Carrera  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python interface to Graphviz's Dot",
    "version": "2.0.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/pydot/pydot/issues",
        "Changelog": "https://github.com/pydot/pydot/blob/master/ChangeLog",
        "Homepage": "https://github.com/pydot/pydot"
    },
    "split_keywords": [
        "graphviz",
        "dot",
        "graphs",
        "visualization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f90c9b51f3cdff89cd8f93382060330f43d1af098a6624cff439e700791e922",
                "md5": "5d5e5c80a0f534baec76f58ea3fdcac8",
                "sha256": "408a47913ea7bd5d2d34b274144880c1310c4aee901f353cf21fe2e526a4ea28"
            },
            "downloads": -1,
            "filename": "pydot-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5d5e5c80a0f534baec76f58ea3fdcac8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 22675,
            "upload_time": "2023-12-30T20:00:14",
            "upload_time_iso_8601": "2023-12-30T20:00:14.240129Z",
            "url": "https://files.pythonhosted.org/packages/7f/90/c9b51f3cdff89cd8f93382060330f43d1af098a6624cff439e700791e922/pydot-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d72f482fcbc389e180e7f8d7e7cb06bc5a7c37be6c57939dfb950951d97f2722",
                "md5": "21678e0d5a2b863e29c88cf61c59de3d",
                "sha256": "60246af215123fa062f21cd791be67dda23a6f280df09f68919e637a1e4f3235"
            },
            "downloads": -1,
            "filename": "pydot-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "21678e0d5a2b863e29c88cf61c59de3d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 152022,
            "upload_time": "2023-12-30T20:00:16",
            "upload_time_iso_8601": "2023-12-30T20:00:16.583167Z",
            "url": "https://files.pythonhosted.org/packages/d7/2f/482fcbc389e180e7f8d7e7cb06bc5a7c37be6c57939dfb950951d97f2722/pydot-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-30 20:00:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pydot",
    "github_project": "pydot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pydot"
}
        
Elapsed time: 0.17632s