How to Install FastAPI Using pip: Complete Setup Guide

Run pip install fastapi to install the core framework with Starlette and Pydantic, or use pip install "fastapi[all]" to include optional dependencies like Uvicorn and python-multipart.

FastAPI is a high-performance ASGI web framework maintained in the fastapi/fastapi repository. Installing the package via pip configures the essential toolchain required to build APIs with automatic data validation. Understanding the difference between minimal and full installations ensures your environment contains only necessary dependencies.

Basic Installation Command

The standard installation retrieves FastAPI and its mandatory dependencies from PyPI.

pip install fastapi

This command installs the core framework along with Starlette (the ASGI toolkit handling requests and routing) and Pydantic (the data validation library). These components form the minimum viable toolchain for running FastAPI applications.

Verifying the Installation

Confirm the package is correctly configured in your environment by checking its version:

python -c "import fastapi; print(fastapi.__version__)"

This imports the main module and outputs the installed version string, confirming successful resolution of all required dependencies.

Installing Optional Dependencies

FastAPI organizes additional functionality into optional dependency groups defined in the package metadata.

Standard Extras

For most production applications, install the standard extras to include the Uvicorn ASGI server:

pip install "fastapi[standard]"

This adds Uvicorn (the server that runs your ASGI application), python-multipart (for handling form data and file uploads), and email-validator (for enhanced email string validation in Pydantic models).

All Extras

For development environments requiring maximum compatibility, install all optional dependencies:

pip install "fastapi[all]"

This includes the standard extras plus libraries for OAuth2 authentication flows, JWT token handling, and additional validation tools. Note that this installs heavier dependencies you may not need in production.

Virtual Environment Isolation

Always install FastAPI within an isolated Python environment to prevent version conflicts with system packages.

Creating an Environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

pip install fastapi

This creates a clean namespace where FastAPI and its specific dependency versions remain separate from other projects.

Production Requirements

Pin exact versions in production deployments to ensure reproducible builds:

pip install fastapi==0.109.0

Alternatively, freeze dependencies into a requirements.txt file after installation:

pip freeze > requirements.txt

Summary

  • Use pip install fastapi for the minimal installation with core dependencies only
  • Use pip install "fastapi[standard]" to include Uvicorn and common form-handling utilities
  • Use pip install "fastapi[all]" when you need OAuth2, JWT, and advanced validation features
  • Always verify installation by importing the module and printing fastapi.__version__
  • Isolate installations using virtual environments to prevent dependency conflicts with other Python projects

Frequently Asked Questions

What is the difference between pip install fastapi and pip install "fastapi[all]"?

The base command installs only FastAPI with Starlette and Pydantic, while [all] includes optional dependencies like Uvicorn (ASGI server), python-multipart (file uploads), and PyYAML. Use [standard] for production servers or [all] for local development convenience.

Do I need to install Uvicorn separately when using FastAPI?

If you run pip install fastapi without extras, you must install an ASGI server separately using pip install uvicorn. Using pip install "fastapi[standard]" or pip install "fastapi[all]" bundles Uvicorn automatically, allowing you to start servers immediately with uvicorn main:app.

Which Python versions support FastAPI?

FastAPI requires Python 3.8 or newer. The pip installer will enforce this requirement through the package's python_requires metadata, refusing installation on older Python versions to prevent compatibility issues with modern type hint syntax.

How do I upgrade FastAPI to the latest version?

Run pip install --upgrade fastapi to update to the latest release. If you installed with extras, use pip install --upgrade "fastapi[all]" to upgrade the main package and all optional dependencies simultaneously.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →