Install FastAPI
Install FastAPI, uvicorn, and httpx in your terminal
Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.
Why FastAPI
FastAPI is a Python web framework built for APIs. Three features make it a strong choice for this course:
- Automatic validation: FastAPI uses Pydantic models to validate incoming data. You define the shape of your data once, and invalid requests are rejected automatically.
- Built-in documentation: FastAPI generates interactive API docs at
/docs. You can test every endpoint directly in your browser. - Minimal boilerplate: A working API takes fewer than 10 lines of code. You spend your time on logic, not configuration.
What you will install
Your API needs a framework and a server. The server listens for incoming HTTP requests and hands them to your FastAPI code for processing.
| Package | Purpose |
|---|---|
fastapi[standard] | The framework, bundled with uvicorn (the server) |
httpx | An HTTP client you will use later to test your API |
Uvicorn is an ASGI server. It opens a port on your machine, accepts HTTP connections, and forwards each request to your FastAPI application. The [standard] extra includes uvicorn so you only need one install command.
Virtual environments
A virtual environment is an isolated Python installation for your project. Packages you install inside it stay separate from your system Python and other projects. This prevents version conflicts and keeps your setup clean.
Create one before installing anything. You only need to do this once per project.
Instructions
Create a project folder, set up a virtual environment, and install the packages.
- Create a project folder and navigate into it with
mkdir expense-tracker && cd expense-tracker. - Create a virtual environment with
python -m venv venv. - Activate the virtual environment with
source venv/bin/activate. - Install
fastapi[standard]andhttpxwithpip install "fastapi[standard]" httpx.
Interactive Code Editor
Sign in to write and run code, track your progress, and unlock all chapters.
Sign In to Start Coding