Converting a FastAPI Project's Dependencies
Convert a FastAPI application's requirements.txt to pyproject.toml, including async dependencies, Pydantic v2, database drivers, and background task workers.
Detailed Explanation
FastAPI projects typically leverage async Python extensively. Their dependency lists include ASGI servers, async database drivers, and Pydantic for data validation.
FastAPI requirements.txt:
fastapi>=0.104
uvicorn[standard]>=0.24
pydantic>=2.5
pydantic-settings>=2.1
# Database
sqlalchemy[asyncio]>=2.0
asyncpg>=0.29
alembic>=1.13
# Auth
python-jose[cryptography]>=3.3
passlib[bcrypt]>=1.7
python-multipart>=0.0.6
# Background Tasks
celery[redis]>=5.3
arq>=0.25
# Monitoring
sentry-sdk[fastapi]>=1.39
prometheus-fastapi-instrumentator>=6.1
Converted to pyproject.toml:
[project]
name = "my-fastapi-app"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
"fastapi>=0.104",
"uvicorn[standard]>=0.24",
"pydantic>=2.5",
"pydantic-settings>=2.1",
"sqlalchemy[asyncio]>=2.0",
"asyncpg>=0.29",
"alembic>=1.13",
"python-jose[cryptography]>=3.3",
"passlib[bcrypt]>=1.7",
"python-multipart>=0.0.6",
"celery[redis]>=5.3",
"arq>=0.25",
"sentry-sdk[fastapi]>=1.39",
"prometheus-fastapi-instrumentator>=6.1",
]
FastAPI-specific patterns:
uvicorn[standard]is essential for production -- it addshttptools,uvloop, andwebsockets- Pydantic v2 uses a separate
pydantic-settingspackage for configuration management asyncpgis the preferred async PostgreSQL driver, whilesqlalchemy[asyncio]provides the async ORM layerpython-jose[cryptography]uses the cryptography backend for JWT handlingpasslib[bcrypt]provides bcrypt password hashing with the bcrypt backend
FastAPI's ecosystem is heavily async-first, so requires-python should typically be set to >=3.11 or higher to take advantage of task groups and other modern async features.
Use Case
Converting a production FastAPI microservice with async database access, JWT authentication, and Celery workers from requirements.txt to pyproject.toml.
Try It — Requirements ↔ Pyproject
Related Topics
Converting a Django Project's Dependencies
Real-World Projects
Converting a Flask Project's Dependencies
Real-World Projects
Dependencies with Extras (Optional Features)
Advanced Features
Environment Markers (Platform-Specific Dependencies)
Advanced Features
Development Dependencies and Optional Groups
Advanced Features