Run Python in the Browser (Pyodide)
With Pyodide, you can run Python directly in the browser without any server-side setup. The runtime downloads on first use (~10MB) and all cells on the same page share variables by default.
Usage Guide
- Code is hidden by default — click "Show Code" to expand
- Click "Run" to execute the cell
- Click "Clear" to hide the output
- All cells share the same Python environment on this page
Basic Examples
Start with simple Python expressions:
Hello World
Idle
Basic calculations
Idle
Variable Sharing Between Cells
Define data in one cell and reuse it in subsequent cells:
Step 1: Define data
Idle
Step 2: Statistical analysis
Idle
Step 3: More operations
Idle
Data Visualization
Create beautiful plots with Matplotlib:
Line plot
Idle
Scatter plot with trend
Idle
Bar chart
Idle
Working with Pandas
Analyze data using the popular Pandas library:
DataFrame operations
Idle
Advanced: Machine Learning
Try a simple machine learning example:
K-Means Clustering
Idle
Custom Layout Options
Use the HTML form to override locale or layout per cell:
Horizontal Layout
Idle
中文示例
未加载
Markdown Syntax
You can use the pyodide language identifier in code blocks to create interactive cells:
markdown
```pyodide
print("Hello")
```
```pyodide title="With Title"
print("Hello")
```You can also use the <Pyodide> component for more control:
html
<Pyodide title="Custom Layout" layout="horizontal">
print("Hello")
</Pyodide>Important Notes
- First run: Downloads Pyodide runtime (~10MB); subsequent runs are instant
- Variable persistence: Variables persist within this page; navigating away resets the environment
- Package support: Most pure Python packages work; some C extensions are available
- Performance: Runs in browser with near-native speed via WebAssembly
Limitations
- Large numerical computations may be slower than native Python
- Some packages with C dependencies might not be available
- File I/O is limited to browser's virtual filesystem