Installing Python packages with pip
As we said earlier, pip
is the built-in Python package manager that will help us install third-party libraries.
A word on alternate package managers such as Poetry, Pipenv, and Conda
While exploring the Python community, you may hear about alternate package managers such as Poetry, Pipenv, and Conda. These managers were created to solve some issues posed by pip
, especially around sub-dependencies management. While they are very good tools, we’ll see in Chapter 10, Deploying a FastAPI Project, that most cloud hosting platforms expect dependencies to be managed with the standard pip
command. Therefore, they may not be the best choice for a FastAPI application.
To get started, let’s install FastAPI and Uvicorn:
(venv) $ pip install fastapi "uvicorn[standard]"
We’ll talk about it in later chapters, but Uvicorn is required to run a FastAPI project.
What does “standard” stand for after “uvicorn”?
You probably noticed the standard
word inside square brackets just after uvicorn
. Sometimes, some libraries have sub-dependencies that are not required to make the library work. Usually, they are needed for optional features or specific project requirements. The square brackets are here to indicate that we want to install the standard sub-dependencies of uvicorn
.
To make sure the installation worked, we can open a Python interactive shell and try to import the fastapi
package:
(venv) $ python>>> from fastapi import FastAPI
If it passes without any errors, congratulations, FastAPI is installed and ready to use!