1.. _library-intro: 2 3************ 4Introduction 5************ 6 7The "Python library" contains several different kinds of components. 8 9It contains data types that would normally be considered part of the "core" of a 10language, such as numbers and lists. For these types, the Python language core 11defines the form of literals and places some constraints on their semantics, but 12does not fully define the semantics. (On the other hand, the language core does 13define syntactic properties like the spelling and priorities of operators.) 14 15The library also contains built-in functions and exceptions --- objects that can 16be used by all Python code without the need of an :keyword:`import` statement. 17Some of these are defined by the core language, but many are not essential for 18the core semantics and are only described here. 19 20The bulk of the library, however, consists of a collection of modules. There are 21many ways to dissect this collection. Some modules are written in C and built 22in to the Python interpreter; others are written in Python and imported in 23source form. Some modules provide interfaces that are highly specific to 24Python, like printing a stack trace; some provide interfaces that are specific 25to particular operating systems, such as access to specific hardware; others 26provide interfaces that are specific to a particular application domain, like 27the World Wide Web. Some modules are available in all versions and ports of 28Python; others are only available when the underlying system supports or 29requires them; yet others are available only when a particular configuration 30option was chosen at the time when Python was compiled and installed. 31 32This manual is organized "from the inside out:" it first describes the built-in 33functions, data types and exceptions, and finally the modules, grouped in 34chapters of related modules. 35 36This means that if you start reading this manual from the start, and skip to the 37next chapter when you get bored, you will get a reasonable overview of the 38available modules and application areas that are supported by the Python 39library. Of course, you don't *have* to read it like a novel --- you can also 40browse the table of contents (in front of the manual), or look for a specific 41function, module or term in the index (in the back). And finally, if you enjoy 42learning about random subjects, you choose a random page number (see module 43:mod:`random`) and read a section or two. Regardless of the order in which you 44read the sections of this manual, it helps to start with chapter 45:ref:`built-in-funcs`, as the remainder of the manual assumes familiarity with 46this material. 47 48Let the show begin! 49 50 51.. _availability: 52 53Notes on availability 54===================== 55 56* An "Availability: Unix" note means that this function is commonly found on 57 Unix systems. It does not make any claims about its existence on a specific 58 operating system. 59 60* If not separately noted, all functions that claim "Availability: Unix" are 61 supported on macOS, which builds on a Unix core. 62 63* If an availability note contains both a minimum Kernel version and a minimum 64 libc version, then both conditions must hold. For example a feature with note 65 *Availability: Linux >= 3.17 with glibc >= 2.27* requires both Linux 3.17 or 66 newer and glibc 2.27 or newer. 67 68.. _wasm-availability: 69 70WebAssembly platforms 71--------------------- 72 73The `WebAssembly`_ platforms ``wasm32-emscripten`` (`Emscripten`_) and 74``wasm32-wasi`` (`WASI`_) provide a subset of POSIX APIs. WebAssembly runtimes 75and browsers are sandboxed and have limited access to the host and external 76resources. Any Python standard library module that uses processes, threading, 77networking, signals, or other forms of inter-process communication (IPC), is 78either not available or may not work as on other Unix-like systems. File I/O, 79file system, and Unix permission-related functions are restricted, too. 80Emscripten does not permit blocking I/O. Other blocking operations like 81:func:`~time.sleep` block the browser event loop. 82 83The 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 86are evolving standards; some features like networking may be 87supported in the future. 88 89For Python in the browser, users should consider `Pyodide`_ or `PyScript`_. 90PyScript is built on top of Pyodide, which itself is built on top of 91CPython and Emscripten. Pyodide provides access to browsers' JavaScript and 92DOM 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/ 122