Foundations of Python Network Programming

Update 9/23/2004: There is now a page for this book on my homepage, Complete.Org.

My latest book, Foundations of Python Network Programming, is now available for purchase (Amazon, bn, AllDirect, This book is designed to show you everything from fundamentals of networking and low-level protocol design to work with higher-level protocols such as IMAP, HTTP, and FTP. For more information, please see the letter to the reader from the book’s back cover.

This is not a basic reference like Python comes with. Rather, it’s a hands-on guide. There are over 6600 lines of example code and the text strives to show you the big picture. For instance, there are several different ways of getting directory information from an FTP server, and some are not documented for use this way. The chapter on FTP explains them and provides example code to illustrate. There’s also an Apress page with details.

Below is the book’s Table of Contents along with a partial list of the examples you’ll find in each chapter:

  • Part I: Low-Level Networking
    • Chapter 1: Introduction to Client/Server Networking
      Provides basic concepts of TCP/IP networking for those new to it. Examples include very basic versions of: Gopher client, URL downloading program.
    • Chapter 2: Network Clients
      Constructing basic network clients: setting up sockets, connecting to servers, sending/receiving data, handling errors. Covers TCP and UDP. Examples include: connecting to servers, error handling, obtaining the exact current time from a UDP network time server.
    • Chapter 3: Network Servers
      Constructing basic network servers: binding to a port, listening, handling connections, logging, socket options, inetd servers. Handling multiple simultaneous connections is covered in Part VI. Examples include: TCP and UDP echo servers, TCP echo client, TCP and UDP inetd servers.
    • Chapter 4: DNS
      Advanced DNS topics: reverse lookups, advanced forward lookups, information about the local system. Examples include various DNS query and lookup utilities.
    • Chapter 5: Advanced Network Operations
      Advanced network topics that are usually applicable to both client and servers: half-open sockets, timeouts, network byte order, broadcasts, IPv6. Examples include: UDP broadcast sending and receiving programs, binding to specific interfaces, IPv6 HTTP client, network byte order example, cross-protocol DNS lookups.
  • Part II: Web Services
    • Chapter 6: HTTP
      Obtaining documents from a Web server. Examples include: obtaining information from headers, submitting GET and POST forms, handling errors, and dumping pages.
    • Chapter 7: HTML
      Parsing HTML documents. Examples include: basic parsing, obtaining the weather forecast for a region.
    • Chapter 8: XML and XML-RPC
      Handling XML documents and communicating with XML-RPC servers. Examples include: DOM tree parsing and mainpulation, XML-RPC news reader, interactive XML-RPC introspection client.
  • Part III: E-Mail
    • Chapter 9: Message Composition and Decoding
      Generating message headers and bodies. Using MIME to represent attachments, data encodings, header languages, etc. Examples include: date parsing, MIME decoding, attachments, multipart messages, header generation and parsing, MIME and non-MIME generation.
    • Chapter 10: SMTP
      Using the Simple Mail Transfer Protocol to transmit messages to remote servers. Covers topics such as establishing a connection, authentication, SSL/TLS, setting recipients, etc. Examples include: mail transmission program, TLS support.
    • Chapter 11: POP3
      Downloading mail using the simple POP3 protocol. Examples include: mailbox information, download messages, delete messages.
    • Chapter 12: IMAP
      A detailed look at the IMAP protocol, including basic connections, authentication methods, folder lists and selection, message searching, flag handling, message retrieval, message storage and copying, and UID handling. Presents the Twisted IMAP4Client library and a brief coverage of the built-in imaplib. Examples include: error handling, uploading messages, downloading messages, deleting messages, message structure, searching, more.
  • Part IV: General-Purpose Client Protocols
    • Chapter 13: FTP
      Using the popular protocol to transfer files, get directory listings, discover information about remote files, handle passive mode connects. Examples include: a basic recursive-download FTP client, directory parsing.
    • Chapter 14: Database Clients
      Using Python’s DB-API 2.0 to connect to database servers. Provides general DB-API background and specific examples using MySQL and PostgreSQL, and the zxJDBC connector. Examples include: connecting, querying, various ways of accessing the result set.
    • Chapter 15: SSL/TLS
      Provides a primer on the potential attacks network programs can face and ways to help reduce them by using SSL. Covers the standard socket.ssl in Python and the more powerful PyOpenSSL. Includes coverage and example code to implement key/certificate verification. Examples include: basic use of the libraries, verification.
  • Part V: Server-Side Frameworks
    • Chapter 16: SocketServer
      Covers this basic infrastructure for writing TCP servers. Includes coverage of BaseHTTPServer and CGIHTTPServer as well as the mix-in classes for forking and threading. Examples include: time server, IPv6 support, HTTP servers.
    • Chapter 17: SimpleXMLRPCServer
      Shows how to write your own XML-RPC server and interface it to new or existing code. Also covers derivitaves of SimpleXMLRPCServer. Examples include: math server, introspection support.
    • Chapter 18: CGI Library
      Explains how CGI fits in with a Web server, covering escaping, form processing, cookie handling, and document generation. Examples include: interactive quiz program, environment.
    • Chapter 19: mod_python
      This Apache module embeds a Python interpreter into the web server. It can be used not just to accelerate dynamic Web sites but also to customize the behavior of Apache itself. Examples include: interactive quiz program, escaping, versatile dispatching system.
  • Part VI: Multitasking
    • Chapter 20: Forking
      Covers the use of forking on Unix platforms under Python. Describes the mechanics of forking, different ways to handle dying child processes, error handling, locking, performance, and implications for server authors. Examples include: echo server, zombie process examples.
    • Chapter 21: Threading
      Covers the use of threading on multiple supported Python platforms. Describes the mechanics of threading, error handling, locking, performance, and implications for server authors. Examples include: echo server, semaphores, thread pools, multi-threaded client.
    • Chapter 22: Non-Blocking Sockets
      Covers the use of poll() to achieve the appearance of a multitasking server without using either forking or threading. It goes on to cover the higher-level Twisted libraries. Examples include: echo server, an inetd server, chat server.

10 thoughts on “Foundations of Python Network Programming

  1. Hi Sathya,

    I did some quick checking, but as far as I can tell, APress doesn’t have an agent specifically in India.

    However, I suspect that you could get reasonable rates from the United Kingdom Amazon store. Try their page for this book.

    APress’ international distributor is Springer-Verlag. You might also check out their site.

    If you still have trouble, let me know, and I can try to do some more digging.

  2. I’m surprised by the dearth of positive feedback in this forum so I really should add my two bobs worth. I have been finding this to be a thoroughly enjoyable book. It is well laid out, well written and provides clear and cogent examples and explanations.

    Excuse the reification, but I give this one 9 out of 10 (only because I have yet to get all the way through it)

    Keep it up!

  3. I am in the middle of your book and I’m very impressed.
    Great book!
    Do you have any plans for the second release based on Python 3 ? Thanks.

  4. Hi
    I am new to python and have worked with C and Linux.
    I just want to know whether this book is for those who has significant experience in Python.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.