Automatically migrate Python web applications between frameworks (Flask → FastAPI, Django → FastAPI). Use when you need to migrate an existing web application to a modern framework while preserving functionality. The skill analyzes the codebase, updates routes, handlers, configuration, dependency injection patterns, and tests. Creates git commits for each migration phase and generates a comprehensive summary of all changes. Supports automatic dependency updates, code transformations, and test adaptations.
89
86%
Does it follow best practices?
Impact
93%
1.24xAverage score across 3 eval scenarios
Passed
No known issues
This skill automatically migrates Python web applications between frameworks, transforming code, configuration, and tests while preserving existing functionality. It handles route migration, request/response patterns, dependency injection, configuration updates, and test adaptations, committing changes incrementally with detailed summaries.
# Navigate to your repository
cd /path/to/your/repo
# Run migration
python scripts/migrate.py . --from flask --to fastapiThe migration process will:
# Migrate Flask app to FastAPI
python scripts/migrate.py /path/to/flask-app --from flask --to fastapi
# Output:
# ✓ Created migration branch: migrate-flask-to-fastapi
# ✓ Analyzing codebase...
# ✓ Found 15 route files
# ✓ Found 23 test files
# ✓ Migrating dependencies...
# ✓ Migrating routes...
# ✓ Migrating configuration...
# ✓ Migrating tests...
# ✓ Migration completed successfully!What gets migrated:
@app.route() → @app.get(), @app.post(), etc.request.args → query parameters, request.json → Pydantic modelsjsonify() → direct returnExample transformation:
Before (Flask):
@app.route('/users/<int:user_id>', methods=['GET'])
def get_user(user_id):
user = db.get_user(user_id)
return jsonify(user)After (FastAPI):
@app.get('/users/{user_id}')
async def get_user(user_id: int) -> UserSchema:
user = await db.get_user(user_id)
return userWhat gets migrated:
The migration tool automatically:
Updates package dependencies:
requirements.txtpyproject.tomlExample changes:
flask>=2.0.0 → fastapi>=0.104.0
werkzeug>=2.0.0 → uvicorn[standard]>=0.24.0
flask-cors>=3.0.0 → fastapi-cors>=0.0.6Transforms route definitions and handlers:
Updates configuration files:
Adapts test files:
Creates a comprehensive report:
MIGRATION_SUMMARY.jsonpython scripts/migrate.py <repo_path> --from <source> --to <target>
# Options:
# repo_path: Path to the repository
# --from: Source framework (flask, django, or auto)
# --to: Target framework (fastapi)You can also run individual migration steps:
from migrate_dependencies import DependencyMigrator
from migrate_routes import RouteMigrator
from migrate_config import ConfigMigrator
from migrate_tests import TestMigrator
# Run specific migration
migrator = RouteMigrator(repo_path, 'flask', 'fastapi')
migrator.migrate()After migration completes:
Review the changes
git log --oneline
git diff main..migrate-flask-to-fastapiInstall new dependencies
pip install -r requirements.txtRun tests
pytestManual review needed for:
Test the application
uvicorn main:app --reloadMerge when ready
git checkout main
git merge migrate-flask-to-fastapireferences/framework_comparison.md - Detailed comparison of Flask, Django, and FastAPI including architecture, routing, request handling, and performancereferences/migration_guide.md - Comprehensive migration guide with step-by-step instructions, common patterns, troubleshooting, and post-migration checklistreferences/migration_patterns.md - Common migration patterns for routes, requests, responses, authentication, database operations, and testingExample applications are provided in assets/:
example_flask_app.py - Flask application before migrationexample_fastapi_app.py - Same application after migration to FastAPICompare these files to understand the transformations applied.
After migration, review MIGRATION_SUMMARY.json:
{
"source_framework": "flask",
"target_framework": "fastapi",
"total_changes": 47,
"changes_by_type": {
"dependency": 5,
"route": 15,
"config": 4,
"test": 23
},
"files_modified": [...],
"next_steps": [...]
}Issue: Import errors after migration
pip install -r requirements.txtIssue: Tests fail with async errors
@pytest.mark.asyncio and install pytest-asyncioIssue: Database connections fail
Issue: CORS errors
See references/migration_guide.md for detailed troubleshooting.
0f00a4f
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.