Python 標準ライブラリ
*********************

Python 言語リファレンス ではプログラミング言語 Python の厳密な構文とセ
マンティクスについて説明されていますが、このライブラリリファレンスマニ
ュアルでは Python とともに配付されている標準ライブラリについて説明しま
す。また Python 配布物に収められていることの多いオプションのコンポーネ
ントについても説明します。

Python の標準ライブラリはとても拡張性があり、下の長い目次のリストで判
るように幅広いものを用意しています。このライブラリには、例えばファイル
I/O のように、Python プログラマが直接アクセスできないシステム機能への
アクセス機能を提供する (Cで書かれた) 組み込みモジュールや、日々のプロ
グラミングで生じる多くの問題に標準的な解決策を提供するPython で書かれ
たモジュールが入っています。これら数多くのモジュールには、プラットフォ
ーム固有の事情をプラットフォーム独立な API へと昇華させることにより、
Pythonプログラムに移植性を持たせ、それを高めるという明確な意図がありま
す。

Windows 向けの Python インストーラはたいてい標準ライブラリのすべてを含
み、しばしばそれ以外の追加のコンポーネントも含んでいます。Unix 系のオ
ペレーティングシステムの場合は Python は一揃いのパッケージとして提供さ
れるのが普通で、オプションのコンポーネントを手に入れるにはオペレーティ
ングシステムのパッケージツールを使うことになるでしょう。

標準ライブラリに加えて、数10万のコンポーネントが (独立したプログラムや
モジュールからパッケージ、アプリケーション開発フレームワークまで) 活動
しているコレクションとしてPython Package Index から入手可能です。

* はじめに

  * 利用可能性について

* 組み込み関数

* 組み込み定数

  * "site" モジュールで追加される定数

* 組み込み型

  * 真理値判定

  * ブール演算 --- "and", "or", "not"

  * 比較

  * 数値型 "int", "float", "complex"

  * イテレータ型

  * シーケンス型 --- "list", "tuple", "range"

  * テキストシーケンス型 --- "str"

  * バイナリシーケンス型 --- "bytes", "bytearray", "memoryview"

  * set（集合）型 --- "set", "frozenset"

  * マッピング型 --- "dict"

  * コンテキストマネージャ型

  * 型アノテーション型 --- *ジェネリックエイリアス* 、 *ユニオン*

  * その他の組み込み型

  * 特殊属性

  * 整数と文字列の変換での長さ制限

* 組み込み例外

  * 例外コンテキスト

  * 組み込み例外から継承する

  * 基底クラス

  * 具象例外

  * 警告

  * 例外グループ

  * 例外のクラス階層

* テキスト処理サービス

  * "string" --- Common string operations

  * "re" --- Regular expression operations

  * "difflib" --- Helpers for computing deltas

  * "textwrap" --- Text wrapping and filling

  * "unicodedata" --- Unicode Database

  * "stringprep" --- Internet String Preparation

  * "readline" --- GNU readline interface

  * "rlcompleter" --- Completion function for GNU readline

* バイナリデータ処理

  * "struct" --- Interpret bytes as packed binary data

  * "codecs" --- Codec registry and base classes

* データ型

  * "datetime" --- Basic date and time types

  * "zoneinfo" --- IANA time zone support

  * "calendar" --- General calendar-related functions

  * "collections" --- Container datatypes

  * "collections.abc" --- Abstract Base Classes for Containers

  * "heapq" --- Heap queue algorithm

  * "bisect" --- Array bisection algorithm

  * "array" --- Efficient arrays of numeric values

  * "weakref" --- 弱参照

  * "types" --- Dynamic type creation and names for built-in types

  * "copy" --- Shallow and deep copy operations

  * "pprint" --- Data pretty printer

  * "reprlib" --- Alternate "repr()" implementation

  * "enum" --- Support for enumerations

  * "graphlib" --- Functionality to operate with graph-like structures

* 数値と数学モジュール

  * "numbers" --- Numeric abstract base classes

  * "math" --- Mathematical functions

  * "cmath" --- Mathematical functions for complex numbers

  * "decimal" --- Decimal fixed point and floating point arithmetic

  * "fractions" --- Rational numbers

  * "random" --- Generate pseudo-random numbers

  * "statistics" --- Mathematical statistics functions

