{"id":16096310,"url":"https://github.com/sio/graphviz-managed","last_synced_at":"2026-01-21T17:34:25.233Z","repository":{"id":57435897,"uuid":"440511531","full_name":"sio/graphviz-managed","owner":"sio","description":"Manipulate Graphviz graphs in Python prior to rendering","archived":false,"fork":false,"pushed_at":"2022-05-13T07:42:47.000Z","size":86,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T16:07:02.753Z","etag":null,"topics":["graphs","graphviz","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/graphviz-managed/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-21T12:36:32.000Z","updated_at":"2023-05-05T09:17:48.000Z","dependencies_parsed_at":"2022-09-01T13:50:33.494Z","dependency_job_id":null,"html_url":"https://github.com/sio/graphviz-managed","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sio%2Fgraphviz-managed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sio%2Fgraphviz-managed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sio%2Fgraphviz-managed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sio%2Fgraphviz-managed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sio","download_url":"https://codeload.github.com/sio/graphviz-managed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694894,"owners_count":20980731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphs","graphviz","python"],"created_at":"2024-10-09T17:13:13.688Z","updated_at":"2026-01-21T17:34:25.204Z","avatar_url":"https://github.com/sio.png","language":"Python","readme":"# Manipulate Graphviz graphs in Python prior to rendering\n\nGraphviz wrapper that allows to manage graph objects in Python prior to\ntranslating them into dot language.\n\n## Rationale\n\nUnfortunately, both [graphviz] and [diagrams] packages do not allow any\noperations on graphs besides adding nodes and edges. If you want to loop\nthrough all graph nodes or edges to calculate some extra attributes - you're\nout of luck.\n\nThis small library builds graphs as Python objects prior to translating them\ninto dot language. That means you can manipulate your graphs programmatically\nin any way you want.\n\n[graphviz]: https://graphviz.readthedocs.io/en/stable/manual.html\n[diagrams]: https://diagrams.mingrammer.com/\n\n\n## Installation\n\ngraphviz-managed is published at [PyPI], you can install it via pip:\n\n```\n$ pip install graphviz-managed\n```\n\n[PyPI]: https://pypi.org/project/graphviz-managed\n\n\n## Usage\n\n### Basic usage\n\nThis is nothing special, [diagrams] offers a lot more possibilities here.\n\n```python\nfrom graphviz_managed import Graph\ngraph = Graph(label='\u003c\u003cb\u003eSample Graph #1\u003c/b\u003e\u003e')\nnode = graph.node\nfoo = node(label='Foo!')\nbar = node(label='BAR', fontcolor='red', penwidth=1.5)\nfoo \u003e\u003e bar \u003e\u003e foo\ngraph.render('basic.svg')\n```\n\n[![sample graph output](samples/basic.svg)](samples/basic.py)\n\n\n### Change node style based on number of incoming/outgoing edges\n\nDynamic graph manipulation is impossible with [graphviz] or [diagrams],\nbut is rather straightforward with this library:\n\n```python\nfrom graphviz_managed import Graph\ngraph = Graph(label='Highlight graph entry points', rankdir='LR')\nnode = graph.node\n\n# Define a larger graph\na = node(label='a')\nb = node(label='b')\nc = node(label='c')\nd = node(label='d')\ne = node(label='e')\nf = node(label='f')\na \u003e\u003e [b, e]\nc \u003e\u003e [b, e]\nd \u003e\u003e a\ne \u003e\u003e f\nf \u003e\u003e [b, a]\n\n# Highlight nodes with no incoming edges\nfrom collections import defaultdict\nincoming_count = defaultdict(int)\nfor edge in graph.edges:\n    incoming_count[edge.end] += 1\nfor node in graph.nodes:\n    if incoming_count[node] == 0:\n        node.attrs.color = 'darkgreen'\n        node.attrs.fontcolor = 'darkgreen'\n        node.attrs.style = 'filled'\n        node.attrs.fillcolor = 'beige'\n\n# Save output\ngraph.render('count.svg')\n```\n\n[![sample graph output](samples/count.svg)](samples/count.py)\n\n### Break long labels into multiple lines\n\nProviding custom factories for nodes and edges allows for some interesting\ncustomizations.\n\n```python\nfrom graphviz_managed import Graph\nfrom graphviz_managed.custom import WrapLongLabelNode\ngraph = Graph(node_cls=WrapLongLabelNode, rankdir='LR', node_attrs=dict(shape='box'))\na = graph.node(label='Short text')\nb = graph.node(label='Long label that will be wrapped into multiple lines')\nc = graph.node(label='CantWrapSpecialCamelCaseWordsWithoutSpaces')\nd = graph.node(label='CantWrapSpecialCamelCaseWordsWithoutSpaces but can wrap elsewhere')\na \u003e\u003e b \u003e\u003e c \u003e\u003e d\ngraph.render('labels.svg')\n```\n\n[![sample graph output](samples/labels.svg)](samples/labels.py)\n\n### Wrapper for [diagrams] package\n\ngraphviz-managed can be extended to support other graph rendering libraries.\n[Here is](src/graphviz_managed/diagrams.py) how it's done for [diagrams].\nResulting objects may be manipulated in the same way, enjoying all pre-rendering\nfreedoms demonstrated above.\n\n```python\nfrom graphviz_managed.diagrams import Diagram\ndiag = Diagram(label='Fancy node templates from https://pypi.org/project/diagrams/', pad=0.1)\nnode = diag.node\nlb = node(kind='aws.network.ELB', label='lb')\nweb = node(kind='aws.compute.EC2', label='web')\ndb = node(kind='aws.database.RDS', label='db')\nstore = node(kind='aws.storage.S3', label='store')\nlb \u003e\u003e web \u003e\u003e db \u003e\u003e store\ndiag.render('diag.png')\n```\n\n[![sample graph output](samples/diag.png)](samples/diag.py)\n\nMore samples can be found in [tests/](tests/) directory.\n\n\n## Support and contributing\n\nIf you need help with using this library or including it into your project,\nplease create **[an issue][issues]**.\nIssues are also the primary venue for reporting bugs and posting feature\nrequests. General discussion related to this project is also acceptable and\nvery welcome!\n\nIn case you wish to contribute code or documentation, feel free to open\n**[a pull request](https://github.com/sio/graphviz-managed/pulls)**. That would\ncertainly make my day!\n\nI'm open to dialog and I promise to behave responsibly and treat all\ncontributors with respect. Please try to do the same, and treat others the way\nyou want to be treated.\n\nIf for some reason you'd rather not use the issue tracker, contacting me via\nemail is OK too. Please use a descriptive subject line to enhance visibility\nof your message. Also please keep in mind that public discussion channels are\npreferable because that way many other people may benefit from reading past\nconversations. My email is visible under the GitHub profile and in the commit\nlog.\n\n[issues]: https://github.com/sio/graphviz-managed/issues\n\n\n## License and copyright\n\nCopyright 2021 Vitaly Potyarkin\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n        http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsio%2Fgraphviz-managed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsio%2Fgraphviz-managed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsio%2Fgraphviz-managed/lists"}