Internet Modules and Tools
This section summarizes Python’s support for Internet scripting.
Commonly Used Library Modules
Following are summaries of some of the more commonly used modules in the Python Internet modules set. This is just a representative sample; see the Python Library Reference for a more complete list.
socketLow-level network communications support (TCP/IP, UDP, etc.). Interfaces for sending and receiving data over BSD-style sockets:
socket.socket()makes an object with socket call methods (e.g.,object.bind()). Most protocol and server modules use this module internally.socketserver(SocketServerin Python 2.X)Framework for general threading and forking network servers.
xdrlibEncodes binary data portably (also see
socketmodules earlier in this list).selectInterfaces to Unix and Windows
selectfunction. Waits for activity on one ofNfiles or sockets. Commonly used to multiplex among multiple streams or to implement timeouts. Works only for sockets on Windows, not files.cgiServer-side CGI script support:
cgi.FieldStorageparses the input stream;cgi.escapeapplies HTML escape conventions to output streams. To parse and access form information: after a CGI script callsform=cgi.FieldStorage(),formis a dictionary-like object with one entry per form field (e.g.,form["name"].valueis form fieldnametext).urllib.request(urllib,urllib2in Python 2.X)Fetches web pages and server script outputs from their Internet addresses (URLs):
urllib.request.urlopen(url)returns ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access