Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Yes, absolutely! Depending on whether you want to generate **static image files** (like PNGs) or **editable Draw.io files** (`.drawio`), there are a few standout Python libraries that fit your exact needs for colors, symbols, and custom icons.
- Here are the best options currently available:
- ### 1. `diagrams` (The Most Popular)
- If you want a "Diagram as Code" approach that generates beautiful, static images, this is the industry standard.
- * **Customization:** It comes pre-loaded with thousands of icons for cloud providers (AWS, GCP, Azure), Kubernetes, programming languages, and general tech. You can also easily load your own custom images using the `Custom` node class.
- * **Styling:** You can customize node colors, line styles (dotted, bold, colored arrows), and group things into colored visual clusters.
- * **Output:** Renders directly to `.png`, `.svg`, or `.pdf`. (Note: It requires you to have Graphviz installed on your system).
- ```python
- # A quick example of how simple it is
- from diagrams import Diagram, Cluster
- from diagrams.aws.compute import EC2
- from diagrams.aws.database import RDS
- from diagrams.custom import Custom
- with Diagram("Web Architecture", show=False):
- with Cluster("VPC"):
- web = EC2("Web Server")
- db = RDS("Database")
- my_icon = Custom("Custom App", "./my_local_icon.png")
- my_icon >> web >> db # Draws directed arrows between them
- ```
- ### 2. `drawpyo` (Best for Native Draw.io Files)
- If you literally want to automate Draw.io and have the ability to manually tweak the diagram later, this library is built exactly for that.
- * **What it is:** It programmatically generates `.drawio` XML files.
- * **Customization:** You can place objects, style them using Draw.io's native style strings (hex colors, fonts, borders, gradients), and set up hierarchies.
- * **Icons:** You can access Draw.io's standard shape collections (General, Flowchart, etc.) and even import third-party XML icon sets from the web.
- * **Output:** Generates a file you can open, click, and edit in the Draw.io / diagrams.net app.
- ### 3. `Graphviz` (The Underlying Powerhouse)
- If you need ultimate, pixel-perfect control over your flowcharts and don't mind a steeper learning curve, you can use the official Python wrapper for `graphviz`.
- * **Customization:** Highly customizable. You can use HTML-like tables for nodes, define custom polygon shapes, insert images directly into nodes, and control exact node styling (fill colors, pen widths, fonts).
- * **Output:** Generates static images. `diagrams` (the first option) actually uses Graphviz under the hood to do its heavy lifting.
- ### 4. `drawio-diagram-generator`
- * **What it is:** A slightly newer, component-based Python library that also exports to Draw.io compatible XML files.
- * **Customization:** It offers a simple API where you can arrange "Boxes" and "IconBoxes" using rows and columns, pass custom CSS-like style strings, and embed image URLs.
- ---
- ### Quick Comparison
- | Library | Output Format | Best Feature | Learning Curve |
- | --- | --- | --- | --- |
- | **`diagrams`** | PNG, SVG, PDF | Massive built-in icon library | Very Easy |
- | **`drawpyo`** | `.drawio` (Editable) | Native Draw.io styling and shapes | Moderate |
- | **`Graphviz`** | PNG, SVG, PDF | Ultimate control over layout | Steep |
- What kind of diagrams are you primarily looking to generate (e.g., cloud architectures, software flowcharts, or network topologies)?
Advertisement