How to Install fastapi in Python
FastAPI framework, high performance, easy to learn, fast to code, ready for production
pip install fastapi
What is fastapi?
FastAPI framework, high performance, easy to learn, fast to code, ready for production
FastAPI framework, high performance, easy to learn, fast to code, ready for production
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.
Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available. Fast to code: Increase the speed to develop features by about 200% to 300%. Fewer bugs: Reduce about 40% of human (developer) induced errors. Intuitive: Great editor support. Completion everywhere. Less time debugging. Easy: Designed to be easy to use and learn. Less time reading docs. Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs. Robust: Get production-ready code. With automatic interactive documentation. Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema.
Quick Start
Minimal example to get started with fastapi:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def root():
return {"message": "Hello, World!"}
# Run with: uvicorn main:app --reload
# Docs at: http://localhost:8000/docs
Installation
pip (standard)
pip install fastapi
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install fastapi
pip3
pip3 install fastapi
conda
conda install -c conda-forge fastapi
Poetry
poetry add fastapi
Dependencies
Installing fastapi will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import fastapi; print(fastapi.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing fastapi with pip.
ModuleNotFoundError: No module named 'fastapi'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install fastapi. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'fastapi' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install fastapi to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'fastapi'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show fastapi and upgrade with pip install --upgrade fastapi.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install fastapi. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user fastapi
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org fastapi
ConnectionError: Failed to establish a new connection
Cause: Server unreachable, URL invalid, or firewall/proxy blocking the connection.
Fix: Verify the URL and network access. Set HTTP_PROXY / HTTPS_PROXY env vars if behind a proxy.
SSLError: CERTIFICATE_VERIFY_FAILED
Cause: The remote server's SSL certificate cannot be verified.
Fix: Update CA certificates on your system. For testing only, disable SSL verification (never in production).
Runtime Errors
Common errors when using fastapi after installation.
HTTP 422 Unprocessable Entity
Cause: Request body or query parameters failed Pydantic validation.
Fix: Check the response body — the detail field lists which fields failed and why.
pydantic_core.ValidationError
Cause: Input data does not match the model's type annotations.
Fix: Inspect e.errors() for field-level details.
ModuleNotFoundError: No module named 'uvicorn'
Cause: uvicorn is a separate package and is not installed.
Fix: Install with: pip install fastapi[standard] (bundles uvicorn) or pip install uvicorn
Recent Releases
| Version | Released |
|---|---|
0.135.3 latest |
2026-04-01 |
0.135.2 |
2026-03-23 |
0.135.0 |
2026-03-01 |
0.135.1 |
2026-03-01 |
0.134.0 |
2026-02-27 |
Manage fastapi
Upgrade to latest version
pip install --upgrade fastapi
Install a specific version
pip install fastapi==0.135.3
Uninstall
pip uninstall fastapi
Check what is installed
pip show fastapi