Skip to content

Instantly share code, notes, and snippets.

@tomrockdsouza
Created January 10, 2026 11:42
Show Gist options
  • Select an option

  • Save tomrockdsouza/9b7f01ffe0df3bcd27cb5e6d57a847fc to your computer and use it in GitHub Desktop.

Select an option

Save tomrockdsouza/9b7f01ffe0df3bcd27cb5e6d57a847fc to your computer and use it in GitHub Desktop.
This implementation of code gives the submodules present in the latest version of pyscript micropython
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module" src="https://cdn.jsdelivr.net/npm/@pyscript/core/dist/core.js"></script>
</head>
<body>
<button mpy-click="handle_click">Inspect Modules</button>
<div id="output"></div>
<script type="mpy" id="mpy-script">
from pyscript import document
def handle_click(event):
functionx = document.getElementById("output")
output = "MicroPython Modules and Their Contents:\n\n"
import sys
modules = sorted(sys.modules.keys())
for module_name in modules:
try:
module = sys.modules[module_name]
output += f'{module_name}\n'
# Get all attributes of the module
attrs = dir(module)
for attr in attrs:
# Skip private attributes (starting with _)
if attr.startswith('_'):
continue
try:
obj = getattr(module, attr)
obj_type = type(obj).__name__
# Classify the object
if callable(obj):
if obj_type == 'type':
output += f' [class] {attr}\n'
else:
output += f' [function] {attr}\n'
else:
output += f' [{obj_type}] {attr}\n'
except Exception as e:
output += f' {attr} (error accessing)\n'
output += '\n'
functionx.innerText = output
except Exception as e:
output += f' Error inspecting module: {str(e)}\n\n'
functionx.innerText = output
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment