19 Using Python libraries

 

This chapter covers

  • Managing various data types—strings, numbers, and more
  • Manipulating files and storage
  • Accessing operating system services
  • Using internet protocols and formats
  • Developing and debugging tools
  • Accessing the Python Package Index
  • Installing Python libraries and virtual environments using pip and venv

Python has long proclaimed that one of its key advantages is its “batteries included” philosophy. This means that a stock install of Python comes with a rich standard library that lets you handle a wide variety of situations without the need to install additional libraries. This chapter gives you a high-level survey of some of the contents of the standard library, as well as some suggestions on finding and installing external modules. Since the content is purely informational, this chapter doesn’t include a lab or other exercises.

19.1 “Batteries included”: The standard library

In Python, what’s considered to be the library consists of several components, including built-in data types and constants that can be used without an import statement, such as numbers and lists, as well as some built-in functions and exceptions. The largest part of the library is an extensive collection of modules. If you have Python, you also have libraries to manipulate diverse types of data and files to interact with your operating system, to write servers and clients for many internet protocols, and to develop and debug your code.

19.1.1 Managing various data types

19.1.2 Manipulating files and storage

19.1.3 Accessing operating system services

19.1.4 Using internet protocols and formats

19.1.5 Development and debugging tools and runtime services

19.2 Moving beyond the standard library

19.3 Adding more Python libraries

19.4 The Python Package Index

19.5 Installing Python libraries using pip and venv

19.5.1 Installing with the --user flag

19.5.2 Virtual environments

19.5.3 Other options

Summary