Converting a Flask Project's Dependencies
Complete example of converting a Flask web application's requirements.txt to pyproject.toml, including extensions, SQLAlchemy, Marshmallow, and API dependencies.
Detailed Explanation
Flask projects tend to be more modular than Django, relying on extensions for features like database access, serialization, authentication, and API documentation. Here's a typical Flask API project conversion.
Flask requirements.txt:
flask>=3.0
flask-cors>=4.0
flask-migrate>=4.0
flask-jwt-extended>=4.6
# Database & ORM
sqlalchemy[asyncio]>=2.0
flask-sqlalchemy>=3.1
alembic>=1.13
# Serialization
marshmallow>=3.20
flask-marshmallow>=1.2
marshmallow-sqlalchemy>=1.0
# API
flask-smorest>=0.43
apispec>=6.3
# Utils
python-dotenv>=1.0
click>=8.1
Converted to pyproject.toml:
[project]
name = "my-flask-api"
version = "0.1.0"
requires-python = ">=3.9"
dependencies = [
"flask>=3.0",
"flask-cors>=4.0",
"flask-migrate>=4.0",
"flask-jwt-extended>=4.6",
"sqlalchemy[asyncio]>=2.0",
"flask-sqlalchemy>=3.1",
"alembic>=1.13",
"marshmallow>=3.20",
"flask-marshmallow>=1.2",
"marshmallow-sqlalchemy>=1.0",
"flask-smorest>=0.43",
"apispec>=6.3",
"python-dotenv>=1.0",
"click>=8.1",
]
[project.optional-dependencies]
dev = [
"pytest>=7.4",
"pytest-flask>=1.3",
"factory-boy>=3.3",
"faker>=20.0",
]
Flask-specific considerations:
- Flask extensions follow a naming convention (
flask-*), making the dependency list highly readable - SQLAlchemy with asyncio uses extras:
sqlalchemy[asyncio]for async session support - Marshmallow ecosystem has multiple interrelated packages that should be version-compatible
python-dotenvis automatically loaded by Flask when present, no code changes neededclickis already a Flask dependency, but listing it explicitly ensures your CLI commands have a minimum version
The conversion preserves all version specifiers and extras exactly. The main benefit of pyproject.toml is having all project configuration (metadata, dependencies, tool settings) in one file.
Use Case
Migrating a Flask REST API project from requirements.txt to pyproject.toml to consolidate project configuration and enable modern build tools like hatch.
Try It — Requirements ↔ Pyproject
Related Topics
Converting a Django Project's Dependencies
Real-World Projects
Basic requirements.txt to pyproject.toml
Getting Started
Dependencies with Extras (Optional Features)
Advanced Features
Development Dependencies and Optional Groups
Advanced Features
Converting a FastAPI Project's Dependencies
Real-World Projects