Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
Python Land
  • Python Tutorial
  • Shop
  • Blog
  • Login / Register
  • Contact
0
Home » Blog » PyScript: Run Python In Your Browser, Including Numpy And Pandas
PyScript

PyScript: Run Python In Your Browser, Including Numpy And Pandas

August 19, 2022

PyScript allows you to create rich Python applications in the browser using nothing but HTML and Python code. Although it’s super rough and super new, I can tell you this will be a game-changing part of the Python ecosystem. It’s worth keeping a close watch on this one!

This article explains what PyScript is and how it works. I also included a fully working PyScript REPL for you to play with.

Table of Contents

  • 1 What is PyScript
  • 2 How does PyScript work?
  • 3 What does PyScript add to Pyodide?
  • 4 The PyScript REPL

What is PyScript

PyScript was introduced on PyCon US 2022 by a company well known in the Python world: Anacona. The aim is to allow Python in the context of your browser. PyScript allows you to:

  • Write Python code between specific <py-script> </py-script> tags
  • Interact with JavaScript code, including all the available JavaScript libraries.
  • Run popular Python packages right in your browser. Some packages that are available include:
    • Numpy
    • Pandas
    • pyyaml
  • Manage the environment. You can define which packages to include on a page.
  • Create visual applications with buttons, text boxes, containers, etcetera.

How does PyScript work?

PyScript runs in your browser, which is pretty amazing! Under the hood, PyScript uses a project called Pyodide. Pyodide is a port of CPython to WebAssembly. This project did not just port CPython to web assembly, but also made the effort to compile well-known packages like Pandas and Numpy so they can be run right from the browser.

In the following screenshot, you can see the actual Python REPL running in my browser:

Pyodide REPL
Pyodide REPL, running in my browser

What does PyScript add to Pyodide?

So why is PyScript such a big deal? It’s mostly because it makes using Python in the browser more accessible. All you need to do, is include some JavaScript and you’re ready to use the py-script tags to include Python code in your HTML page.

Another thing I noticed, is that PyScript is trying hard to make Python interoperate with the browser. The Pyodide REPL doesn’t support the input() function, for example. PyScript does, by means of a simple JavaScript popup box asking for your input.

The PyScript REPL

The following REPL runs entirely in your browser, thanks to the awesome PyScript project. PyScript is new and experimental and was only tested in recent browsers so far. However, I’ve found it works in Firefox and anything based on Chrome, like Chrome itself, Chromium, and Microsoft Edge.

Usage instructions

Note that this resembles a regular Python REPL, but it’s not at all the same as the real Python REPL. For example, you need to enter your code and hit shift+enter or the play button to run it. It doesn’t support the underscore to get the previous result. It does support the input() function though!

The REPL

I’ve embedded the REPL below. If you don’t see anything, it probably means your browser is not supported:

Get certified with our courses

Learn Python properly through small, easy-to-digest lessons, progress tracking, quizzes to test your knowledge, and practice sessions. Each course will earn you a downloadable course certificate.

  • Sale Product on sale
    The Python Course for Beginners
    Beginners Python Course (2024)
    € 59.00 Original price was: € 59.00.€ 39.00Current price is: € 39.00.
  • Sale Product on sale
    Computer Fundamentals
    Files, Folders, And The Command Line (2024)
    € 39.00 Original price was: € 39.00.€ 19.00Current price is: € 19.00.
  • Sale Product on sale
    Modules, Packages, And Virtual Environments (2024)
    Modules, Packages, And Virtual Environments (2024)
    € 59.00 Original price was: € 59.00.€ 39.00Current price is: € 39.00.

Leave a Comment Cancel reply

You must be logged in to post a comment.

Subscribe to my newsletter for Python news, tips, and tricks!

Footer subscribe

  • Home
  • Python Courses
  • Privacy Policy
  • About Us
  • Contact us
©2025 Python Land - All rights reserved
Python Land is not affiliated with Python.org or the Python Software Foundation
  • Free Tutorial
    • Install Python
      • Online Python Interpreter
      • How To Open Python on Windows, Mac, Linux
    • Introduction to Python
      • The Python REPL
      • Python Variable
      • Python String
      • Python Print function
      • Python Booleans
      • For-loop and While-loop
      • Python Functions
      • Your First Python Program
      • Python Comments
    • Creating Python Programs
      • The Best Python IDE
      • Installing VSCode
      • VSCode Python Extensions
      • VSCode GUI Tour
      • Python in VSCode: Running and Debugging
    • Classes and Objects in Python
      • Python Constructor
      • Python Inheritance
    • Structure Your Project
      • Python Modules And Importing
      • Python Packages
    • Python Data Types
      • Python Integer
      • Python Float
      • Python Tuple
      • Python List
      • Python Set
      • Python Dictionary
    • Language Deep Dives
      • Python Try Except (Exceptions)
      • Python Functions: Advanced Concepts
      • List Comprehension
      • Python Iterator
      • Python Range
      • Python Docstrings
      • Python pass (Do Nothing)
    • Interaction with the OS
      • Python Read And Write File
      • Python Subprocess: Run External Commands
    • Venvs / Package Management
      • Working With Python’s venv
      • Pip install: the Python package manager
      • Python Poetry: Package and venv Management Made Easy
      • Python Pipenv: Another Package Manager
      • Pipx: Safely Install Packages Globally
    • Python Concurrency
      • The Python GIL (Global Interpreter Lock)
      • Setting the Baseline
      • Python Threading
      • Python Multiprocessing
    • Data Processing with Python
      • Working With JSON
        • JMESPath Python: JSON Query Language
      • Python YAML: How to Load, Read, and Write YAML
      • Python CSV: Read And Write CSV Files
    • Migrating From Python 2 to 3
      • Check Python Version On The Command-Line
      • How to Migrate To Python 3
      • Python 3 Advantages
    • Using The Unix Shell
      • Basic Linux Commands
      • Bash Scripts
      • Using the Find Command in Linux
      • Unix Pipes
      • Process and Highlight JSON with jq
      • Using the Bash History
      • Bash Multiprocessing
    • Deployment
      • PyInstaller: Create An Executable From Python Code
      • How To Use Docker To Containerize Your Python Project
      • Automatically Build and Deploy Your Python Application with CI/CD
      • Guerrilla Scale Your Web Application
    • Data Science
      • Jupyter Notebook
      • NumPy: Getting Started Tutorial
    • Python Learning Resources
  • Python Courses
  • Blog
  • Login / Register