Download
Introduction
Welcome to the world of network programming with Python. Python is a full-featured object-oriented programming language with a standard library that includes everything needed to rapidly build powerful network applications. In addition, it has a multitude of third-party libraries and packages that extend Python to every sphere of network programming. Combined with the fun of using Python, with this book, we hope to get you started on your journey so that you master these tools and produce some great networking code.
In this book, we are squarely targeting Python 3. Although Python 3 is still establishing itself as the successor to Python 2, version 3 is the future of the language, and we want to demonstrate that it is ready for network programming prime time. It offers many improvements over the previous version, many of which improve the network programming experience, with enhanced standard library modules and new additions.
We hope you enjoy this introduction to network programming with Python
What this book covers
Chapter 1, Network Programming and Python, introduces core networking concepts for readers that are new to networking, and also covers how network programming is approached in Python.
Chapter 2, HTTP and Working with the Web, introduces you to the HTTP protocol and covers how we can retrieve and manipulate web content using Python as an HTTP client. We also take a look at the standard library urllib and third-party Requests modules.
Chapter 3, APIs in Action, introduces you to working with web APIs using HTTP. We also cover the XML and JSON data formats, and walk you through developing applications using the Amazon Web Services Simple Storage Service (S3) and Twitter APIs.
Chapter 4, Engaging with E-mails, covers the principle protocols used in sending and receiving e-mails, such as SMTP, POP3, and IMAP, and how to work with them in Python 3.
Chapter 5, Interacting with Remote Systems, guides you through the ways of using Python to connect to servers and performing common administrative tasks, including the execution of shell commands through SSH, file transfers with FTP and SMB, authentication with LDAP, and to monitor systems with SNMP.
Chapter 6, IP and DNS, discusses the details of the Internet Protocol (IP), ways of working with IP in Python, and how to use DNS to resolve hostnames.
Chapter 7, Programming with Sockets, covers using TCP and UDP sockets from Python for writing low-level network applications. We also cover HTTPS and TLS for secure data transport.
Chapter 8, Client and Server Applications, looks at writing client and server programs for socket-based communication. By writing an echo application and a chat application we look at developing basic protocols, framing network data, and compare the multithreading and event-based server architectures.
Chapter 9, Applications for the Web, introduces you to writing web applications in Python. We cover the main approaches, methods of hosting Python web applications, and develop an example application in the Flask microframework.
Appendix, Working with Wireshark, covers packet sniffers, the installation of Wireshark, and how to capture and filter packets using the Wireshark application
What you need for this book
This book is aimed at Python 3. While many of the examples will work in Python 2, you'll get the best experience working through this book with a recent version of Python 3. At the time of writing, the latest version is 3.4.3, and the examples were tested against this.
Though Python 3.4 is the preferred version, all the examples should run on Python 3.1 or later, except for the following:
• The asyncio example in Chapter 8, Client and Server Applications, as the asyncio module was only included in Version 3.4
• The Flask example in Chapter 9, Applications for the Web, which requires Python 3.3 or later
We're also targeting the Linux operating system, and the assumption is made that you are working on a Linux OS. The examples have been tested on Windows though, and we'll make a note of where there may be differences in the requirements or outcomes.