Python Common class libraries

Source: Internet
Author: User
Tags base64 glob posix shallow copy sqlite database string format system log

In addition to the keywords (keywords) and the built-in types and functions (builtins), Python provides more functionality through libraries (that is, modules).

The Common libraries (modules) are as follows:

1) Python Runtime service

* The Copy:copy module provides a shallow copy and deep copy of the composite (compound) object (List,tuple,dict,custom Class).

* The Pickle:pickle module is used to serialize Python objects to the bytes stream, making it suitable for storing to files, network transmissions, or database storage. (The pickle process is also called serializing,marshalling or flattening,pickle can also be used to deserialize the bytes stream into a Python object).

* The Sys:sys module contains variables and functions related to the Python parser and environment.

* Other: Atexit,gc,inspect,marshal,traceback,types,warnings,weakref.

2) Mathematics

* Float in Decimal:python is represented by double-precision binary floating-point encoding, which causes decimals to not be accurately represented, such as 0.1 in memory 0.100000000000000001, and 3*0.1 = = 0.3 as false. Decimal is to solve similar problems, with higher accuracy, can represent a larger range of numbers, more precisely rounded.

* The Math:math module defines standard mathematical methods such as cos (x), sin (x), and so on.

* The Random:random module provides various methods for generating random numbers.

* Other: Fractions,numbers.

3) data structures, algorithms and code simplification

* Array:array represents an array, similar to list, unlike list, where only objects of the same type can be stored.

* Bisect:bisect is an ordered list in which the internal use of dichotomy (bitsection) is used for most operations.

* The Collections:collections module contains the high performance implementations of some useful containers, abstract base classes for various containers, and functions to create name-tuple objects. For example, contains container deque,defaultdict,namedtuple and so on.

* HEAPQ:HEAPQ is a queue with a priority that is implemented using the heap.

* Itertools:itertools contains the function used to create a valid iterators. All functions return iterators or the function contains iterators (for example, generators and generators expression).

* Operator:operator provides special methods for accessing Python's built-in operations and parsers, such as x+y for Add (x, y), x+=y for Iadd (x, y), a% B for mod (b), and so on.

* Other: Abc,contextlib,functools.

4) string and text processing

The *codecs:codecs module is used to process the conversion of different character encodings with Unicode text IO.

* The Re:re module is used to match and replace strings in regular expressions.

* The String:string module contains a number of useful constants and functions for working with strings. A class that also contains the new string format.

* The Struct:struct module is used to convert between Python and binary architectures.

* Unicodedata:unicodedata module provides access to Unicode character database

5) Python Database access

* Relational databases have common specifications Python database API specification v2.0,mysql,oracle and so on have implemented this specification, and then increased their own extensions.

* The Sqlite3:sqlite3 module provides an interface for SQLite database access. The SQLite database is a self-contained relational database that exists in the form of a file or memory.

* Dbm-style Database module: Python provides a dozen modules to support UNIX Dbm-style database files. The DBM module is used to read the standard UNIX-DBM database file, GDBM is used to read the GNU dbm database file, and Dbhash is used to read Berkeley DB database files. All of these modules provide an object that implements a dictionary of string-based persistence, which is very similar to dictionary dict, but his keys and values must be strings.

* The Shelve:shelve module uses a special "shelf" object to support persistent objects. This object behaves like Dict, but all of his stored objects are stored on the hard disk using the Hashtable-based database (DBHASH,DBM,GDBM). The difference from the DBM module is that the stored object is not only a string, but can be any pickle compatible object.

6) file and directory processing

* The BZ2:BZ2 module is used to process files compressed with the BZIP2 compression algorithm.

* The FILECMP:FILECMP module provides functions to compare files and directories.

* The Fnmatch:fnmatch module provides wildcard characters using Unix shell-style to match file names. This module is just used to match, using Glob to get a list of matching files.

* The Glob:glob module returns all files that match the specified Unix shell wildcard character in a directory.

* The Gzip:gzip module provides class gzipfile to perform reads and writes of files that are compatible with Gnugzip programs.

* The Shutil:shutil module is used to perform higher level file operations such as copying, deleting, renaming. Shutil operation for general files, Pipes,block devices and other file types are not supported.

* The Tarfile:tarfile module is used to maintain the TAR archive file. The tar does not have compression capabilities.

* The Tempfile:tempfile module is used to generate temporary files and file names.

* The Zipfile:zipfile module is used to process files in zip format.

* The Zlib,zlib module provides access to the compression function of the zlib library.

