{"id":1017,"date":"2021-04-28T08:34:46","date_gmt":"2021-04-28T06:34:46","guid":{"rendered":"http:\/\/www.netexpertise.eu\/en\/?p=1017"},"modified":"2022-06-05T22:35:31","modified_gmt":"2022-06-05T20:35:31","slug":"show-all-available-icons-in-diagram-as-code","status":"publish","type":"post","link":"http:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html","title":{"rendered":"Show All Available Icons in Diagram as Code"},"content":{"rendered":"\n<p>Diagram as Code by <a href=\"https:\/\/diagrams.mingrammer.com\/docs\/getting-started\/examples\" target=\"_blank\" rel=\"noreferrer noopener\">Mingrammer<\/a> lets you draw <a href=\"\/en\/code\/python\/draw-beautiful-diagrams-with-diagram-as-code.html\">beautiful diagrams<\/a> while offering so many icons. It is just frustrating to go within all subdirectories to check and see all available icons. I decided to write a piece of code that imports classes from Diagram as Code package&#8217;s submodules.<br>I then gather each provider&#8217;s submodules in a cluster &#8211; that shows up as a blue area &#8211; and classes in green. A class matches a specific icon.<br><br>You will find on this image all icons available for your diagrams as code. Clic to expand image in bigger resolution, and right clic to save on your desktop.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.netexpertise.eu\/images\/diagram_as_code_all_icons.png\"><img decoding=\"async\" src=\"\/images\/diagram_as_code_all_icons_650.png\" alt=\"Diagram as code all available icons\"\/><\/a><\/figure>\n\n\n\n<p><br>Here is the source code that generates above image that you can adapt to your needs to get all the latest icons.<br>You might want to show icons for a specific provider or generate separate images for each.<br><br>I had to link icons with one another so they display horizontally rather than a single unending vertical column. This is what the recursive function display_icons is for. For some reason, recursivity works removing the last element, but the first.<br><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">#!\/usr\/bin\/env python3\n \nimport importlib\nimport pkgutil\nimport sys, inspect\n \nimport diagrams\nfrom diagrams import Cluster, Diagram, Edge\n \ndef get_modules(module):\n\u00a0\u00a0 path_list = []\n \u00a0 spec_list = []\n \u00a0 for importer, modname, ispkg in pkgutil.walk_packages(module.__path__):\n \u00a0\u00a0 \u00a0 import_path = f\"{module.__name__}.{modname}\"\n \u00a0\u00a0 \u00a0 if ispkg:\n \u00a0 \u00a0 \u00a0 \u00a0 spec = pkgutil._get_spec(importer, modname)\n \u00a0 \u00a0 \u00a0 \u00a0 importlib._bootstrap._load(spec)\n \u00a0 \u00a0 \u00a0 \u00a0 spec_list.append(spec)\n \u00a0\u00a0 \u00a0 else:\n \u00a0\u00a0\u00a0 \u00a0 \u00a0 path_list.append(import_path)\n \u00a0 return path_list\n \ndef get_classes(module):\n \u00a0 class_list = []\n \u00a0 for name, obj in inspect.getmembers(module,inspect.isclass):\n \u00a0  \u00a0 if not name.startswith('_'):\n \u00a0\u00a0\u00a0 \u00a0 \u00a0 class_list.append([name,obj])\u00a0\n \u00a0 return class_list\n \ndef add_module_to_provider_list(providers, module):\n \u00a0 # eg diagrams.azure.database\n \u00a0 # add \"database\" to array linked to key \"azure\"\n \u00a0 (diagram,provider,pclass) = module.split('.')\n \u00a0 if provider not in providers:\n \u00a0\u00a0 \u00a0 providers[provider] = [pclass]\n \u00a0 else:\n \u00a0  \u00a0 providers[provider].append(pclass)\n \ndef get_provider_list(providers):\n \u00a0 return providers.keys()\n \ndef get_provider_classes(providers, provider):\n \u00a0 return providers[provider]\n \ndef display_icons(class_list):\n \u00a0 if len(class_list) &lt; 1: return\n \u00a0 if len(class_list) == 1: return class_list[0][1](class_list[0][0])\n \u00a0 length = len(class_list)\n \u00a0 return display_icons(class_list[:-1]) - class_list[length-1][1](class_list[length-1][0])\n \nif __name__ == \"__main__\":\n \u00a0 providers = {}\n \u00a0 modules = get_modules(diagrams)\n \n \u00a0 for module in modules:\n \u00a0\u00a0 \u00a0 # Module exception\n \u00a0\u00a0 \u00a0 # \/usr\/local\/lib\/python3.8\/site-packages\/diagrams\/oci\/database.py\n \u00a0\u00a0 \u00a0 # NameError: name 'AutonomousDatabase' is not defined\n \u00a0\u00a0 \u00a0 if module not in ['diagrams.oci.database']:\n \u00a0\u00a0  \u00a0 \u00a0 add_module_to_provider_list(providers, module)\n \n \u00a0 with Diagram(\"all_Icons\", show=\"False\", outformat=\"png\"):\n \u00a0  \u00a0 for provider in get_provider_list(providers):\n \u00a0\u00a0\u00a0 \u00a0 \u00a0 with Cluster(provider):\n \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 for pclassname in get_provider_classes(providers, provider):\n \u00a0\u00a0  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 with Cluster(pclassname):\n \u00a0 \u00a0  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 classes = get_classes(importlib.import_module('diagrams.'+provider+'.'+pclassname))\n \u00a0 \u00a0  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 display_icons(classes)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Diagram as Code by Mingrammer lets you draw beautiful diagrams while offering so many icons. It is just frustrating to go within all subdirectories to check and see all available icons. I decided to write a piece of code that imports classes from Diagram as Code package&#8217;s submodules.I then gather each provider&#8217;s submodules in a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[431],"tags":[432,414,19],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netexpertise - Show All Available Icons in Diagram as Code<\/title>\n<meta name=\"description\" content=\"Show all available icons in diagram as code in a unique image. Provided with a Python piece of code for local generation\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netexpertise - Show All Available Icons in Diagram as Code\" \/>\n<meta property=\"og:description\" content=\"Show all available icons in diagram as code in a unique image. Provided with a Python piece of code for local generation\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html\" \/>\n<meta property=\"og:site_name\" content=\"Netexpertise\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-28T06:34:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-05T20:35:31+00:00\" \/>\n<meta name=\"author\" content=\"dave\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@netexpertise\" \/>\n<meta name=\"twitter:site\" content=\"@netexpertise\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html\",\"url\":\"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html\",\"name\":\"Netexpertise - Show All Available Icons in Diagram as Code\",\"isPartOf\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\"},\"datePublished\":\"2021-04-28T06:34:46+00:00\",\"dateModified\":\"2022-06-05T20:35:31+00:00\",\"author\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\"},\"description\":\"Show all available icons in diagram as code in a unique image. Provided with a Python piece of code for local generation\",\"breadcrumb\":{\"@id\":\"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.netexpertise.eu\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Show All Available Icons in Diagram as Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\",\"url\":\"http:\/\/www.netexpertise.eu\/en\/\",\"name\":\"Netexpertise\",\"description\":\"Systems \/ Networks \/ DevOps\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\",\"name\":\"dave\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"caption\":\"dave\"},\"sameAs\":[\"http:\/\/www.netexpertise.eu\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netexpertise - Show All Available Icons in Diagram as Code","description":"Show all available icons in diagram as code in a unique image. Provided with a Python piece of code for local generation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html","og_locale":"en_US","og_type":"article","og_title":"Netexpertise - Show All Available Icons in Diagram as Code","og_description":"Show all available icons in diagram as code in a unique image. Provided with a Python piece of code for local generation","og_url":"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html","og_site_name":"Netexpertise","article_published_time":"2021-04-28T06:34:46+00:00","article_modified_time":"2022-06-05T20:35:31+00:00","author":"dave","twitter_card":"summary_large_image","twitter_creator":"@netexpertise","twitter_site":"@netexpertise","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html","url":"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html","name":"Netexpertise - Show All Available Icons in Diagram as Code","isPartOf":{"@id":"http:\/\/www.netexpertise.eu\/en\/#website"},"datePublished":"2021-04-28T06:34:46+00:00","dateModified":"2022-06-05T20:35:31+00:00","author":{"@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa"},"description":"Show all available icons in diagram as code in a unique image. Provided with a Python piece of code for local generation","breadcrumb":{"@id":"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.netexpertise.eu\/en\/code\/python\/show-all-available-icons-in-diagram-as-code.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.netexpertise.eu\/en"},{"@type":"ListItem","position":2,"name":"Show All Available Icons in Diagram as Code"}]},{"@type":"WebSite","@id":"http:\/\/www.netexpertise.eu\/en\/#website","url":"http:\/\/www.netexpertise.eu\/en\/","name":"Netexpertise","description":"Systems \/ Networks \/ DevOps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa","name":"dave","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","caption":"dave"},"sameAs":["http:\/\/www.netexpertise.eu"]}]}},"_links":{"self":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/1017"}],"collection":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/comments?post=1017"}],"version-history":[{"count":0,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/1017\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/media?parent=1017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/categories?post=1017"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/tags?post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}