* 関数型プログラミング用モジュール

  * "itertools" --- Functions creating iterators for efficient looping

  * "functools" --- Higher-order functions and operations on callable
    objects

  * "operator" --- Standard operators as functions

* ファイルとディレクトリへのアクセス

  * "pathlib" --- Object-oriented filesystem paths

  * "os.path" --- Common pathname manipulations

  * "fileinput" --- Iterate over lines from multiple input streams

  * "stat" --- Interpreting "stat()" results

  * "filecmp" --- File and Directory Comparisons

  * "tempfile" --- Generate temporary files and directories

  * "glob" --- Unix style pathname pattern expansion

  * "fnmatch" --- Unix filename pattern matching

  * "linecache" --- Random access to text lines

  * "shutil" --- High-level file operations

* データの永続化

  * "pickle" --- Python object serialization

  * "copyreg" --- Register "pickle" support functions

  * "shelve" --- Python object persistence

  * "marshal" --- Internal Python object serialization

  * "dbm" --- Interfaces to Unix "databases"

  * "sqlite3" --- DB-API 2.0 interface for SQLite databases

* データ圧縮とアーカイブ

  * "zlib" --- Compression compatible with **gzip**

  * "gzip" --- Support for **gzip** files

  * "bz2" --- Support for **bzip2** compression

  * "lzma" --- Compression using the LZMA algorithm

  * "zipfile" --- Work with ZIP archives

  * "tarfile" --- Read and write tar archive files

* ファイルフォーマット

  * "csv" --- CSV File Reading and Writing

  * "configparser" --- Configuration file parser

  * "tomllib" --- Parse TOML files

  * "netrc" --- netrc file processing

  * "plistlib" --- Generate and parse Apple ".plist" files

* 暗号関連のサービス

  * "hashlib" --- Secure hashes and message digests

  * "hmac" --- Keyed-Hashing for Message Authentication

  * "secrets" --- Generate secure random numbers for managing secrets

* 汎用オペレーティングシステムサービス

  * "os" --- Miscellaneous operating system interfaces

  * "io" --- Core tools for working with streams

  * "time" --- Time access and conversions

  * "argparse" --- Parser for command-line options, arguments and sub-
    commands

  * "getopt" --- C-style parser for command line options

  * "logging" --- Logging facility for Python

  * "logging.config" --- Logging configuration

  * "logging.handlers" --- Logging handlers

  * "getpass" --- Portable password input

  * "curses" --- Terminal handling for character-cell displays

  * "curses.textpad" --- curses プログラムのためのテキスト入力ウィジェ
    ット

  * "curses.ascii" --- Utilities for ASCII characters

  * "curses.panel" --- A panel stack extension for curses

  * "platform" ---  Access to underlying platform's identifying data

  * "errno" --- Standard errno system symbols

  * "ctypes" --- A foreign function library for Python

* 並行実行

  * "threading" --- Thread-based parallelism

  * "multiprocessing" --- Process-based parallelism

  * "multiprocessing.shared_memory" --- Shared memory for direct
    access across processes

  * "concurrent" パッケージ

  * "concurrent.futures" --- Launching parallel tasks

  * "subprocess" --- Subprocess management

  * "sched" --- Event scheduler

  * "queue" --- A synchronized queue class

  * "contextvars" --- Context Variables

  * "_thread" --- Low-level threading API

* ネットワーク通信とプロセス間通信

  * "asyncio" --- Asynchronous I/O

  * "socket" --- Low-level networking interface

  * "ssl" --- TLS/SSL wrapper for socket objects

  * "select" --- Waiting for I/O completion

  * "selectors" --- High-level I/O multiplexing

  * "signal" --- Set handlers for asynchronous events

  * "mmap" --- Memory-mapped file support

* インターネット上のデータの操作

  * "email" --- An email and MIME handling package

  * "json" --- JSON encoder and decoder

  * "mailbox" --- Manipulate mailboxes in various formats

  * "mimetypes" --- Map filenames to MIME types

  * "base64" --- Base16, Base32, Base64, Base85 Data Encodings

  * "binascii" --- Convert between binary and ASCII

  * "quopri" --- Encode and decode MIME quoted-printable data

