Last active
April 2, 2024 15:01
-
-
Save dylanroy/dd48a8d3cb7dc581d976329208c1c422 to your computer and use it in GitHub Desktop.
Code snippets from Medium Blog Post Create Beautiful Architecture Diagrams with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diagrams import Diagram | |
with Diagram("Simple Website Diagram") as diag: | |
pass | |
diag # This will illustrate the diagram if you are using a Google Colab or Jypiter notebook. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diagrams import Diagram, Cluster | |
from diagrams.aws.compute import EC2 | |
from diagrams.aws.network import ELB | |
from diagrams.aws.network import Route53 | |
from diagrams.onprem.database import PostgreSQL # Would typically use RDS from aws.database | |
from diagrams.onprem.inmemory import Redis # Would typically use ElastiCache from aws.database | |
with Diagram("Simple Website Diagram") as diag: | |
dns = Route53("dns") | |
load_balancer = ELB("Load Balancer") | |
database = PostgreSQL("User Database") | |
cache = Redis("Cache") | |
svc_group = [EC2("Webserver 1"), | |
EC2("Webserver 2"), | |
EC2("Webserver 3")] | |
diag # This will illustrate the diagram if you are using a Google Colab or Jypiter notebook. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diagrams import Diagram, Cluster | |
from diagrams.aws.compute import EC2 | |
from diagrams.aws.network import ELB | |
from diagrams.aws.network import Route53 | |
from diagrams.onprem.database import PostgreSQL # Would typically use RDS from aws.database | |
from diagrams.onprem.inmemory import Redis # Would typically use ElastiCache from aws.database | |
with Diagram("Simple Website Diagram") as diag: | |
dns = Route53("dns") | |
load_balancer = ELB("Load Balancer") | |
database = PostgreSQL("User Database") | |
cache = Redis("Cache") | |
with Cluster("Webserver Cluster"): | |
svc_group = [EC2("Webserver 1"), | |
EC2("Webserver 2"), | |
EC2("Webserver 3")] | |
diag # This will illustrate the diagram if you are using a Google Colab or Jypiter notebook. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diagrams import Diagram, Cluster | |
from diagrams.aws.compute import EC2 | |
from diagrams.aws.network import ELB | |
from diagrams.aws.network import Route53 | |
from diagrams.onprem.database import PostgreSQL # Would typically use RDS from aws.database | |
from diagrams.onprem.inmemory import Redis # Would typically use ElastiCache from aws.database | |
with Diagram("Simple Website Diagram", direction='LR') as diag: # It's LR by default, but you have a few options with the orientation | |
dns = Route53("dns") | |
load_balancer = ELB("Load Balancer") | |
database = PostgreSQL("User Database") | |
cache = Redis("Cache") | |
with Cluster("Webserver Cluster"): | |
svc_group = [EC2("Webserver 1"), | |
EC2("Webserver 2"), | |
EC2("Webserver 3")] | |
dns >> load_balancer >> svc_group | |
svc_group >> cache | |
svc_group >> database | |
diag # This will illustrate the diagram if you are using a Google Colab or Jypiter notebook. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install diagrams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diagrams import Cluster, Diagram | |
from diagrams.gcp.analytics import BigQuery, Dataflow, PubSub | |
from diagrams.gcp.compute import AppEngine, Functions | |
from diagrams.gcp.database import BigTable | |
from diagrams.gcp.iot import IotCore | |
from diagrams.gcp.storage import GCS | |
with Diagram("Media Monitoring Storage Architecture", show=False) as med_diag: | |
pubsub = PubSub("pubsub") | |
flow = Dataflow("DataFlow") | |
with Cluster("Data Collection"): | |
[Functions("RSS Feed Webhook"), | |
Functions("Twitter Webhook"), | |
Functions("Press Release")] >> pubsub >> flow | |
with Cluster("Storage"): | |
with Cluster("Data Lake"): | |
flow >> [BigQuery("BigQuery"), | |
GCS("Storage")] | |
with Cluster("Event Driven"): | |
with Cluster("Processing"): | |
flow >> AppEngine("GAE") >> BigTable("BigTable") | |
with Cluster("Serverless"): | |
flow >> Functions("Function") >> AppEngine("AppEngine") | |
pubsub >> flow | |
med_diag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran into an error:
NameError: name 'Cluster' is not defined