{"id":26355718,"url":"https://github.com/merrimanind/drawpyo","last_synced_at":"2025-04-06T16:10:22.234Z","repository":{"id":186880692,"uuid":"675107754","full_name":"MerrimanInd/drawpyo","owner":"MerrimanInd","description":"A Python library for programmatically generating Draw.io charts.","archived":false,"fork":false,"pushed_at":"2024-09-25T03:02:58.000Z","size":4474,"stargazers_count":241,"open_issues_count":13,"forks_count":15,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-16T09:11:28.952Z","etag":null,"topics":["diagrams","diagramsnet","drawio","drawio-tools","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/drawpyo/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MerrimanInd.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-05T19:59:45.000Z","updated_at":"2024-11-29T11:25:12.000Z","dependencies_parsed_at":"2023-11-21T02:26:30.854Z","dependency_job_id":"c0b55c12-2f7b-483a-a7b8-69ab5c94152d","html_url":"https://github.com/MerrimanInd/drawpyo","commit_stats":null,"previous_names":["merrimanind/drawpyo"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MerrimanInd%2Fdrawpyo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MerrimanInd%2Fdrawpyo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MerrimanInd%2Fdrawpyo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MerrimanInd%2Fdrawpyo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MerrimanInd","download_url":"https://codeload.github.com/MerrimanInd/drawpyo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509221,"owners_count":20950232,"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":["diagrams","diagramsnet","drawio","drawio-tools","python"],"created_at":"2025-03-16T13:17:30.907Z","updated_at":"2025-04-06T16:10:22.175Z","avatar_url":"https://github.com/MerrimanInd.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# drawpyo\n\nDrawpyo is a Python library for programmatically generating Diagrams.net/Draw.io charts. It enables creating a diagram object, placing and styling objects, then writing the object to a file.\n\n# History/Justification\n\nI love Draw.io! Compared to expensive and heavy commercial options like Visio and Miro, Draw.io's free and lightweight app allows wider and more universal distribution of diagrams. Because the files are stored in plaintext they can be versioned alongside code in a repository as documentation. The XML-based file format makes these diagrams semi-portable, and could easily be ported to other applications if Draw.io ever failed you. For these reason, I think it's one of the best options for documentation diagrams.\n\nWhen I had a need to generate heirarchical tree diagrams of requirement structures I was surprised to find there wasn't even a single existing Python library for working with these files. I took the project home and spent a weekend building the initial functionality. I've been adding functionality, robustness, and documentation intermittently since.\n\n# Full Documentation\n\nAvailable here!\n\nhttps://merrimanind.github.io/drawpyo/\n\n# Basic Usage\n\nThe basic mode of interacting with drawpyo is to manually create, style, and place objects just like you would using the Draw.io UI. There are a number of ways to style objects and you can write your own functionality for automatically handling style or placement.\n\n## Make a new file\n\n```python\nimport drawpyo\nfile = drawpyo.File()\nfile.file_path = r\"C:\\drawpyo\"\nfile.file_name = \"Test Generated Edges.drawio\"\n# Add a page\npage = drawpyo.Page(file=file)\n```\n\n## Add an object\n\n```python\nitem = drawpyo.diagram.Object(page=page, value=\"new object\")\nitem.position = (0, 0)\n```\n\n## Create an object from the base style libraries available in the Draw.io UI\n\n```python\nitem_from_lib = drawpyo.diagram.object_from_library(\n    page=page,\n    library=\"general\",\n    obj_name=\"process\",\n    value=\"New Process\",\n    )\n```\n\n## Style an object from a string\n\n```python\nitem_from_stylestr = drawpyo.diagram.Object(page=page)\nitem_from_stylestr.apply_style_string(\"rounded=1;whiteSpace=wrap;html=1;fillColor=#6a00ff;fontColor=#ffffff;strokeColor=#000000;gradientColor=#FF33FF;strokeWidth=4;\")\n```\n\n## Write the file\n\n```python\nfile.write()\n```\n\n# Usage with a diagram type\n\nThere is also functionality available in drawpyo that extends what can be done in Draw.io's app! These diagram types allow for easy and automatic creation of specific diagrams.\n\nThe only diagram type that's released is the tree diagram. Varying level of conceptual work has been started for:\n\n- Automatic class/object/inheritance diagrams of a python module\n\n- Flowcharts\n\n- Process diagrams\n\n## Working with TreeDiagrams\n\nCreate a new tree diagram:\n\n```python\nfrom drawpyo.diagram_types import TreeDiagram, NodeObject\n\ntree = TreeDiagram(\n    file_path = path.join(path.expanduser('~'), \"Test Drawpyo Charts\"),\n    file_name = \"Coffee Grinders.drawio\",\n    direction = \"down\",\n    link_style = \"orthogonal\",\n    )\n```\n\nThe direction property sets which way the leaf nodes grow from the root: up, down, left, or right. The link_style can be orthogonal, straight, or curved.\n\nCreate some NodeObjects:\n\n```python\n# Top object\ngrinders = NodeObject(tree=tree, value=\"Appliances for Grinding Coffee\", base_style=\"rounded rectangle\")\n\n# Main categories\nblade_grinders = NodeObject(tree=tree, value=\"Blade Grinders\", tree_parent=grinders)\nburr_grinders = NodeObject(tree=tree, value=\"Burr Grinders\", tree_parent=grinders)\nblunt_objects = NodeObject(tree=tree, value=\"Blunt Objects\", tree_parent=grinders)\n```\n\nNote that the base_style was manually declared for the first object. But NodeObjects will default to \"rounded rectangle\" so it's not necessary for every one. Any NodeObject can be a parent, so you can keep adding objects down the tree:\n\n```python\n# Other\nelec_blade = NodeObject(tree=tree, value=\"Electric Blade Grinder\", tree_parent=blade_grinders)\nmnp = NodeObject(tree=tree, value=\"Mortar and Pestle\", tree_parent=blunt_objects)\n\n# Conical Burrs\nconical = NodeObject(tree=tree, value=\"Conical Burrs\", tree_parent=burr_grinders)\nelec_conical = NodeObject(tree=tree, value=\"Electric\", tree_parent=conical)\nmanual_conical = NodeObject(tree=tree, value=\"Manual\", tree_parent=conical)\n```\n\n\u003e **Important Note:** TreeDiagrams do not currently support NodeObjects with multiple parents! It may not ever as this seriously complicates the auto layout process. However, you can add links between any two objects in the tree and render them in the diagram. They just may look ugly until you manually rearrange the diagram.\n\nFinally, before writing the diagram you'll want to run the magic penultimate step: auto layout.\n\n```python\ntree.auto_layout()\ntree.write()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmerrimanind%2Fdrawpyo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmerrimanind%2Fdrawpyo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmerrimanind%2Fdrawpyo/lists"}