PyScript

PyScript
DeveloperAnaconda, Inc.
Stable release
2026.3.1[1]  / 2 March 2026 (2 March 2026)
OScross-platform
LicenseApache Software License 2.0[2]
Websitepyscript.net
Influenced by
Python[3]

PyScript is a framework for running Python scripts in a web browser.[4][5] PyScript was presented to the public by Peter Wang at a Python developer conference in June 2022.[6][7] PyScript is primarily developed by Anaconda, Inc.

Usage

PyScript allows Python scripts, which normally run on a server, to be executed in a web browser.[8] This allows the same programming language to be used in the backend (on the server) and in the frontend (in the web browser). PyScript is a TypeScript library that is loaded by the web page and interprets the embedded Python scripts. Apart from PyScript's JavaScript library and CSS rules, there are no other dependencies. JavaScript is typically used to provide dynamic functionality to a web page. PyScript can replace JavaScript, but it can also run side-by-side with JavaScript. This allows JavaScript to call PyScript functions and vice versa. The advantage of PyScript lies in the large number of available Python libraries that can be used on web pages. These must be installed on the server.[9] For example, there are graphics libraries for editing digital images. The image data does not have to be sent to the server for processing. Another example is the creation of graphs and diagrams.[10] The Python programming language was mainly used on the server side. There has been virtually no support for pure front-end development so far. PyScript is intended to help close this gap.[11][12]

In order to execute Python scripts in a browser, you need a Python runtime environment. Several Python runtime environments exist, typically written in C. PyScript can theoretically work with various runtime environments. By default, Pyodide (a port of the CPython runtime environment to WebAssembly) is used.[7] Many well-known Python packages have also been ported to WebAssembly and can therefore be used by PyScript. Pyodide was developed in 2018 by Michael Droettboom at the Mozilla Foundation.[13] To use Pyodide, and thus PyScript, in a browser, Firefox version 70.0 or Google Chrome version 71.0 or higher is required.[14]

Examples

Example: What time is it?

The following example imports three packages. These contain functions for output control, date management, and event handling. Each time the button is clicked, the current date and time are displayed in a new line.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <title>PyScript: What time is it?</title>
    <link rel="stylesheet" href="https://pyscript.net/releases/2025.10.3/core.css">
    <script defer type="module" src="https://pyscript.net/releases/2025.10.3/core.js"></script>
  </head>
  <body>
    <button id="btnTime">What time is it?</button>
    <script type="py">
      from pyscript import when, display
      from datetime import datetime
      @when("click", "#btnTime")
      def click_handler(event):
        now = datetime.now()
        display(
          now.strftime(
            "Today is %m/%d/%Y. " +
            "The current time is %I:%M:%S %p."
          )
        )
    </script>
  </body>
</html>

As an alternative to <script type="py">, the element <py-script> can also be used (as in the example below). However, the new notation is recommended.[15]

PyScript also offers the possibility to communicate with the user via a command prompt. For this, the terminal attribute must be added to the <script type="py"> or <py-script> element. If input should also be possible, the worker attribute must be specified as well.[16] In earlier versions, a terminal could also be implemented using the <py-terminal> element.

Example: Bar chart

This example shows how to create a bar chart.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <title>PyScript: Bar chart</title>
    <link rel="stylesheet" href="https://pyscript.net/releases/2025.10.3/core.css">
    <script defer type="module" src="https://pyscript.net/releases/2025.10.3/core.js"></script>
  </head>
  <body>
    <div id="mpl"></div>
    <py-config>
      packages = ["matplotlib"]
    </py-config>
    <py-script>
      import matplotlib.pyplot as plt
      from pyscript import display
      fig, ax = plt.subplots()
      x = ["Apples", "Pears", "Bananas", "Pineapples"]
      y = [3, 7, 8, 10]
      plt.bar(x, y)
      plt.xlabel('Fruits')
      plt.ylabel('Popularity')
      plt.title('Fruits and their popularity')
      fig
      display(fig, target="mpl")
    </py-script>
  </body>
</html>

In order to create such diagrams, the matplotlib extension must be loaded in an <py-config> block.

Literature

  • Merkert, Pina (2022). c’t Python: PyScript im Browser statt JavaScript (in German). Heise Group. p. 30. ISBN 978-3-95788-318-6.
  • Divadkar, Varun (2024). "The PyScript Framework". Learn Autonomous Programming with Python. BPB Publications. pp. 257–274. ISBN 978-93-5551763-0.

References

  1. ^ "Release 2026.3.1". GitHub. Retrieved 7 March 2026.
  2. ^ "Apache License 2.0 (PyScript)". GitHub. Retrieved 27 May 2024.
  3. ^ "PyScript". Retrieved 27 May 2024. PyScript is a platform for Python in the browser.
  4. ^ "Run Python Script in the Web Browser". tpointtech.com. Retrieved 2023-01-19.
  5. ^ Yegulalp, Serdar (2022-06-15). "Intro to PyScript: Run Python in your web browser". infoworld.com. Retrieved 2023-01-19.
  6. ^ Zaczyński, Bartosz (2022-06-06). "A First Look at PyScript: Python in the Web Browser". realpython.com. Retrieved 2023-01-19.
  7. ^ a b Madachy, Raymond (2025). "PyScript". What Every Engineer Should Know About Python. CRC Press. p. 238. ISBN 978-1-03-235562-7.
  8. ^ Martelli, Alex; Martelli Ravenscroft, Anna; Holden, Steve; McGuire, Paul (2023). "PyScript". Python in a Nutshell (4 ed.). O’Reilly. p. 31. ISBN 978-1-09-811352-0.
  9. ^ Shmoon, Muhammad. "How to import external libraries and Python script in pyscript". educative.io. Retrieved 2023-01-19.
  10. ^ Chandra, Yuvraj (2022-08-10). "Run Python Visualizations on the Web Using PyScript". makeuseof.com. Retrieved 2023-01-19.
  11. ^ Olusheye, Ifihanagbara (2022-05-25). "How to Use PyScript – A Python Frontend Framework". freecodecamp.org. Retrieved 2023-01-19.
  12. ^ "How to Create an Interactive Web App With PyScript and Pandas". turing.com. Retrieved 2023-01-19.
  13. ^ "What is Pyodide?". pyodide.org. Retrieved 2023-01-19.
  14. ^ "Using Pyodide: Supported browsers". pyodide.org. Retrieved 2023-01-19.
  15. ^ "First steps". docs.pyscript.net. Retrieved 2025-10-24.
  16. ^ "Terminal". docs.pyscript.net. Retrieved 2025-10-26.