Package management with pip
A FastAPI application constitutes packages, therefore you will be introduced to package management practices, such as installing packages, removing packages, and updating packages for your application.
Installing packages from the source can turn out to be a cumbersome task as, most of the time, it involves downloading and unzipping
.tar.gz files before manual installation. In a scenario where a hundred packages are to be installed, this method becomes inefficient. Then, how do you automate this process?
$ python3 -m pip list
The preceding command should return a list of packages installed. The output should be similar to the following figure:
If the command returns an error, follow the instructions at https://pip.pypa.io/en/stable/installation/ to install pip.
$ pip install fastapi
On a Unix operating system, such as Mac or Linux, in some cases, the
sudo keyword is prepended to install global packages.
To uninstall a package, the following command is used:
$ pip uninstall fastapi
To collate the current packages installed in a project into a file, we use the following
$ pip freeze > requirements.txt
> operator tells bash to save the output from the command into the
requirements.txt file. This means that running
pip freeze returns an output of all the currently installed packages.
To install packages from a file such as the
requirements.txt file, the following command is used:
$ pip install -r requirements.txt
Now that you have learned the basics of pip and have gone over some basic commands, let’s learn the basics of Docker.