Create design diagram using Python
- Sudherson Vetrichelvan
- Nov 26, 2020
- 1 min read
We spend more time in correcting the arrows and containers than focussing on the concept.
Python leverages graphviz an open source graph visualization software to create beautiful diagrams with in minutes.
Dependencies:
1. Install Visual Studio Code, https://code.visualstudio.com/download
2. Install Python extension for Visual Studio Code using Marketplace
3. Install Python , https://www.python.org/downloads/
4. Install PIP
> curl -O https://bootstrap.pypa.io/get-pip.py > python3 get-pip.py
5. Install Diagrams
> pip install diagrams
6. Install Graphviz, https://graphviz.org/download/ - I used homebrew.
Sample code:
from diagrams import Diagram, Cluster from diagrams.gcp.compute import Functions from diagrams.aws.compute import EC2 from diagrams.aws.network import ELB with Diagram("Webhook Processing Diagram", direction='LR') as diag: webhook = Functions("Web Hook") load_balancer = ELB("Load Balancer") with Cluster("Webserver Cluster"): web_group = [EC2("Webserver 1"), EC2("Webserver 2"), EC2("Webserver 3")] webhook >> load_balancer >> web_group
diag # render the diagram
Execute: > python3 <file_name>.py
Output:
Reference:
Comments