{"id":11730,"date":"2016-04-05T12:11:41","date_gmt":"2016-04-05T09:11:41","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=11730"},"modified":"2016-03-24T15:47:29","modified_gmt":"2016-03-24T13:47:29","slug":"python-reflection-list-modules-inspect-functions","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/","title":{"rendered":"Python reflection: how to list modules and inspect functions"},"content":{"rendered":"<p>Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS.<\/p>\n<p>To do any of this I would need to first build a model of Python code. Recently we have seen how to <a href=\"http:\/\/tomassetti.me\/parsing-any-language-in-java-in-5-minutes-using-antlr-for-example-python\/\">parse Python code<\/a>, however we still need to consider all the packages our code use. Some of those could be builtin\u00a0or be implemented through C extensions. That means we do not have python code for them. In this post I look into retrieving a list of all modules and then inspect their contents.<\/p>\n<p>My strategy is to use reflection writing scripts in Python. I will then invoke those scripts from inside Jetbrains MPS (and so from Java code). However this is the topic of a future post.<\/p>\n<h2>Listing modules<\/h2>\n<p>Listing top modules is relatively easy if you know how to do it. This script prints a list of all top level modules:<\/p>\n<pre class=\"brush:python\">import pkgutil\r\n\r\nfor p in pkgutil.iter_modules():\r\n    print(p[1])\r\n<\/pre>\n<p>Now we need to look inside modules to find sub-modules. For performance reasons I want to do that only when it is needed:<\/p>\n<pre class=\"brush:python\">import pkgutil\r\nimport sys\r\n \r\ndef explore_package(module_name):    \r\n    loader = pkgutil.get_loader(module_name)\r\n    for sub_module in pkgutil.walk_packages([loader.filename]):\r\n        _, sub_module_name, _ = sub_module\r\n        qname = module_name + &amp;.&amp; + sub_module_name\r\n        print(qname)\r\n        explore_package(qname)\r\n \r\nexplore_package(sys.argv[1])\r\n<\/pre>\n<p>For example for <em>xml<\/em> I get:<\/p>\n<pre class=\"brush:xml\">xml.dom\r\nxml.dom.NodeFilter\r\nxml.dom.domreg\r\nxml.dom.expatbuilder\r\nxml.dom.minicompat\r\nxml.dom.minidom\r\nxml.dom.pulldom\r\nxml.dom.xmlbuilder\r\nxml.etree\r\nxml.etree.ElementInclude\r\nxml.etree.ElementPath\r\nxml.etree.ElementTree\r\nxml.etree.cElementTree\r\nxml.parsers\r\nxml.parsers.expat\r\nxml.sax\r\nxml.sax._exceptions\r\nxml.sax.expatreader\r\nxml.sax.handler\r\nxml.sax.saxutils\r\nxml.sax.xmlreader\r\n<\/pre>\n<h2>Examining module contents and recognizing functions<\/h2>\n<p>Now given a module I need to list all its contents. I can load the module by name and iterate over it, printing information about the elements found.<\/p>\n<p>I want to distinguish between classes, submodules (which I will ignore for now), functions and simple values.<br \/>\nBuiltin functions need to be treated differently: to access their information I need to parse their documentation. Not cool, not cool at all.<\/p>\n<pre class=\"brush:python\">import sys\r\nimport inspect\r\n \r\ndef describe_builtin(obj):\r\n    \"\"\" Describe a builtin function \"\"\"\r\n    # Built-in functions cannot be inspected by\r\n    # inspect.getargspec. We have to try and parse\r\n    # the __doc__ attribute of the function.\r\n    docstr = obj.__doc__\r\n    args = ''\r\n    if docstr:\r\n        items = docstr.split('\\n')\r\n        if items:\r\n            func_descr = items[0]\r\n            s = func_descr.replace(obj.__name__,'')\r\n            idx1 = s.find('(')\r\n            idx2 = s.find(')',idx1)\r\n            if idx1 != -1 and idx2 != -1 and (idx2&gt;idx1+1):\r\n                args = s[idx1+1:idx2]\r\n    return args\r\n \r\npackage_name = sys.argv[1].strip()\r\nmymodule = __import__(package_name, fromlist=['foo'])\r\n \r\nfor element_name in dir(mymodule):\r\n    element = getattr(mymodule, element_name)\r\n    if inspect.isclass(element):\r\n        print(\"class %s\" % element_name)\r\n    elif inspect.ismodule(element):\r\n        pass        \r\n    elif hasattr(element, '__call__'):\r\n        if inspect.isbuiltin(element):\r\n            sys.stdout.write(\"builtin_function %s\" % element_name)\r\n            data = describe_builtin(element)\r\n            data = data.replace(\"[\", \" [\")\r\n            data = data.replace(\"  [\", \" [\")\r\n            data = data.replace(\" [, \", \" [\")\r\n            sys.stdout.write(data.replace(\", \", \" \"))\r\n            print(\"\")\r\n        else:                    \r\n            try:\r\n                data = inspect.getargspec(element)\r\n                sys.stdout.write(\"function %s\" % element_name)\r\n                for a in data.args:\r\n                    sys.stdout.write(\" \")\r\n                    sys.stdout.write(a)\r\n                if data.varargs:\r\n                    sys.stdout.write(\" *\")\r\n                    sys.stdout.write(data.varargs)\r\n                print(\"\")\r\n            except:\r\n                pass\r\n    else:\r\n        print(\"value %s\" % element_name)\r\n<\/pre>\n<p>This is what I get for the module <em>os<\/em>:<\/p>\n<pre class=\"brush:python\">value EX_CANTCREAT\r\nvalue EX_CONFIG\r\nvalue EX_DATAERR\r\nvalue EX_IOERR\r\nvalue EX_NOHOST\r\nvalue EX_NOINPUT\r\nvalue EX_NOPERM\r\nvalue EX_NOUSER\r\nvalue EX_OK\r\nvalue EX_OSERR\r\nvalue EX_OSFILE\r\nvalue EX_PROTOCOL\r\nvalue EX_SOFTWARE\r\nvalue EX_TEMPFAIL\r\nvalue EX_UNAVAILABLE\r\nvalue EX_USAGE\r\nvalue F_OK\r\nvalue NGROUPS_MAX\r\nvalue O_APPEND\r\nvalue O_ASYNC\r\nvalue O_CREAT\r\nvalue O_DIRECT\r\nvalue O_DIRECTORY\r\nvalue O_DSYNC\r\nvalue O_EXCL\r\nvalue O_LARGEFILE\r\nvalue O_NDELAY\r\nvalue O_NOATIME\r\nvalue O_NOCTTY\r\nvalue O_NOFOLLOW\r\nvalue O_NONBLOCK\r\nvalue O_RDONLY\r\nvalue O_RDWR\r\nvalue O_RSYNC\r\nvalue O_SYNC\r\nvalue O_TRUNC\r\nvalue O_WRONLY\r\nvalue P_NOWAIT\r\nvalue P_NOWAITO\r\nvalue P_WAIT\r\nvalue R_OK\r\nvalue SEEK_CUR\r\nvalue SEEK_END\r\nvalue SEEK_SET\r\nvalue ST_APPEND\r\nvalue ST_MANDLOCK\r\nvalue ST_NOATIME\r\nvalue ST_NODEV\r\nvalue ST_NODIRATIME\r\nvalue ST_NOEXEC\r\nvalue ST_NOSUID\r\nvalue ST_RDONLY\r\nvalue ST_RELATIME\r\nvalue ST_SYNCHRONOUS\r\nvalue ST_WRITE\r\nvalue TMP_MAX\r\nvalue WCONTINUED\r\nbuiltin_function WCOREDUMPstatus\r\nbuiltin_function WEXITSTATUSstatus\r\nbuiltin_function WIFCONTINUEDstatus\r\nbuiltin_function WIFEXITEDstatus\r\nbuiltin_function WIFSIGNALEDstatus\r\nbuiltin_function WIFSTOPPEDstatus\r\nvalue WNOHANG\r\nbuiltin_function WSTOPSIGstatus\r\nbuiltin_function WTERMSIGstatus\r\nvalue WUNTRACED\r\nvalue W_OK\r\nvalue X_OK\r\nclass _Environ\r\nvalue __all__\r\nvalue __builtins__\r\nvalue __doc__\r\nvalue __file__\r\nvalue __name__\r\nvalue __package__\r\nfunction _execvpe file args env\r\nfunction _exists name\r\nbuiltin_function _exitstatus\r\nfunction _get_exports_list module\r\nfunction _make_stat_result tup dict\r\nfunction _make_statvfs_result tup dict\r\nfunction _pickle_stat_result sr\r\nfunction _pickle_statvfs_result sr\r\nfunction _spawnvef mode file args env func\r\nbuiltin_function abort\r\nbuiltin_function accesspath mode\r\nvalue altsep\r\nbuiltin_function chdirpath\r\nbuiltin_function chmodpath mode\r\nbuiltin_function chownpath uid gid\r\nbuiltin_function chrootpath\r\nbuiltin_function closefd\r\nbuiltin_function closerangefd_low fd_high\r\nbuiltin_function confstrname\r\nvalue confstr_names\r\nbuiltin_function ctermid\r\nvalue curdir\r\nvalue defpath\r\nvalue devnull\r\nbuiltin_function dupfd\r\nbuiltin_function dup2old_fd new_fd\r\nvalue environ\r\nclass error\r\nfunction execl file *args\r\nfunction execle file *args\r\nfunction execlp file *args\r\nfunction execlpe file *args\r\nbuiltin_function execvpath args\r\nbuiltin_function execvepath args env\r\nfunction execvp file args\r\nfunction execvpe file args env\r\nvalue extsep\r\nbuiltin_function fchdirfildes\r\nbuiltin_function fchmodfd mode\r\nbuiltin_function fchownfd uid gid\r\nbuiltin_function fdatasyncfildes\r\nbuiltin_function fdopenfd [mode='r' [bufsize]]\r\nbuiltin_function fork\r\nbuiltin_function forkpty\r\nbuiltin_function fpathconffd name\r\nbuiltin_function fstatfd\r\nbuiltin_function fstatvfsfd\r\nbuiltin_function fsyncfildes\r\nbuiltin_function ftruncatefd length\r\nbuiltin_function getcwd\r\nbuiltin_function getcwdu\r\nbuiltin_function getegid\r\nfunction getenv key default\r\nbuiltin_function geteuid\r\nbuiltin_function getgid\r\nbuiltin_function getgroups\r\nbuiltin_function getloadavg\r\nbuiltin_function getlogin\r\nbuiltin_function getpgidpid\r\nbuiltin_function getpgrp\r\nbuiltin_function getpid\r\nbuiltin_function getppid\r\nbuiltin_function getresgid\r\nbuiltin_function getresuid\r\nbuiltin_function getsidpid\r\nbuiltin_function getuid\r\nbuiltin_function initgroupsusername gid\r\nbuiltin_function isattyfd\r\nbuiltin_function killpid sig\r\nbuiltin_function killpgpgid sig\r\nbuiltin_function lchownpath uid gid\r\nvalue linesep\r\nbuiltin_function linksrc dst\r\nbuiltin_function listdirpath\r\nbuiltin_function lseekfd pos how\r\nbuiltin_function lstatpath\r\nbuiltin_function majordevice\r\nbuiltin_function makedevmajor minor\r\nfunction makedirs name mode\r\nbuiltin_function minordevice\r\nbuiltin_function mkdirpath [mode=0777]\r\nbuiltin_function mkfifofilename [mode=0666]\r\nbuiltin_function mknodfilename [mode=0600 device]\r\nvalue name\r\nbuiltin_function niceinc\r\nbuiltin_function openfilename flag [mode=0777]\r\nbuiltin_function openpty\r\nvalue pardir\r\nbuiltin_function pathconfpath name\r\nvalue pathconf_names\r\nvalue pathsep\r\nbuiltin_function pipe\r\nbuiltin_function popencommand [mode='r' [bufsize]]\r\nfunction popen2 cmd mode bufsize\r\nfunction popen3 cmd mode bufsize\r\nfunction popen4 cmd mode bufsize\r\nbuiltin_function putenvkey value\r\nbuiltin_function readfd buffersize\r\nbuiltin_function readlinkpath\r\nbuiltin_function removepath\r\nfunction removedirs name\r\nbuiltin_function renameold new\r\nfunction renames old new\r\nbuiltin_function rmdirpath\r\nvalue sep\r\nbuiltin_function setegidgid\r\nbuiltin_function seteuiduid\r\nbuiltin_function setgidgid\r\nbuiltin_function setgroupslist\r\nbuiltin_function setpgidpid pgrp\r\nbuiltin_function setpgrp\r\nbuiltin_function setregidrgid egid\r\nbuiltin_function setresgidrgid egid sgid\r\nbuiltin_function setresuidruid euid suid\r\nbuiltin_function setreuidruid euid\r\nbuiltin_function setsid\r\nbuiltin_function setuiduid\r\nfunction spawnl mode file *args\r\nfunction spawnle mode file *args\r\nfunction spawnlp mode file *args\r\nfunction spawnlpe mode file *args\r\nfunction spawnv mode file args\r\nfunction spawnve mode file args env\r\nfunction spawnvp mode file args\r\nfunction spawnvpe mode file args env\r\nbuiltin_function statpath\r\nbuiltin_function stat_float_times [newval]\r\nclass stat_result\r\nbuiltin_function statvfspath\r\nclass statvfs_result\r\nbuiltin_function strerrorcode\r\nbuiltin_function symlinksrc dst\r\nbuiltin_function sysconfname\r\nvalue sysconf_names\r\nbuiltin_function systemcommand\r\nbuiltin_function tcgetpgrpfd\r\nbuiltin_function tcsetpgrpfd pgid\r\nbuiltin_function tempnam [dir [prefix]]\r\nbuiltin_function times\r\nbuiltin_function tmpfile\r\nbuiltin_function tmpnam\r\nbuiltin_function ttynamefd\r\nbuiltin_function umasknew_mask\r\nbuiltin_function uname\r\nbuiltin_function unlinkpath\r\nbuiltin_function unsetenvkey\r\nbuiltin_function urandomn\r\nbuiltin_function utimepath (atime mtime\r\nbuiltin_function wait\r\nbuiltin_function wait3options\r\nbuiltin_function wait4pid options\r\nbuiltin_function waitpidpid options\r\nfunction walk top topdown onerror followlinks\r\nbuiltin_function writefd strin\r\n<\/pre>\n<h2>Conclusions<\/h2>\n<p>I still need to build a model of the imported classes but I starting to have a decent model of the elements I can import in my Python code. This would permit to verify easily which import statements are valid. Of course this can be used in combination with virtualenvs and requirements files: given a list of requirements I would install them in a virtualenv and build the model of the modules available in that virtualenv. I could then statically verify which import would work in that context.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/tomassetti.me\/python-reflection-how-to-list-modules-and-inspect-functions\/\">Python reflection: how to list modules and inspect functions<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/join-us\/wcg\/\">WCG partner<\/a> Federico Tomassetti at the <a href=\"http:\/\/tomassetti.me\/\">Federico Tomassetti<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS. To do any of this I would need to first build a model of Python code. Recently we have seen how to parse Python code, however we still need to consider all the &hellip;<\/p>\n","protected":false},"author":149,"featured_media":1651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-11730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python reflection: how to list modules and inspect functions - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS. To do any of this I\" \/>\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.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python reflection: how to list modules and inspect functions - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS. To do any of this I\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-04-05T09:11:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Federico Tomassetti\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@raindancer\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Federico Tomassetti\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/\"},\"author\":{\"name\":\"Federico Tomassetti\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4d63f143f3c969ad223bc081c0284951\"},\"headline\":\"Python reflection: how to list modules and inspect functions\",\"datePublished\":\"2016-04-05T09:11:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/\"},\"wordCount\":388,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/\",\"name\":\"Python reflection: how to list modules and inspect functions - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"datePublished\":\"2016-04-05T09:11:41+00:00\",\"description\":\"Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS. To do any of this I\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python reflection: how to list modules and inspect functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4d63f143f3c969ad223bc081c0284951\",\"name\":\"Federico Tomassetti\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/10d3414571edf95f2255d57c9c02759daba20499f6761de9228c1cbbbd2fab6c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/10d3414571edf95f2255d57c9c02759daba20499f6761de9228c1cbbbd2fab6c?s=96&d=mm&r=g\",\"caption\":\"Federico Tomassetti\"},\"description\":\"Federico has a PhD in Polyglot Software Development. He is fascinated by all forms of software development with a focus on Model-Driven Development and Domain Specific Languages.\",\"sameAs\":[\"http:\/\/tomassetti.me\/\",\"https:\/\/fr.linkedin.com\/in\/federicotomassetti\",\"https:\/\/x.com\/raindancer\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/federico-tomassetti\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python reflection: how to list modules and inspect functions - Web Code Geeks - 2026","description":"Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS. To do any of this I","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.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/","og_locale":"en_US","og_type":"article","og_title":"Python reflection: how to list modules and inspect functions - Web Code Geeks - 2026","og_description":"Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS. To do any of this I","og_url":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-04-05T09:11:41+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","type":"image\/jpeg"}],"author":"Federico Tomassetti","twitter_card":"summary_large_image","twitter_creator":"@raindancer","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Federico Tomassetti","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/"},"author":{"name":"Federico Tomassetti","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4d63f143f3c969ad223bc081c0284951"},"headline":"Python reflection: how to list modules and inspect functions","datePublished":"2016-04-05T09:11:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/"},"wordCount":388,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/","url":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/","name":"Python reflection: how to list modules and inspect functions - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","datePublished":"2016-04-05T09:11:41+00:00","description":"Recently I have been playing with some ideas about applying static analysis to Python and building a Python editor in Jetbrains MPS. To do any of this I","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/python\/python-reflection-list-modules-inspect-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/www.webcodegeeks.com\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python reflection: how to list modules and inspect functions"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4d63f143f3c969ad223bc081c0284951","name":"Federico Tomassetti","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/10d3414571edf95f2255d57c9c02759daba20499f6761de9228c1cbbbd2fab6c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/10d3414571edf95f2255d57c9c02759daba20499f6761de9228c1cbbbd2fab6c?s=96&d=mm&r=g","caption":"Federico Tomassetti"},"description":"Federico has a PhD in Polyglot Software Development. He is fascinated by all forms of software development with a focus on Model-Driven Development and Domain Specific Languages.","sameAs":["http:\/\/tomassetti.me\/","https:\/\/fr.linkedin.com\/in\/federicotomassetti","https:\/\/x.com\/raindancer"],"url":"https:\/\/www.webcodegeeks.com\/author\/federico-tomassetti\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/11730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/149"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=11730"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/11730\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/1651"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=11730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=11730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=11730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}