pydot

Python interface to Graphviz's Dot language

https://github.com/pydot/pydot

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 29 committers (6.9%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.5%) to scientific vocabulary

Keywords

dot-language graphviz hacktoberfest python

Keywords from Contributors

distributed graph-generation graph-analysis complex-networks graph-algorithms graph-theory genomics graph-visualization tensor autograd
Last synced: 6 months ago · JSON representation

Repository

Python interface to Graphviz's Dot language

Basic Info
Statistics
  • Stars: 962
  • Watchers: 24
  • Forks: 165
  • Open Issues: 60
  • Releases: 0
Topics
dot-language graphviz hacktoberfest python
Created almost 11 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Codeowners Security

README.md

CI Coverage PyPI Code style: 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!

Dependencies

  • Python: The latest version of pydot supports Python 3.9+. It may work with Python 3.6-3.8, but we can't guarantee full support. If you're using one of these older versions, feel free to experiment, but we won't be able to address issues specific to them. Older versions of pydot are also an option.
  • 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, something similar (e.g., MacPorts), or from its source.

Installation

  • Latest release, from 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):

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.graphfromdot_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

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

graphs = pydot.graphfromdotdata(dotstring) 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("mygraph", graphtype="graph", bgcolor="yellow")

Add nodes

mynode = pydot.Node("a", label="Foo") graph.addnode(my_node)

Or, without using an intermediate variable:

graph.add_node(pydot.Node("b", shape="circle"))

Add edges

