Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-py

elilambnz6.4kMIT1.11.3TypeScript support: included

Effortlessly run Python code in your React apps

react, python, pyodide

readme

react-py logo

Effortlessly run Python code in your React apps.

CI CodeQL MIT License NPM Version NPM Bundle Size


Try it out

You can try out react-py in the playground.

Quickstart

Install react-py with:

npm install react-py

Then, wrap your app in a PythonProvider component.

import { PythonProvider } from 'react-py'

function App() {
  return (
    // Add the provider to your app
    <PythonProvider>
      <Codeblock />
    </PythonProvider>
  )
}

render(<App />, document.getElementById('root'))

Using the usePython hook, you can run code and access both stdout and stderr. For full usage instructions and framework specific guides, see the usage docs.

Documentation

For full documentation, visit elilambnz.github.io/react-py.

Examples

Basic Example

REPL

Interrupting Execution

Using Packages

File System

Custom Modules

Making API Calls

User Input

Data Visualisation

Limitations

Most of the Python standard library is functional, except from some modules. The following modules can be imported, but are not functional due to the limitations of the WebAssembly VM:

  • multiprocessing
  • threading
  • sockets

Learn more about the limitations here.

License

react-py is available under the MIT License.

Maintainers

Eli Lamb - elilambnz
James Ansley - James-Ansley

Acknowledgments

This project uses Pyodide, a Python distribution for the browser and Node.js based on WebAssembly.

Contributing

If you're interested in contributing, please read our contributing docs before submitting a pull request.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.11.3 (2025-02-27)

1.11.2 (2024-08-05)

1.11.1 (2024-08-05)

Bug fixes

  • Encode prompt when sending to the sw (#346)

1.11.0 (2024-08-05)

Features

  • Added autoImportPackages prop to automatically import packages in a code chunk

1.10.7 (2024-02-13)

1.10.6 (2023-09-21)

1.10.5 (2023-07-23)

1.10.4 (2023-07-23)

Features

  • Support for external service workers

1.10.3 (2023-07-23)

Bug fixes

  • Fixed input patch code for Safari bug

1.10.2 (2023-07-23)

Bug fixes

  • Fixed an issue where Webpack would not resolve the service worker URL correctly

1.10.1 (2023-07-22)

Features

  • Update Pyodide to 0.23.3

1.10.0 (2023-07-22)

Features

  • Patch default stdin behaviour (#212)

1.9.0 (2023-07-04)

Features

  • Update Pyodide to 0.23.3 (#202)

1.8.5 (2023-02-10)

Bug fixes

  • Fix runPython is causing an infinite loop (#92)

1.8.0 (2023-01-10)

Features

  • Added interactive console (#61)

1.7.0 (2023-01-08)

Features

  • Update Pyodide to 0.22.0

1.5.0 (2022-12-31)

Features

  • Added file system support (#36)

1.4.0 (2022-12-30)

Bug fixes

  • Removed sourcemap from build (#51)

1.3.0 (2022-12-10)

Features

  • Added support for packages

1.1.0 (2022-11-27)

Features

  • Implemented web workers

1.0.4 (2022-08-08)

Bug fixes

  • Fix stdout is not returned when output does not end with newline (#1)

0.0.1 (2022-08-07)

Features

  • Removed the need to manually import Pyodide CDN