知方号

知方号

The Python Standard Library

The Python Standard Library¶

While The Python Language Reference describes the exact syntax andsemantics of the Python language, this library reference manualdescribes the standard library that is distributed with Python. It alsodescribes some of the optional components that are commonly includedin Python distributions.

Python’s standard library is very extensive, offering a wide range offacilities as indicated by the long table of contents listed below. Thelibrary contains built-in modules (written in C) that provide access tosystem functionality such as file I/O that would otherwise beinaccessible to Python programmers, as well as modules written in Pythonthat provide standardized solutions for many problems that occur ineveryday programming. Some of these modules are explicitly designed toencourage and enhance the portability of Python programs by abstractingaway platform-specifics into platform-neutral APIs.

The Python installers for the Windows platform usually includethe entire standard library and often also include many additionalcomponents. For Unix-like operating systems Python is normally providedas a collection of packages, so it may be necessary to use the packagingtools provided with the operating system to obtain some or all of theoptional components.

In addition to the standard library, there is an active collection ofhundreds of thousands of components (from individual programs and modules topackages and entire application development frameworks), available fromthe Python Package Index.

IntroductionNotes on availabilityBuilt-in FunctionsBuilt-in ConstantsConstants added by the site moduleBuilt-in TypesTruth Value TestingBoolean Operations — and, or, notComparisonsNumeric Types — int, float, complexBoolean Type - boolIterator TypesSequence Types — list, tuple, rangeText Sequence Type — strBinary Sequence Types — bytes, bytearray, memoryviewSet Types — set, frozensetMapping Types — dictContext Manager TypesType Annotation Types — Generic Alias, UnionOther Built-in TypesSpecial AttributesInteger string conversion length limitationBuilt-in ExceptionsException contextInheriting from built-in exceptionsBase classesConcrete exceptionsWarningsException groupsException hierarchyText Processing Servicesstring — Common string operationsre — Regular expression operationsdifflib — Helpers for computing deltastextwrap — Text wrapping and fillingunicodedata — Unicode Databasestringprep — Internet String Preparationreadline — GNU readline interfacerlcompleter — Completion function for GNU readlineBinary Data Servicesstruct — Interpret bytes as packed binary datacodecs — Codec registry and base classesData Typesdatetime — Basic date and time typeszoneinfo — IANA time zone supportcalendar — General calendar-related functionscollections — Container datatypescollections.abc — Abstract Base Classes for Containersheapq — Heap queue algorithmbisect — Array bisection algorithmarray — Efficient arrays of numeric valuesweakref — Weak referencestypes — Dynamic type creation and names for built-in typescopy — Shallow and deep copy operationspprint — Data pretty printerreprlib — Alternate repr() implementationenum — Support for enumerationsgraphlib — Functionality to operate with graph-like structuresNumeric and Mathematical Modulesnumbers — Numeric abstract base classesmath — Mathematical functionscmath — Mathematical functions for complex numbersdecimal — Decimal fixed-point and floating-point arithmeticfractions — Rational numbersrandom — Generate pseudo-random numbersstatistics — Mathematical statistics functionsFunctional Programming Modulesitertools — Functions creating iterators for efficient loopingfunctools — Higher-order functions and operations on callable objectsoperator — Standard operators as functionsFile and Directory Accesspathlib — Object-oriented filesystem pathsos.path — Common pathname manipulationsfileinput — Iterate over lines from multiple input streamsstat — Interpreting stat() resultsfilecmp — File and Directory Comparisonstempfile — Generate temporary files and directoriesglob — Unix style pathname pattern expansionfnmatch — Unix filename pattern matchinglinecache — Random access to text linesshutil — High-level file operationsData Persistencepickle — Python object serializationcopyreg — Register pickle support functionsshelve — Python object persistencemarshal — Internal Python object serializationdbm — Interfaces to Unix “databases”sqlite3 — DB-API 2.0 interface for SQLite databasesData Compression and Archivingzlib — Compression compatible with gzipgzip — Support for gzip filesbz2 — Support for bzip2 compressionlzma — Compression using the LZMA algorithmzipfile — Work with ZIP archivestarfile — Read and write tar archive filesFile Formatscsv — CSV File Reading and Writingconfigparser — Configuration file parsertomllib — Parse TOML filesnetrc — netrc file processingplistlib — Generate and parse Apple .plist filesCryptographic Serviceshashlib — Secure hashes and message digestshmac — Keyed-Hashing for Message Authenticationsecrets — Generate secure random numbers for managing secretsGeneric Operating System Servicesos — Miscellaneous operating system interfacesio — Core tools for working with streamstime — Time access and conversionsargparse — Parser for command-line options, arguments and subcommandslogging — Logging facility for Pythonlogging.config — Logging configurationlogging.handlers — Logging handlersgetpass — Portable password inputcurses — Terminal handling for character-cell displayscurses.textpad — Text input widget for curses programscurses.ascii — Utilities for ASCII characterscurses.panel — A panel stack extension for cursesplatform — Access to underlying platform’s identifying dataerrno — Standard errno system symbolsctypes — A foreign function library for PythonConcurrent Executionthreading — Thread-based parallelismmultiprocessing — Process-based parallelismmultiprocessing.shared_memory — Shared memory for direct access across processesThe concurrent packageconcurrent.futures — Launching parallel taskssubprocess — Subprocess managementsched — Event schedulerqueue — A synchronized queue classcontextvars — Context Variables_thread — Low-level threading APINetworking and Interprocess Communicationasyncio — Asynchronous I/Osocket — Low-level networking interfacessl — TLS/SSL wrapper for socket objectsselect — Waiting for I/O completionselectors — High-level I/O multiplexingsignal — Set handlers for asynchronous eventsmmap — Memory-mapped file supportInternet Data Handlingemail — An email and MIME handling packagejson — JSON encoder and decodermailbox — Manipulate mailboxes in various formatsmimetypes — Map filenames to MIME typesbase64 — Base16, Base32, Base64, Base85 Data Encodingsbinascii — Convert between binary and ASCIIquopri — Encode and decode MIME quoted-printable dataStructured Markup Processing Toolshtml — HyperText Markup Language supporthtml.parser — Simple HTML and XHTML parserhtml.entities — Definitions of HTML general entitiesXML Processing Modulesxml.etree.ElementTree — The ElementTree XML APIxml.dom — The Document Object Model APIxml.dom.minidom — Minimal DOM implementationxml.dom.pulldom — Support for building partial DOM treesxml.sax — Support for SAX2 parsersxml.sax.handler — Base classes for SAX handlersxml.sax.saxutils — SAX Utilitiesxml.sax.xmlreader — Interface for XML parsersxml.parsers.expat — Fast XML parsing using ExpatInternet Protocols and Supportwebbrowser — Convenient web-browser controllerwsgiref — WSGI Utilities and Reference Implementationurllib — URL handling modulesurllib.request — Extensible library for opening URLsurllib.response — Response classes used by urlliburllib.parse — Parse URLs into componentsurllib.error — Exception classes raised by urllib.requesturllib.robotparser — Parser for robots.txthttp — HTTP moduleshttp.client — HTTP protocol clientftplib — FTP protocol clientpoplib — POP3 protocol clientimaplib — IMAP4 protocol clientsmtplib — SMTP protocol clientuuid — UUID objects according to RFC 4122socketserver — A framework for network servershttp.server — HTTP servershttp.cookies — HTTP state managementhttp.cookiejar — Cookie handling for HTTP clientsxmlrpc — XMLRPC server and client modulesxmlrpc.client — XML-RPC client accessxmlrpc.server — Basic XML-RPC serversipaddress — IPv4/IPv6 manipulation libraryMultimedia Serviceswave — Read and write WAV filescolorsys — Conversions between color systemsInternationalizationgettext — Multilingual internationalization serviceslocale — Internationalization servicesProgram Frameworksturtle — Turtle graphicscmd — Support for line-oriented command interpretersshlex — Simple lexical analysisGraphical User Interfaces with Tktkinter — Python interface to Tcl/Tktkinter.colorchooser — Color choosing dialogtkinter.font — Tkinter font wrapperTkinter Dialogstkinter.messagebox — Tkinter message promptstkinter.scrolledtext — Scrolled Text Widgettkinter.dnd — Drag and drop supporttkinter.ttk — Tk themed widgetsIDLEDevelopment Toolstyping — Support for type hintspydoc — Documentation generator and online help systemPython Development Modedoctest — Test interactive Python examplesunittest — Unit testing frameworkunittest.mock — mock object libraryunittest.mock — getting startedtest — Regression tests package for Pythontest.support — Utilities for the Python test suitetest.support.socket_helper — Utilities for socket teststest.support.script_helper — Utilities for the Python execution teststest.support.bytecode_helper — Support tools for testing correct bytecode generationtest.support.threading_helper — Utilities for threading teststest.support.os_helper — Utilities for os teststest.support.import_helper — Utilities for import teststest.support.warnings_helper — Utilities for warnings testsDebugging and ProfilingAudit events tablebdb — Debugger frameworkfaulthandler — Dump the Python tracebackpdb — The Python DebuggerThe Python Profilerstimeit — Measure execution time of small code snippetstrace — Trace or track Python statement executiontracemalloc — Trace memory allocationsSoftware Packaging and Distributionensurepip — Bootstrapping the pip installervenv — Creation of virtual environmentszipapp — Manage executable Python zip archivesPython Runtime Servicessys — System-specific parameters and functionssys.monitoring — Execution event monitoringsysconfig — Provide access to Python’s configuration informationbuiltins — Built-in objects__main__ — Top-level code environmentwarnings — Warning controldataclasses — Data Classescontextlib — Utilities for with-statement contextsabc — Abstract Base Classesatexit — Exit handlerstraceback — Print or retrieve a stack traceback__future__ — Future statement definitionsgc — Garbage Collector interfaceinspect — Inspect live objectssite — Site-specific configuration hookCustom Python Interpreterscode — Interpreter base classescodeop — Compile Python codeImporting Moduleszipimport — Import modules from Zip archivespkgutil — Package extension utilitymodulefinder — Find modules used by a scriptrunpy — Locating and executing Python modulesimportlib — The implementation of importimportlib.resources – Package resource reading, opening and accessimportlib.resources.abc – Abstract base classes for resourcesimportlib.metadata – Accessing package metadataThe initialization of the sys.path module search pathPython Language Servicesast — Abstract Syntax Treessymtable — Access to the compiler’s symbol tablestoken — Constants used with Python parse treeskeyword — Testing for Python keywordstokenize — Tokenizer for Python sourcetabnanny — Detection of ambiguous indentationpyclbr — Python module browser supportpy_compile — Compile Python source filescompileall — Byte-compile Python librariesdis — Disassembler for Python bytecodepickletools — Tools for pickle developersMS Windows Specific Servicesmsvcrt — Useful routines from the MS VC++ runtimewinreg — Windows registry accesswinsound — Sound-playing interface for WindowsUnix Specific Servicesposix — The most common POSIX system callspwd — The password databasegrp — The group databasetermios — POSIX style tty controltty — Terminal control functionspty — Pseudo-terminal utilitiesfcntl — The fcntl and ioctl system callsresource — Resource usage informationsyslog — Unix syslog library routinesModules command-line interface (CLI)Superseded Modulesgetopt — C-style parser for command line optionsoptparse — Parser for command line optionsSecurity Considerations

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。