* 構造化マークアップツール

  * "html" --- HyperText Markup Language support

  * "html.parser" --- Simple HTML and XHTML parser

  * "html.entities" --- Definitions of HTML general entities

  * XMLを扱うモジュール群

  * "xml.etree.ElementTree" --- The ElementTree XML API

  * "xml.dom" --- The Document Object Model API

  * "xml.dom.minidom" --- Minimal DOM implementation

  * "xml.dom.pulldom" --- Support for building partial DOM trees

  * "xml.sax" --- Support for SAX2 parsers

  * "xml.sax.handler" --- Base classes for SAX handlers

  * "xml.sax.saxutils" --- SAX Utilities

  * "xml.sax.xmlreader" --- Interface for XML parsers

  * "xml.parsers.expat" --- Fast XML parsing using Expat

* インターネットプロトコルとサポート

  * "webbrowser" --- Convenient web-browser controller

  * "wsgiref" --- WSGI Utilities and Reference Implementation

  * "urllib" --- URL handling modules

  * "urllib.request" --- Extensible library for opening URLs

  * "urllib.response" --- urllib で使用するレスポンスクラス

  * "urllib.parse" --- Parse URLs into components

  * "urllib.error" --- Exception classes raised by urllib.request

  * "urllib.robotparser" ---  Parser for robots.txt

  * "http" --- HTTP modules

  * "http.client" --- HTTP protocol client

  * "ftplib" --- FTP protocol client

  * "poplib" --- POP3 protocol client

  * "imaplib" --- IMAP4 protocol client

  * "smtplib" --- SMTP protocol client

  * "uuid" --- UUID objects according to **RFC 4122**

  * "socketserver" --- A framework for network servers

  * "http.server" --- HTTP servers

  * "http.cookies" --- HTTP state management

  * "http.cookiejar" --- Cookie handling for HTTP clients

  * "xmlrpc" --- XMLRPC サーバーとクライアントモジュール群

  * "xmlrpc.client" --- XML-RPC client access

  * "xmlrpc.server" --- Basic XML-RPC servers

  * "ipaddress" --- IPv4/IPv6 manipulation library

* マルチメディアサービス

  * "wave" --- Read and write WAV files

  * "colorsys" --- Conversions between color systems

* 国際化

  * "gettext" --- Multilingual internationalization services

  * "locale" --- Internationalization services

* プログラムのフレームワーク

  * "turtle" --- Turtle graphics

  * "cmd" --- Support for line-oriented command interpreters

  * "shlex" --- Simple lexical analysis

* Tk を用いたグラフィカルユーザーインターフェース

  * "tkinter" --- Python interface to Tcl/Tk

  * "tkinter.colorchooser" --- Color choosing dialog

  * "tkinter.font" --- Tkinter font wrapper

  * Tkinter ダイアログ

  * "tkinter.messagebox" --- Tkinter message prompts

  * "tkinter.scrolledtext" --- Scrolled Text Widget

  * "tkinter.dnd" --- Drag and drop support

  * "tkinter.ttk" --- Tk themed widgets

  * "tkinter.tix" --- Tkの拡張ウィジェット

  * IDLE

* 開発ツール

  * "typing" --- Support for type hints

  * "pydoc" --- Documentation generator and online help system

  * Python 開発モード

  * "doctest" --- Test interactive Python examples

  * "unittest" --- Unit testing framework

  * "unittest.mock" --- mock object library

  * "unittest.mock" --- getting started

  * 2to3 --- Python 2 から 3 への自動コード変換

  * "test" --- Regression tests package for Python

  * "test.support" --- テストのためのユーティリティ関数

  * "test.support.socket_helper" --- Utilities for socket tests

  * "test.support.script_helper" --- Utilities for the Python
    execution tests

  * "test.support.bytecode_helper" --- Support tools for testing
    correct bytecode generation

  * "test.support.threading_helper" --- Utilities for threading tests

  * "test.support.os_helper" --- Utilities for os tests

  * "test.support.import_helper" --- Utilities for import tests

  * "test.support.warnings_helper" --- Utilities for warnings tests

* デバッグとプロファイル

  * 監査イベント表

  * "bdb" --- Debugger framework

  * "faulthandler" --- Dump the Python traceback

  * "pdb" --- Python デバッガ

  * Python プロファイラ

  * "timeit" --- Measure execution time of small code snippets

  * "trace" --- Trace or track Python statement execution

  * "tracemalloc" --- Trace memory allocations

