Giriş

The Python standard library consists of a collection of modules. There are many ways to dissect this collection. Most modules are written in Python, but some are written in C. All can be imported into your program to add functionality. Some modules provide interfaces that are highly specific to Python, like printing a stack trace; some provide interfaces that are specific to particular operating systems, such as access to specific hardware; others provide interfaces that are specific to a particular application domain, like web development. Some modules are available in all versions and ports of Python; others are only available when the underlying system supports or requires them; yet others are available only when a particular configuration option was chosen at the time when Python was compiled and installed.

If you start reading this manual from the start, and skip to the next chapter when you get bored, you will get a reasonable overview of the available modules and application areas that are supported by the Python library. Of course, you don’t have to read it like a novel — you can also browse the table of contents (in front of the manual), or look for a specific function, module or term in the index (in the back). And finally, if you enjoy learning about random subjects, you choose a random page and read a section or two. Regardless of the order in which you read the sections of this manual, it helps to first read Built-in Functions, as the remainder of this section assumes familiarity with this material.

Ayrıca bakınız

The built-in functions and classes (which can be used without an import statement) are described in Python built-ins reference.

Kullanılabilirlik hakkında notlar

  • “Kullanılabilirlik: Unix” notu, bu fonksiyonun Unix sistemlerinde yaygın olarak bulunduğu anlamına gelir. Belirli bir işletim sistemindeki varlığı hakkında herhangi bir iddiada bulunmaz.

  • If not separately noted, all functions that claim “Availability: Unix” are supported on macOS, iOS and Android, all of which build on a Unix core.

  • Bir kullanılabilirlik notu hem minimum Çekirdek(Kernel) sürümü hem de minimum libc sürümü içeriyorsa, her iki koşul da geçerli olmalıdır. Örneğin Availability: Linux >= 3.17 with glibc >= 2.27 notuna sahip bir özellik için hem Linux 3.17 veya daha yeni hem de glibc 2.27 veya daha yeni olması gerekir.

WebAssembly platformları

WebAssembly platformları wasm32-emscripten (Emscripten) ve wasm32-wasi (WASI) POSIX API`lerinin bir alt kümesini sağlar. WebAssembly çalışma zamanları ve tarayıcıları korumalıdır ve ana bilgisayara ve harici kaynaklara sınırlı erişime sahiptir. Süreçler, iş parçacığı, ağ, sinyaller veya diğer süreçler arası iletişim (IPC) biçimlerini kullanan herhangi bir Python standart kütüphane modülü ya mevcut değildir ya da diğer Unix benzeri sistemlerde olduğu gibi çalışmayabilir. Dosya I/O, dosya sistemi ve Unix izinleriyle ilgili işlevler de kısıtlanmıştır. Emscripten bloklama I/O’ye izin vermez. sleep() gibi diğer engelleme işlemleri tarayıcı olay döngüsünü engeller.

Python’un WebAssembly platformlarındaki özellikleri ve davranışı Emscripten-SDK veya WASI-SDK sürümüne, WASM çalışma zamanlarına (tarayıcı, NodeJS, wasmtime) ve Python derleme zamanı bayraklarına(build time flags) bağlıdır. WebAssembly, Emscripten ve WASI gelişmekte olan standartlardır; ağ oluşturma gibi bazı özellikler gelecekte desteklenebilir.

Tarayıcıda Python için kullanıcılar Pyodide veya PyScript’i düşünmelidir. PyScript, kendisi de CPython ve Emscripten üzerine inşa edilmiş olan Pyodide üzerine kurulmuştur. Pyodide, tarayıcıların JavaScript ve DOM API’lerine erişimin yanı sıra JavaScript’in XMLHttpRequest ve Fetch API’leri ile sınırlı ağ yetenekleri sağlar.

  • Süreçle ilgili API’ler kullanılamaz veya her zaman bir hata ile başarısız olur. Bu, yeni süreçler oluşturan (fork(), execve()), süreçleri bekleyen (waitpid()), sinyal gönderen (kill()) veya süreçlerle başka şekilde etkileşime giren API’leri içerir. subprocess içe aktarılabilir ancak çalışmaz.

  • socket modülü mevcuttur, ancak sınırlıdır ve diğer platformlardan farklı davranır. Emscripten üzerinde, soketler her zaman bloklama yapmaz ve WebSockets aracılığıyla TCP’yi proxy’lemek için sunucuda ek JavaScript kodu ve yardımcılar gerektirir; daha fazla bilgi için Emscripten Networking bölümüne bakın. WASI anlık görüntü önizleme 1, yalnızca mevcut bir dosya tanımlayıcısından soketlere izin verir.

  • Bazı fonksiyonlar hiçbir şey yapmayan ve her zaman sabit kodlanmış değerler döndüren taslaklardır.

  • Dosya tanımlayıcıları, dosya izinleri, dosya sahipliği ve bağlantılarla ilgili işlevler sınırlıdır ve bazı işlemleri desteklemez. Örneğin, WASI mutlak dosya adlarıyla ortak bağlantılara izin vermez.

Mobile platforms

Android and iOS are, in most respects, POSIX operating systems. File I/O, socket handling, and threading all behave as they would on any POSIX operating system. However, there are several major differences:

  • Mobile platforms can only use Python in “embedded” mode. There is no Python REPL, and no ability to use separate executables such as python or pip. To add Python code to your mobile app, you must use the Python embedding API. For more details, see Using Python on Android and Using Python on iOS.

  • Subprocesses:

    • On Android, creating subprocesses is possible but officially unsupported. In particular, Android does not support any part of the System V IPC API, so multiprocessing is not available.

    • An iOS app cannot use any form of subprocessing, multiprocessing, or inter-process communication. If an iOS app attempts to create a subprocess, the process creating the subprocess will either lock up, or crash. An iOS app has no visibility of other applications that are running, nor any ability to communicate with other running applications, outside of the iOS-specific APIs that exist for this purpose.

  • Mobile apps have limited access to modify system resources (such as the system clock). These resources will often be readable, but attempts to modify those resources will usually fail.

  • Console input and output:

    • On Android, the native stdout and stderr are not connected to anything, so Python installs its own streams which redirect messages to the system log. These can be seen under the tags python.stdout and python.stderr respectively.

    • iOS apps have a limited concept of console output. stdout and stderr exist, and content written to stdout and stderr will be visible in logs when running in Xcode, but this content won’t be recorded in the system log. If a user who has installed your app provides their app logs as a diagnostic aid, they will not include any detail written to stdout or stderr.

    • Mobile apps have no usable stdin at all. While apps can display an on-screen keyboard, this is a software feature, not something that is attached to stdin.

      As a result, Python modules that involve console manipulation (such as curses and readline) are not available on mobile platforms.