• 6 hours
  • Easy

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 3/1/22

Discover Python Packages

Woman discovering Python packages on her computer.

What is a Python package?

When working as a Python developer you make regular use of built-in Python modules and 3rd-party Python packages. These are essentially collections of code which perform common tasks that have been bundled together for re-use by Python developers across the world. 😁

Collections of code that are considered absolutely essential to all Python developers have been included in built-in Python modules so that they are available to all developers as part of the Python Standard Library when they install Python. Built-in Python modules are individual  .py  files that contain a collection of classes, methods, functions and data structures which help you perform particular tasks.

Collections of code that developers want to make available to all are put together as third-party Python packages so that they are easy to access for Python developers. However, they are not accessible via the Python Standard Library and are instead installed via PyPI, the Python Package Index. Third-party Python packages are a collection of one or more modules. 

For example, you may have already used the built-in CSV module to read and write data from/to CSV files and the third-party requests package to make requests to particular URLs.

pip: the package installer for Python

In order to install, uninstall, and upgrade Python packages (and much more) we use  pip  , the Python Package Installer.  pip  uses PyPI as the default source for its packages.

In this course, we’ll assume you already have Python installed and it should be available via your command line. You can check this by typing the following into your terminal:

→ python --version

What I get back is the following:

Python 3.7.1

pip  is included by default if you install Python  >= 3.4  . You can check that it is available via your command line by typing:

→ pip --version

In my case, I get back:

pip 18.1 from /Users/george/anaconda3/lib/python3.7/site-packages/pip (python 3.7)

PyPI - the Python Package Index

Python packages are made available to the public via PyPI, the Python Package Index. At the time of writing, there are ~240,000 packages listed on PyPI. 😵

When you are working on a Python development project, you will often find yourself in a situation where you suspect that the code you need to write has already been written by many other people around the world. If this is the case, then it is quite likely that a Python package exists which will help you perform your task. You should investigate available packages to see if it will help you save some time! 😉

There are two ways of looking for Python packages: you can search on PyPI itself, or you can trust Google to point you to the desired package on PyPI! Once you have found your desired package, the web page on PyPI will give you lots of useful information about the package. For example, the requests package listing on PyPI has information about:

  • How to install requests.

  • The requests release history.

  • Where to find documentation for requests.

  • Where to find the source code for the package.

  • Much, much more!

Check out the screencast below if you want to double-check that you have  pip  available to you via the command line and you want to have a peek at me nosing around PyPI.

Let’s Recap!

Now that you have completed this chapter you should be confident with the following tasks:

  • Python packages are used to store code that performs common tasks so that the code is easily re-usable.

  • Packages can be kept private or made available to the public via PyPI.

  • Installation and uninstallation of Python packages is controlled via  pip  .

Now that you have learned the theory behind Python packages, pip and PyPI, let’s move on to using some Python packages.

Example of certificate of achievement
Example of certificate of achievement