myedge = pydot.Edge("a", "b", color="blue") graph.addedge(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.nxpydot.topydot(mynetworkxgraph) ```

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.

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 and the logging_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.

The module pydot._vendor.tempfile is based on the Python 3.12 standard library module tempfile.py, Copyright © 2001-2023 Python Software Foundation. All rights reserved. Licensed under the terms of the Python-2.0 license.

Contacts

Current maintainer(s): - Łukasz Łapiński

Past maintainers: - Sebastian Kalinowski (GitHub: @prmtl) - Peter Nowee (GitHub: @peternowee)

Original author: Ero Carrera

Owner

  • Name: pydot
  • Login: pydot
  • Kind: organization

GitHub Events

Total
  • Issues event: 29
  • Watch event: 43
  • Delete event: 18
  • Issue comment event: 217
  • Push event: 86
  • Pull request review event: 70
  • Pull request review comment event: 58
  • Pull request event: 94
  • Fork event: 10
  • Create event: 27
Last Year
  • Issues event: 29
  • Watch event: 43
  • Delete event: 18
  • Issue comment event: 217
  • Push event: 86
  • Pull request review event: 70
  • Pull request review comment event: 58
  • Pull request event: 94
  • Fork event: 10
  • Create event: 27

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 301
  • Total Committers: 29
  • Avg Commits per committer: 10.379
  • Development Distribution Score (DDS): 0.585
Past Year
  • Commits: 63
  • Committers: 7
  • Avg Commits per committer: 9.0
  • Development Distribution Score (DDS): 0.571
Top Committers
Name Email Commits
Ioannis Filippidis j****s@g****m 125
Peter Nowee p****r@p****m 35
Frank Dana f****c@g****m 27
Sebastian Kalinowski s****n@k****u 23
Łukasz l****7@g****m 21
ero.carrera@gmail.com e****a@g****m@0****7 14
dependabot[bot] 4****] 11
Lance Hepler n****r@g****m 10
Hugo h****k 6
Carlos Miguel Jenkins Perez c****s@h****m 5
ero.carrera e****a@0****7 4
brlam t****4@g****m 2
Julian Jarecki j****i@g****m 2
StepSecurity Bot b****t@s****o 1
Peter Cock p****k@g****m 1
Chris Burr c****r 1
Johan-Martijn ten Hove 4****t 1
kg k****6 1
leycec l****c@g****m 1
Paolo Melchiorre p****o@m****g 1
Nigel Bosch p****b@g****m 1
Nanno Langstraat l****h@g****m 1
Leonard l****d@s****m 1
Hrishikesh Terdalkar h****t@c****n 1
Gustav Larsson g****n@g****m 1
Daniel Chimeno d****o@t****m 1
Clinale 2****4@q****m 1
Ashafix m****s@m****l 1
Alexander Dokuchaev a****v@i****m 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 117
  • Total pull requests: 314
  • Average time to close issues: over 1 year
  • Average time to close pull requests: 2 months
  • Total issue authors: 80
  • Total pull request authors: 26
  • Average comments per issue: 3.48
  • Average comments per pull request: 2.11
  • Merged pull requests: 235
  • Bot issues: 0
  • Bot pull requests: 74
Past Year
  • Issues: 20
  • Pull requests: 110
  • Average time to close issues: 7 days
  • Average time to close pull requests: 6 days
  • Issue authors: 12
  • Pull request authors: 7
  • Average comments per issue: 2.65
  • Average comments per pull request: 2.49
  • Merged pull requests: 69
  • Bot issues: 0
  • Bot pull requests: 35
Top Authors
Issue Authors
  • ferdnyc (14)
  • GoogleCodeExporter (8)
  • peternowee (5)
  • johnyf (4)
  • 2br-2b (4)
  • sandrotosi (3)
  • lkk7 (3)
  • cheikhnadiouf (2)
  • wildoranges (2)
  • StevanWhite (2)
  • Veek (1)
  • goerz (1)
  • thomasvengal (1)
  • iamaziz (1)
  • Lucas-C (1)
Pull Request Authors
  • ferdnyc (147)
  • dependabot[bot] (74)
  • lkk7 (40)
  • peternowee (17)
  • tusharsadhwani (5)
  • juusomer (4)
  • SagaraBattousai (2)
  • step-security-bot (2)
  • henrywu2019 (2)
  • johnyf (2)
  • AlexanderDokuchaev (2)
  • davidweichiang (2)
  • chrizzFTD (2)
  • qinyeli (1)
  • mathstuf (1)
Top Labels
Issue Labels
bug (29) api (16) quoting (14) dot-language (13) discussion (10) question (8) enhancement (8) parser (8) duplicate (6) graphviz (4) details-needed (3) documentation (3) internals (2) output (2) conda (2) dependencies (1) auto-migrated (1) logging (1) performance (1) ci (1)
Pull Request Labels
dependencies (79) github_actions (75) conflicts (14) enhancement (12) api (6) legacy-pr-to-consider (5) bug (5) documentation (5) internals (5) tests (3) graphviz (3) dot-language (2) ci (2) logging (2) packaging (1) output (1) conda (1)

Packages

  • Total packages: 20
  • Total downloads:
    • pypi 13,258,891 last-month
  • Total docker downloads: 169,633,707
  • Total dependent packages: 402
    (may contain duplicates)
  • Total dependent repositories: 11,346
    (may contain duplicates)
  • Total versions: 78
  • Total maintainers: 4
pypi.org: pydot

Python interface to Graphviz's Dot

  • Versions: 29
  • Dependent Packages: 399
  • Dependent Repositories: 11,166
  • Downloads: 13,258,891 Last month
  • Docker Downloads: 169,633,707
Rankings
Dependent packages count: 0.1%
Dependent repos count: 0.1%
Downloads: 0.1%
Docker downloads count: 0.4%
Average: 1.1%
Stargazers count: 2.2%
Forks count: 4.0%
Maintainers (3)
Last synced: 6 months ago
alpine-v3.18: py3-pydot-pyc

Precompiled Python bytecode for py3-pydot

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 4.4%
Forks count: 8.8%
Stargazers count: 9.0%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.18: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 4.4%
Forks count: 8.8%
Stargazers count: 9.0%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.13: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 5.7%
Forks count: 6.3%
Average: 7.9%
Dependent packages count: 19.5%
Maintainers (1)
Last synced: 6 months ago
proxy.golang.org: github.com/pydot/pydot
  • Versions: 19
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 7.0%
Average: 8.2%
Dependent repos count: 9.3%
Last synced: 6 months ago
alpine-v3.14: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 5.9%
Forks count: 6.3%
Average: 8.5%
Dependent packages count: 21.7%
Maintainers (1)
Last synced: 6 months ago
alpine-edge: py3-pydot-pyc

Precompiled Python bytecode for py3-pydot

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 8.6%
Forks count: 10.1%
Stargazers count: 10.8%
Dependent packages count: 13.4%
Maintainers (1)
Last synced: 6 months ago
alpine-edge: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 8.7%
Forks count: 9.8%
Stargazers count: 10.5%
Dependent packages count: 14.6%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.15: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 6.4%
Forks count: 6.5%
Average: 9.6%
Dependent packages count: 25.6%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.16: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Forks count: 6.8%
Stargazers count: 7.0%
Average: 10.3%
Dependent packages count: 27.3%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.17: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Forks count: 8.5%
Stargazers count: 8.6%
Average: 11.1%
Dependent packages count: 27.3%
Maintainers (1)
Last synced: 6 months ago
anaconda.org: pydot

This module provides with a full interface to create handle modify and process graphs in Graphviz’s dot language.

  • Versions: 6
  • Dependent Packages: 3
  • Dependent Repositories: 180
Rankings
Dependent packages count: 9.4%
Dependent repos count: 14.9%
Average: 19.2%
Stargazers count: 25.8%
Forks count: 26.7%
Last synced: 6 months ago
alpine-v3.19: py3-pydot-pyc

Precompiled Python bytecode for py3-pydot

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.22: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.20: py3-pydot-pyc

Precompiled Python bytecode for py3-pydot

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.22: py3-pydot-pyc

Precompiled Python bytecode for py3-pydot

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.21: py3-pydot-pyc

Precompiled Python bytecode for py3-pydot

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.19: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Last synced: 6 months ago
alpine-v3.20: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.21: py3-pydot

Python interface to Graphviz's Dot language

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements-conda.txt pypi
  • chardet *
  • graphviz >=2.38.0
  • pyparsing >=2.0.1
requirements.txt pypi
  • chardet *
setup.py pypi
  • pyparsing >=2.1.4