packages = ["bokeh", "pandas", "numpy", "networkx", "diagrams", "scikit-learn", "pillow", "matplotlib", "plotly"] [[fetch]] files = ["diagrams_base.py"] from = "../../python/diagrams/" [[fetch]] files = ["pyscript_manager.py", "data.py"] to_folder = "lib" from = "../../python/lib/" [[fetch]] files = ["bokeh_utils.py"] from = "../../python/bokeh/" [[fetch]] files = ["matplotlib_utils.py", "plotly_utils.py"] from = "../../python/matplotlib/" [[fetch]] files = ["agent.py", "trainer.py", "utils.py", "metrics_chart.py", "crossover.py", "__init__.py"] to_folder = "ml/neuro" from = "../../python/ml/neuro/" [[fetch]] files = ["trainer.py"] to_folder = "ml/grokking" from = "../../python/ml/grokking/"

Loading...

Example 1

Print hello world:


Example 2

Current date and time, as computed by Python:


Example 3

Fibonacci sequence, computed by Python:


Example 4

Snake traversal, computed by Python:

HELLO WORLD

PyScript allows you to run Python code directly in your web browser without any server-side processing.

Key Features:

  • Zero Server Setup: Python runs entirely in the browser using WebAssembly
  • Standard Library Access: Use familiar Python modules like datetime, sys, and more
  • Simple Integration: Add Python with just a tag
  • External Scripts: Load Python code from files using the src attribute
  • Console Output: View results in the browser console or write to the DOM

The Examples:

  • Example 1: Classic "Hello World" - The simplest PyScript program
  • Example 2: Current date/time - Demonstrates external Python scripts and datetime module
  • Example 3: Fibonacci sequence - Shows algorithmic computation and list comprehension
  • Example 4: Snake traversal - Matrix manipulation and DOM manipulation from Python

Getting Started:

The basic pattern for running Python in the browser is simple:

<script type="py">
  print("Hello from Python!")
</script>

<!-- Or load from a file -->
<script type="py" src="/path/to/script.py"></script>

Click the "πŸ–₯️ Open Console" button above to see the output of these Python scripts!

🐍 Python Console