* ソフトウェア・パッケージと配布

  * "distutils" --- Building and installing Python modules

  * "ensurepip" --- Bootstrapping the "pip" installer

  * "venv" --- Creation of virtual environments

  * "zipapp" --- Manage executable Python zip archives

* Python ランタイムサービス

  * "sys" --- System-specific parameters and functions

  * "sysconfig" --- Provide access to Python's configuration
    information

  * "builtins" --- Built-in objects

  * "__main__" --- Top-level code environment

  * "warnings" --- Warning control

  * "dataclasses" --- データクラス

  * "contextlib" --- "with" 文コンテキスト用ユーティリティ

  * "abc" --- Abstract Base Classes

  * "atexit" --- Exit handlers

  * "traceback" --- Print or retrieve a stack traceback

  * "__future__" --- Future statement definitions

  * "gc" --- Garbage Collector interface

  * "inspect" --- Inspect live objects

  * "site" --- Site-specific configuration hook

* カスタム Python インタプリタ

  * "code" --- Interpreter base classes

  * "codeop" --- Compile Python code

* モジュールのインポート

  * "zipimport" --- Import modules from Zip archives

  * "pkgutil" --- Package extension utility

  * "modulefinder" --- Find modules used by a script

  * "runpy" --- Locating and executing Python modules

  * "importlib" --- "import" の実装

  * "importlib.resources" -- Package resource reading, opening and
    access

  * "importlib.resources.abc" -- Abstract base classes for resources

  * "importlib.metadata" -- パッケージメタデータへのアクセス

  * "sys.path" モジュール検索パスの初期化

* Python言語サービス

  * "ast" --- Abstract Syntax Trees

  * "symtable" --- Access to the compiler's symbol tables

  * "token" --- Constants used with Python parse trees

  * "keyword" --- Testing for Python keywords

  * "tokenize" --- Tokenizer for Python source

  * "tabnanny" --- Detection of ambiguous indentation

  * "pyclbr" --- Python module browser support

  * "py_compile" --- Compile Python source files

  * "compileall" --- Byte-compile Python libraries

  * "dis" --- Disassembler for Python bytecode

  * "pickletools" --- Tools for pickle developers

* MS Windows 固有のサービス

  * "msvcrt" --- Useful routines from the MS VC++ runtime

  * "winreg" --- Windows registry access

  * "winsound" --- Sound-playing interface for Windows

* Unix 固有のサービス

  * "posix" --- The most common POSIX system calls

  * "pwd" --- The password database

  * "grp" --- The group database

  * "termios" --- POSIX style tty control

  * "tty" --- Terminal control functions

  * "pty" --- Pseudo-terminal utilities

  * "fcntl" --- The "fcntl" and "ioctl" system calls

  * "resource" --- Resource usage information

  * "syslog" --- Unix syslog library routines

* モジュールのコマンドラインインターフェース (CLI)

* 取って代わられたモジュール群

  * "aifc" --- Read and write AIFF and AIFC files

  * "asynchat" --- Asynchronous socket command/response handler

  * "asyncore" --- Asynchronous socket handler

  * "audioop" --- Manipulate raw audio data

  * "cgi" --- Common Gateway Interface support

  * "cgitb" --- Traceback manager for CGI scripts

  * "chunk" --- Read IFF chunked data

  * "crypt" --- Function to check Unix passwords

  * "imghdr" --- Determine the type of an image

  * "imp" --- Access the *import* internals

  * "mailcap" --- Mailcap file handling

  * "msilib" --- Read and write Microsoft Installer files

  * "nis" --- Interface to Sun's NIS (Yellow Pages)

  * "nntplib" --- NNTP protocol client

  * "optparse" --- Parser for command line options

  * "ossaudiodev" --- Access to OSS-compatible audio devices

  * "pipes" --- Interface to shell pipelines

  * "smtpd" --- SMTP Server

  * "sndhdr" --- Determine type of sound file

  * "spwd" --- The shadow password database

  * "sunau" --- Read and write Sun AU files

  * "telnetlib" --- Telnet client

  * "uu" --- Encode and decode uuencode files

  * "xdrlib" --- Encode and decode XDR data

* セキュリティで考慮すべき点
