Build Python web apps with Flask using application factory pattern, Blueprints, and Flask-SQLAlchemy. Prevents 9 documented errors including stream_with_context teardown issues, async/gevent conflicts, and CSRF cache problems. Use when: creating Flask projects, organizing blueprints, or troubleshooting circular imports, context errors, registration, streaming, or authentication.
View on GitHubskills/flask/SKILL.md
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/brendadeeznuts1111/tier-1380-omega/blob/main/skills/flask/SKILL.md -a claude-code --skill flaskInstallation paths:
.claude/skills/flask/# Flask Skill
Production-tested patterns for Flask with the application factory pattern, Blueprints, and Flask-SQLAlchemy.
**Latest Versions** (verified January 2026):
- Flask: 3.1.2
- Flask-SQLAlchemy: 3.1.1
- Flask-Login: 0.6.3
- Flask-WTF: 1.2.2
- Werkzeug: 3.1.5
- **Python**: 3.9+ required (3.8 dropped in Flask 3.1.0)
---
## Quick Start
### Project Setup with uv
```bash
# Create project
uv init my-flask-app
cd my-flask-app
# Add dependencies
uv add flask flask-sqlalchemy flask-login flask-wtf python-dotenv
# Run development server
uv run flask --app app run --debug
```
### Minimal Working Example
```python
# app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return {"message": "Hello, World!"}
if __name__ == "__main__":
app.run(debug=True)
```
Run: `uv run flask --app app run --debug`
---
## Known Issues Prevention
This skill prevents **9** documented issues:
### Issue #1: stream_with_context Teardown Regression (Flask 3.1.2)
**Error**: `KeyError` in teardown functions when using `stream_with_context`
**Source**: [GitHub Issue #5804](https://github.com/pallets/flask/issues/5804)
**Why It Happens**: Flask 3.1.2 introduced a regression where `stream_with_context` triggers `teardown_request()` calls multiple times before response generation completes. If teardown callbacks use `g.pop(key)` without a default, they fail on the second call.
**Prevention**:
```python
# WRONG - fails on second teardown call
@app.teardown_request
def _teardown_request(_):
g.pop("hello") # KeyError on second call
# RIGHT - idempotent teardown
@app.teardown_request
def _teardown_request(_):
g.pop("hello", None) # Provide default value
```
**Status**: Will be fixed in Flask 3.2.0 as side effect of PR #5812. Until then, ensure all teardown callbacks are idempotent.
---
### Issue #2: Async Views with Gevent Incompatibility
**Error**: `RuntimeError` when handling concurrent async requests with gevent
**Source**: [GitHub Is