📦 Package Management
Install pure Python packages from PyPI using micropip:
import micropip
await micropip.install("requests")
Common scientific packages (numpy, pandas, matplotlib) are pre-built and load automatically when imported.
🌐 JavaScript Interop
Access the browser environment and JS libraries:
from js import window, document, console
window.alert("Python says hi!")
document.title = "Updated from Python"
📊 Plotting
Matplotlib plots are automatically rendered in the console area or a dedicated container if %matplotlib inline style behavior is expected.
📂 File System
Pyodide uses a virtual file system. Files created are stored in memory and lost on page refresh.
with open("test.txt", "w") as f:
f.write("Hello World")
💡 Pro Tips
- Use
await at top-level for asynchronous calls.
- The
input() function is supported via a browser prompt.
- Check the browser console (F12) for detailed logs if something fails silently.