Skip to content

qiushiyan/webpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

webpy is a JavaScript library for running Python in web apps. It's a wrapper of pyodide with couple of abstractions and runs in a web worker.

Usage

npm install webpy
import { initializePython } from "webpy"

const start = async () => {
    const python = await initializePython()
    return await python.runPython("list(map(abs, [1, -2, 3]))")
}

start()
//  {
//    output: "[1, 2, 3]",
// .  type: "list",
//    error: null
// }

Install python packages

await python.installPackages("pandas")
python.runPython(`
import pandas as pd

pd.DataFrame({"a": [1, 2, 3]})
`)
// {
//    output: '   a\n0  1\n1  2\n2  3',
//    type: "pd.DataFrame",
//    error: null
// }

React

npm install @webpy/react
export function() {
    const {
        runPython,
        installPackage,
        isRunning,
        isLoading,
        isInstalling
    } = usePython()

    useEffect(() => {
        if (!isLoading) {
            runPython("abs(-1)").then(console.log)
        }
    }, [isLoading])

    if (isLoading) {
        return "python is loading"
    }

    ...
}

Credits

webpy is inspired by react-py.

About

JavaScript library for running Python in the browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published