@@ -64,3 +64,58 @@ Notes on availability
64
64
libc version, then both conditions must hold. For example a feature with note
65
65
*Availability: Linux >= 3.17 with glibc >= 2.27 * requires both Linux 3.17 or
66
66
newer and glibc 2.27 or newer.
67
+
68
+ .. _wasm-availability :
69
+
70
+ WebAssembly platforms
71
+ ---------------------
72
+
73
+ The `WebAssembly `_ platforms ``wasm32-emscripten `` (`Emscripten `_) and
74
+ ``wasm32-wasi `` (`WASI `_) provide a subset of POSIX APIs. WebAssembly runtimes
75
+ and browsers are sandboxed and have limited access to the host and external
76
+ resources. Any Python standard library module that uses processes, threading,
77
+ networking, signals, or other forms of inter-process communication (IPC), is
78
+ either not available or may not work as on other Unix-like systems. File I/O,
79
+ file system, and Unix permission-related functions are restricted, too.
80
+ Emscripten does not permit blocking I/O. Other blocking operations like
81
+ :func: `~time.sleep ` block the browser event loop.
82
+
83
+ The properties and behavior of Python on WebAssembly platforms depend on the
84
+ `Emscripten `_-SDK or `WASI `_-SDK version, WASM runtimes (browser, NodeJS,
85
+ `wasmtime `_), and Python build time flags. WebAssembly, Emscripten, and WASI
86
+ are evolving standards; some features like networking may be
87
+ supported in the future.
88
+
89
+ For Python in the browser, users should consider `Pyodide `_ or `PyScript `_.
90
+ PyScript is built on top of Pyodide, which itself is built on top of
91
+ CPython and Emscripten. Pyodide provides access to browsers' JavaScript and
92
+ DOM APIs as well as limited networking capabilities with JavaScript's
93
+ ``XMLHttpRequest `` and ``Fetch `` APIs.
94
+
95
+ * Process-related APIs are not available or always fail with an error. That
96
+ includes APIs that spawn new processes (:func: `~os.fork `,
97
+ :func: `~os.execve `), wait for processes (:func: `~os.waitpid `), send signals
98
+ (:func: `~os.kill `), or otherwise interact with processes. The
99
+ :mod: `subprocess ` is importable but does not work.
100
+
101
+ * The :mod: `socket ` module is available, but is limited and behaves
102
+ differently from other platforms. On Emscripten, sockets are always
103
+ non-blocking and require additional JavaScript code and helpers on the
104
+ server to proxy TCP through WebSockets; see `Emscripten Networking `_
105
+ for more information. WASI snapshot preview 1 only permits sockets from an
106
+ existing file descriptor.
107
+
108
+ * Some functions are stubs that either don't do anything and always return
109
+ hardcoded values.
110
+
111
+ * Functions related to file descriptors, file permissions, file ownership, and
112
+ links are limited and don't support some operations. For example, WASI does
113
+ not permit symlinks with absolute file names.
114
+
115
+ .. _WebAssembly : https://webassembly.org/
116
+ .. _Emscripten : https://emscripten.org/
117
+ .. _Emscripten Networking : https://emscripten.org/docs/porting/networking.html>
118
+ .. _WASI : https://wasi.dev/
119
+ .. _wasmtime : https://wasmtime.dev/
120
+ .. _Pyodide : https://pyodide.org/
121
+ .. _PyScript : https://pyscript.net/
0 commit comments