Chapter 9. Software Interfaces

This chapter will first show you how to use Python to get information from APIs that are used now to share data between organizations, and then highlight the tools that most Python-powered organizations would use to support communication within their own infrastructure.

We already discussed Python’s support for pipes and queues across processes in “Multiprocessing”. Communicating between computers requires the computers at both ends of the conversation use a defined set of protocols—the Internet adheres to the TCP/IP suite.1 You can implement UDP yourself over sockets, Python provides a library called ssl for TLS/SSL wrappers over sockets, and asyncio to implement asynchronous transports for TCP, UDP, TLS/SSL, and subprocess pipes.

But most of us will be using the higher-level libraries that provide clients implementing various application-level protocols: ftplib, poplib, imaplib, nntplib, smtplib, telnetlib, and xmlrpc. All of them provide classes for both regular and TLS/SSL wrapped clients (and urllib exists for HTTP requests, but recommends the Requests library for most uses).

The first section in this chapter covers HTTP requests—how to get data from public APIs on the Web. Next is a brief aside about serialization in Python, and the third section describes popular tools used in enterprise-level networking. We’ll try to explicitly say when something is only available in Python 3. If you’re using Python 2 and can’t find a module ...

Get The Hitchhiker's Guide to Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.