pyscript API/docstring refactor with comprehensive tests (#2414)
* Revise display module. TODO: more comprehensive tests. Especially around mimebundles. * Markdown corrections in example code in display.py docstrings. * Minor adjustments and a much more comprehensive test-suite for the display module. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Updated docstring in __init__.py. * Remove unused imports and black-ify the source. * Refactor, docs and tests for the Event class in events.py. * Refactored, simplified and documented @when decorator. * Extensive test suite for @when decorator. * Documentation and minor refactoring of the fetch.py module. TODO: Check tests. * Refactored and more comprehensive tests for the fetch module. * Add/clarify Event related interactions. Thanks @Neon22 for the suggestion. * Refactor, document ffi.py module. * More complete passing tests for ffi.py. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add docstrings to flatted.py. Since this is actually an external(ish) module, tests for it should be in the external repository from which this code is derived. * Minor docstring cleanup in ffi.py. * Added docstrings and clarifications to fs.py. * Add very limited test suite for fs.py. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Rename magic_js.py to context.py, add comprehensive docstrings, and rename certain internal things for readability and comprehension. * Fix dict check in ffi.py. * Rename test_js_modules to test_context. * Fix test configuration aftert rename. * Docs and refactor of media.py. * Comprehensive tests for media.py. * Refactor and docstrings for storage.py * Appease the ruff gods. * Further storage.py changes and a more complete test suite for storage. * Refactor and docstrings for the util.py module. Fixed a problem with is_awaitable not handling async bound methods. * More comprehensive test suite for util.py. Updated to latest upytest. * A major refactoring, documenting and simplification of the web.py module substantially reducing it in size and complexity with only a few minor (edge) behavioural changes. Softly breaking changes include: - An element's classes are just a set. - An element's styles are just a dict. - Explicitly use `update_all` with ElementCollections (simpler and greater flexibility). - Extract a child element by id with `my_container["#an-id"]` * Updates and additions for a more comprehensive test suite for the web.py module. All code paths are exercised and checked. * Black tidy-ups in test suite. * Refactor and documentation for websocket.py module. * Tests for websocket.py. Disabled due to playwright flakiness, but they all pass in a local browser. * Refactor and documentation of workers.py module. * Added tests for workers.py module. Updated related test suite to account for the new named worker in the test HTML. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor away remaining "is not None" not caught before. * Remove check-docstring-first because it interferes with the auto-generated documentation (where triple quoted strings are used to document module attributes). * Careful Markdown changes so the docstrings render properly in the PyScript docs. * Typo correction. * More typo corrections and clarifications. * Add clarification about SVG handling to _render_image docstring. * Add DOM event options to the @when decorator (with new tests to exercise this functionality). * Fixes default value for options if no options passed into @when. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
PyScript
PyScript is an open source platform for Python in the browser.
Using PyScript is as simple as:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>PyScript!</title>
<link
rel="stylesheet"
href="https://pyscript.net/releases/2025.11.2/core.css"
/>
<script
type="module"
src="https://pyscript.net/releases/2025.11.2/core.js"
></script>
</head>
<body>
<!-- type mpy (MicroPython) or py (Pyodide) to run some Python -->
<script type="mpy" terminal>
print("Hello, world!")
</script>
</body>
</html>
PyScript enables the creation of rich Python applications in the browser using Pyodide (a version of CPython), MicroPython, WASM, and modern web technologies. It means Python now runs anywhere a browser runs: desktop, laptop, mobile, tablet, or any other browser enabled device.
To start building, read the Beginning PyScript tutorial.
For example applications, see here.
Other useful resources:
- Our Home Page as an open source project.
- The official technical docs.
- A YouTube channel with helpful videos and community content.
- A free-to-use online IDE for trying PyScript.
- Our community Discord Channel, to keep in touch .
Every Tuesday at 15:30 UTC there is the PyScript Community Call on zoom, where we can talk about PyScript development in the open. Most of the maintainers regularly participate in the call, and everybody is welcome to join. This meeting is recorded and uploaded to our YouTube channel.
Every other Thursday at 16:00 UTC there is the PyScript FUN call: the focus of this call is to share fun projects, goofy hacks or clever uses of PyScript. It's a supportive, energetic and entertaining meeting. This meeting is also recorded and uploaded to our YouTube channel.
For more details on how to join the calls and up to date schedule, consult the official calendar:
- Google calendar in UTC time;
- iCal format.
Contribute
For technical details of the code, please see the README in
the core directory.
Read the contributing guide to learn about our development process, reporting bugs and improvements, creating issues and asking questions.
Check out the development process documentation for more information on how to setup your development environment.
Governance
The PyScript organization governance is documented in a separate repository.
Supporters
PyScript is an independent open source project.
However, PyScript was born at Anaconda Inc and its core contributors are currently employed by Anaconda to work on PyScript. We would like to acknowledge and celebrate Anaconda's continued support of this project. Thank you Anaconda Inc!