7) Service of the operating system

* The Cmmands:commands module is used to execute simple system commands, which are passed in as a string and return the output of the command as a string. However, this module is only available on UNIX systems.

* The Configparser,configparser module is used to read and write to the Windows INI format configuration file.

* The Datetime,datetime module provides various types to represent and process dates and times.

* errno, defines all the errorcode corresponding to the symbolic name.

* The Io,io module implements various IO forms and built-in open () functions.

* Logging, logging module is flexible and convenient to record events,errors,warnings, and debuging information to the application. These log messages can be collected, filtered, written to a file or system log, or even sent over a network to a remote machine.

The *mmap,mmap module provides support for memory-mapped file objects, using a memory-mapped file similar to using a generic file or a byte string.

*MSVCRT,MSCRT can be used only on Windows systems to access many useful features of the Visual C run-time library.

*optparse,optparse module higher level to handle UNIX style command-line option SYS.ARGV.

* The Os,os module provides a portable (portable) interface for common operating system services. The OS can be thought of as an abstraction of NT and POSIX. NT provides a service interface for Windows, and POSIX provides a service interface for UNIX (LINUX,MAC).

* The Os.path,os.path module handles path-related operations in a portable manner.

* The Signal,signal module is used to implement signal (signal) processing, which is often associated with synchronization.

* The Subprocess,subprocess module contains functions and objects to unify the creation of new processes, control the input and output streams of new processes, and process the return of processes.

* The Time,time module provides a variety of time-related functions. Commonly used Time.sleep ().

* WinReg, the WinReg module is used to manipulate the Windows registry.

* Other: Fcntl.

8) Threading and parallel

* The Multiprocessing,multiprocessing module provides for loading multiple tasks, communicating, sharing data, and performing various synchronization operations via subprocess.

* The Threading,threading module provides a lot of synchronization methods for thread classes to achieve multithreaded programming.

* Queue,queue module realizes a variety of multi-producer, multi-consumer queue, which is used to realize the information security exchange of multi-thread.

* Other: Coroutines and microthreading.

9) network programming and sockets (Sockets)

* The Asynchat,asynchat module simplifies the application's network asynchronous processing by encapsulating the Asyncore.

* The Ssl,ssl module is used to wrap the socket object using Secure Sockets Layer (SSL), which enables data encryption and terminal authentication. Python uses OpenSSL to implement this module.

* The Socketserver,socketserver module provides a type that simplifies the implementation of socket server in the TCP,UDP and UNIX domains.

* Other: Asyncore,select.

Internet application Programming

* The Ftplib,ftplib module implements the client-side protocol for FTP. This module is rarely used because Urllib provides a more advanced interface.

* HTTP package, contains the HTTP client and server implementation and the module of the cookie management.

* Smtplib,smtplib contains the underlying interface of the SMTP client, which is used to send mail using the SMTP protocol.

* The Urllib,urllib package provides an advanced interface for the client to interact with HTTP server,ftp server and local files.

* The XMLRPC,XMLRPC module is implemented with Class XML-RPC client.

One) Web programming

* The cgi,cgi module is used to implement CGI scripts, and CGI programs are generally executed by webserver to handle the user's input in a form, or to generate some dynamic content. When the request with the CGI script is submitted, webserver executes the CGI as a subprocess, and the CGI program obtains the input through the Sys.stdin or environment variable and outputs it through the sys.stdout.

* The Webbrowser,webbrowser module provides platform-independent tool functions to open documents using the Web browser.

* Other: Wsgiref/wsgi (Python Web Server Gateway Interface).

Internet Data processing and encoding

* The Base64,base64 module provides a BASE64,BASE32,BASE16 encoding method for encoding and decoding between binary and text. Base64 is typically used to encode binary data, which is embedded in the mail or HTTP protocol.

* The BINASCII,BINASCII module provides a low-level interface for binary and various ASCII-encoded conversions.

* The Csv,csv module is used to read and write comma-separated values (CSV) files.

* The Email,email package provides a number of functions and objects to represent, parse, and maintain email messages using MIME standards.

* The Hashlib,hashlib module implements a variety of secure hash and message digest algorithms, such as MD5 and SHA1.

* Htmlparser (Html.parser), this module defines htmlparser to parse HTML and XHTML documents. With this class, you need to define your own class and inherit from Htmlparser.

* The Json,json module is serialized with class or rice to serialize JavaScript Object Notation (JSON) objects.

* The Xml,xml package provides a variety of ways to process XML.

Python Common class libraries

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.