drawpyo


Namedrawpyo JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryA Python library for programmatically generating Draw.io charts.
upload_time2024-04-25 15:20:19
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords draw.io diagrams.net diagrams
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # drawpyo

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

# History/Justification

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

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

# Full Documentation

Available here!

https://merrimanind.github.io/drawpyo/

# Basic Usage

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

## Make a new file

```python
import drawpyo
file = drawpyo.File()
file.file_path = r"C:\drawpyo"
file.file_name = "Test Generated Edges.drawio"
# Add a page
page = drawpyo.Page(file=file)
```

## Add an object

```python
item = drawpyo.diagram.Object(page=page, value="new object")
item.position = (0, 0)
```

## Create an object from the base style libraries available in the Draw.io UI

```python
item_from_lib = drawpyo.diagram.object_from_library(
    page=page,
    library="general",
    obj_name="process",
    value="New Process",
    )
```

## Style an object from a string

```python
item_from_stylestr = drawpyo.diagram.Object(page=page)
item_from_stylestr.apply_style_string("rounded=1;whiteSpace=wrap;html=1;fillColor=#6a00ff;fontColor=#ffffff;strokeColor=#000000;gradientColor=#FF33FF;strokeWidth=4;")
```

## Write the file

```python
file.write()
```

# Usage with a diagram type

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

The only diagram type that's released is the tree diagram. Varying level of conceptual work has been started for:

- Automatic class/object/inheritance diagrams of a python module

- Flowcharts

- Process diagrams

## Working with TreeDiagrams

Create a new tree diagram:

```python
from drawpyo.diagram_types import TreeDiagram, NodeObject

tree = TreeDiagram(
    file_path = path.join(path.expanduser('~'), "Test Drawpyo Charts"),
    file_name = "Coffee Grinders.drawio",
    direction = "down",
    link_style = "orthogonal",
    )
```

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

Create some NodeObjects:

```python
# Top object
grinders = NodeObject(tree=tree, value="Appliances for Grinding Coffee", base_style="rounded rectangle")

# Main categories
blade_grinders = NodeObject(tree=tree, value="Blade Grinders", parent=grinders)
burr_grinders = NodeObject(tree=tree, value="Burr Grinders", parent=grinders)
blunt_objects = NodeObject(tree=tree, value="Blunt Objects", parent=grinders)
```

Note 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:

```python
# Other
elec_blade = NodeObject(tree=tree, value="Electric Blade Grinder", parent=blade_grinders)
mnp = NodeObject(tree=tree, value="Mortar and Pestle", parent=blunt_objects)

# Conical Burrs
conical = NodeObject(tree=tree, value="Conical Burrs", parent=burr_grinders)
elec_conical = NodeObject(tree=tree, value="Electric", parent=conical)
manual_conical = NodeObject(tree=tree, value="Manual", parent=conical)
```

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

Finally, before writing the diagram you'll want to run the magic penultimate step: auto layout.

```python
tree.auto_layout()
tree.write()
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "drawpyo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "draw.io, diagrams.net, diagrams",
    "author": null,
    "author_email": "Xander Cesari <xander@merriman.industries>",
    "download_url": "https://files.pythonhosted.org/packages/08/5a/9f1bc505570dfa9e5d6b3e83665de1676546e3d06c5b0a6d1e5633d40ce0/drawpyo-0.1.3.tar.gz",
    "platform": null,
    "description": "# 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\", parent=grinders)\nburr_grinders = NodeObject(tree=tree, value=\"Burr Grinders\", parent=grinders)\nblunt_objects = NodeObject(tree=tree, value=\"Blunt Objects\", 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\", parent=blade_grinders)\nmnp = NodeObject(tree=tree, value=\"Mortar and Pestle\", parent=blunt_objects)\n\n# Conical Burrs\nconical = NodeObject(tree=tree, value=\"Conical Burrs\", parent=burr_grinders)\nelec_conical = NodeObject(tree=tree, value=\"Electric\", parent=conical)\nmanual_conical = NodeObject(tree=tree, value=\"Manual\", parent=conical)\n```\n\n> **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\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python library for programmatically generating Draw.io charts.",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/MerrimanInd/drawpyo",
        "Issues": "https://github.com/MerrimanInd/drawpyo/issues"
    },
    "split_keywords": [
        "draw.io",
        " diagrams.net",
        " diagrams"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "da3bf6a3607b19078ce0b46db2069d421e6af002c8e991b87a7ca7db1cc848f8",
                "md5": "f0819a1a063c927e0aba84d739fd16f3",
                "sha256": "5981963f0e2ce3b9f5e7331e371db1458485ffbee5d89adf665fe1aeb4527406"
            },
            "downloads": -1,
            "filename": "drawpyo-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f0819a1a063c927e0aba84d739fd16f3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 30186,
            "upload_time": "2024-04-25T15:20:17",
            "upload_time_iso_8601": "2024-04-25T15:20:17.119042Z",
            "url": "https://files.pythonhosted.org/packages/da/3b/f6a3607b19078ce0b46db2069d421e6af002c8e991b87a7ca7db1cc848f8/drawpyo-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "085a9f1bc505570dfa9e5d6b3e83665de1676546e3d06c5b0a6d1e5633d40ce0",
                "md5": "146998b1f785e21d787020ec40591e1f",
                "sha256": "c4acb3b7c75d12ad809c9400f8ef9a0b1f394e00c4f8db66baddbb0b29126e4e"
            },
            "downloads": -1,
            "filename": "drawpyo-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "146998b1f785e21d787020ec40591e1f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 26361,
            "upload_time": "2024-04-25T15:20:19",
            "upload_time_iso_8601": "2024-04-25T15:20:19.048182Z",
            "url": "https://files.pythonhosted.org/packages/08/5a/9f1bc505570dfa9e5d6b3e83665de1676546e3d06c5b0a6d1e5633d40ce0/drawpyo-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 15:20:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MerrimanInd",
    "github_project": "drawpyo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "drawpyo"
}
        
Elapsed time: 0.31637s