Pyodide is a Python distribution for the browser and Node.js based on WebAssembly
Go to file
Hood Chatham 7422ab370d
Implement more detailed streams support (#3268)
Resolves https://github.com/pyodide/pyodide/issues/3112
This adds a carefully designed API for controlling stdin, stdout, and stderr. It changes
the default behavior to be a bit more useful, though in doing so introduces some mild
backwards incompatibility. In particular:

1. By default, stdin reads directly from `process.stdin` in node (as before) and raises an
error if in browser (not as before).
2. By default, stdout writes directly to `process.stdout` in node (before it called console.log)
and calls console.log in browser (as before).
3. By default, stderr writes directly to `process.stderr` in node (before it called console.warn)
and calls console.warn in browser (as before).
4. In all three cases, by default isatty(stdin/stdout/stderr) is true in node and false in browser
(in the browser it used to be true).
5. As before, if you pass `stdin`, `stdout`, or `stderr` as arguments to `loadPyodide`, `isatty` of
the corresponding stream is set to false.

The stdin function is now more flexible: we now correctly handle the case where it returns an
ArrayBuffer or ArrayBufferView.

I also added 3 new functions to set streams after Pyodide is loaded which offer additional
control:
* `setStdin({stdin?, error?, isatty = false})` -- Sets the stdin function. The stdin function takes no
arguments and should return null, undefined, a string, or a buffer. Sets and `isatty(stdin)` to 
`isatty` (by default `false`). If error is true, set stdin to always raise an EIO error when it is read.
* `setStdout({raw?, batched?, isatty = false})` -- If neither raw nor batched is passed, restore 
default stdout behavior. If rwa is passed, the raw stdout function receives a byte which it should
interpret as a utf8 character code. Sets `isatty(stdout)` to isatty (by default `false`). If batched is
passed but not raw, it sets a batched stdout function. The stdout function receives a string and
should do something with it. In this case it ignores isatty and sets isatty(stdout) to false.
* `setStderr({raw?, batched?, isatty = false})` -- same but with stderr.
2022-12-18 15:55:52 -08:00
.circleci build packages from pypi direct (#3196) 2022-11-17 10:05:14 +09:00
.github Deploy pyodide-py in CI (#3356) 2022-12-15 10:22:23 +01:00
benchmark Disable matplotlib benchmark temporarily (#3205) 2022-10-28 11:39:16 +02:00
cpython Patch ctypes.util.find_library to support Emscripten platform (#3353) 2022-12-18 11:20:00 +01:00
docs Implement more detailed streams support (#3268) 2022-12-18 15:55:52 -08:00
emsdk Make fs timestamps have millisecond resolution rather than second resolution (#3313) 2022-12-10 09:50:08 -08:00
packages Remove unused shapely patch (accidentally added in #3365) 2022-12-18 15:45:50 -08:00
pyodide-build Fix version comparison in mkpkg update (#3364) 2022-12-18 11:14:24 +01:00
src Implement more detailed streams support (#3268) 2022-12-18 15:55:52 -08:00
tools Implement more detailed streams support (#3268) 2022-12-18 15:55:52 -08:00
.clang-format chore: update pre-commit hooks (#2209) 2022-02-23 23:58:11 -05:00
.codecov.yml Add codecov configuration (#3067) 2022-09-05 14:30:27 +09:00
.dockerignore Docker image with prebuilt pyodide (#787) 2020-11-08 21:05:38 +01:00
.editorconfig Fix #71: Upgrade to Python 3.7 2018-09-06 10:56:33 -04:00
.flake8 Use pyodide-cli entrypoint for out-of-tree CLI (#3140) 2022-09-24 18:34:36 -07:00
.gitignore build packages from pypi direct (#3196) 2022-11-17 10:05:14 +09:00
.gitpod.yml Add Gitpod configuration (#3201) 2022-10-24 21:13:01 +02:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate (#3345) 2022-12-13 00:08:49 +01:00
.prettierignore style: improve pre-commit (#2177) 2022-02-19 09:06:25 +01:00
.readthedocs.yml fix: better mypy coverage (#2339) 2022-04-01 21:58:54 +02:00
CODE-OF-CONDUCT.md MAINT Apply prettier to everything by default (#2095) 2022-01-10 13:47:59 -08:00
Dockerfile Fix chrome and chromedriver version mismatch in Docker image (#3219) 2022-11-02 13:35:31 +09:00
LICENSE Initial commit 2018-02-23 14:21:29 -05:00
Makefile NFC Use initialization function to load _pyodide_core (#3333) 2022-12-10 09:51:17 -08:00
Makefile.envs Emscripten 3.1.27 (#3314) 2022-12-02 16:12:42 -08:00
README.md DOCS Edits and updates (#2756) 2022-06-21 20:15:37 -07:00
codecov.yml Disable codecov annotations in pull requests (#3197) 2022-10-24 09:21:11 +09:00
conftest.py TST Run package tests in Safari (#3095) 2022-09-14 09:13:53 +09:00
lgtm.yml Apply lints suggested by lgtm.com (#1398) 2021-03-31 21:11:41 +02:00
pyodide_env.sh chore: more pre-commit checking (#2257) 2022-03-07 21:51:20 -08:00
pyproject.toml [pre-commit.ci] pre-commit autoupdate (#3254) 2022-12-02 15:12:33 -08:00
repository-structure.md chore: more pre-commit checking (#2257) 2022-03-07 21:51:20 -08:00
requirements.txt MAINT Use run_in_pyodide in xgboost, opencv, and matplotlib tests (#3184) 2022-10-28 17:35:27 +09:00
run_docker Remove pre-built docker image support (#3342) 2022-12-13 12:04:15 +09:00
setup.cfg MAINT Build test and distutils stdlib modules with pyodide-build (#2979) 2022-08-18 13:55:16 +09:00

README.md

NPM Latest Release PyPI Latest Release Build Status Documentation Status

Pyodide is a Python distribution for the browser and Node.js based on WebAssembly.

What is Pyodide?

Pyodide is a port of CPython to WebAssembly/Emscripten.

Pyodide makes it possible to install and run Python packages in the browser with micropip. Any pure Python package with a wheel available on PyPi is supported. Many packages with C extensions have also been ported for use with Pyodide. These include many general-purpose packages such as regex, PyYAML, lxml and scientific Python packages including NumPy, pandas, SciPy, Matplotlib, and scikit-learn.

Pyodide comes with a robust Javascript ⟺ Python foreign function interface so that you can freely mix these two languages in your code with minimal friction. This includes full support for error handling, async/await, and much more.

When used inside a browser, Python has full access to the Web APIs.

Try Pyodide (no installation needed)

Try Pyodide in a REPL directly in your browser. For further information, see the documentation.

Getting Started

Pyodide offers three different ways to get started depending on your needs and technical resources. These include:

  • Use a hosted distribution of Pyodide: see the Getting Started documentation.
  • Download a version of Pyodide from the releases page and serve it with a web server.
  • Build Pyodide from source
    • Build natively with make: primarily for Linux users who want to experiment or contribute back to the project.
    • Use a Docker image: recommended for Windows and macOS users and for Linux users who prefer a Debian-based Docker image with the dependencies already installed.

History

Pyodide was created in 2018 by Michael Droettboom at Mozilla as part of the Iodide project. Iodide is an experimental web-based notebook environment for literate scientific computing and communication.

Iodide is no longer maintained. If you want to use Pyodide in an interactive client-side notebook, see Pyodide notebook environments.

Contributing

Please view the contributing guide for tips on filing issues, making changes, and submitting pull requests. Pyodide is an independent and community-driven open-source project. The decision-making process is outlined in the Project governance.

Communication

License

Pyodide uses the Mozilla Public License Version 2.0.