agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/frameworks/flask/SKILL.md

flask

Skill15 starsChanged 43 days agoMITView on GitHub

Expert Flask assistance covering Blueprints, application factories, Jinja2 templating, and SQLAlchemy extensions. Use when developing lightweight Python web services and applications.

  • Reads credentials

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Flask Application Factory pattern:

    line 115
  2. Very specific:

    Always structure applications using the Application Factory pattern (create_app()) and Blueprints.

    line 137
  3. Distinctive:

    Run Flask applications behind a production WSGI/ASGI server like Gunicorn or Uvicorn with Gevent workers.

    line 138
  4. Very specific:

    Use environment variables for SECRET_KEY and database credentials (python-dotenv).

    line 139
  5. Very specific:

    Use extensions like Flask-SQLAlchemy and Flask-Migrate for relational data management.

    line 140
  6. Very specific:

    Use the built-in development server (flask run) in production environments.

    line 144
  7. Distinctive:

    Commit default secret keys to version control.

    line 145
  8. Very specific:

    Use global state variables to store request-specific user data.

    line 146

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Flask

Flask is a lightweight WSGI web framework for Python, offering modular blueprints, extensible request handling, and flexible integration with database ORMs and async handlers.

When to Use

  • Lightweight Python Microservices: Rapidly prototyping APIs and small-to-medium web services without boilerplate.
  • Machine Learning Inference Wrappers: Wrapping data science pipelines and Scikit-learn/XGBoost models with minimal overhead.
  • Custom Architectures: Projects requiring complete freedom to select ORMs, auth libraries, and database drivers.
  • Internal Scripting & Admin Utilities: Embedding web dashboards inside automated Python operations tooling.

Quick Start

from flask import Flask
import asyncio

app = Flask(__name__)

@app.route("/")
async def hello():
    await asyncio.sleep(1)
    return "Hello form Async Flask!"

Core Concepts

Application Factory & Blueprint Pattern

Structuring scalable Flask applications:

# app/__init__.py
from flask import Flask
from .routes.users import user_bp
from .routes.orders import order_bp

def create_app(config_object="app.config.ProductionConfig"):
    app = Flask(__name__)
    app.config.from_object(config_object)

    # Register modular blueprints
    app.register_blueprint(user_bp, url_prefix="/api/v1/users")
    app.register_blueprint(order_bp, url_prefix="/api/v1/orders")

    return app

Type-Safe Request Handling & JSON Responses

Parsing payloads and handling route parameters:

# app/routes/users.py
from flask import Blueprint, request, jsonify, abort

user_bp = Blueprint("users", __name__)

@user_bp.route("/<int:user_id>", methods=["GET"])
def get_user(user_id):
    if user_id <= 0:
        abort(404, description="User not found")
    return jsonify({
        "id": user_id,
        "name": f"User_{user_id}",
        "status": "active"
    }), 200

@user_bp.route("/", methods=["POST"])
def create_user():
    data = request.get_json()
    if not data or "email" not in data:
        return jsonify({"error": "Email is required"}), 400

    return jsonify({"id": 42, "email": data["email"]}), 201

Centralized Error Handling & RFC 7807

Formatting consistent API exceptions:

from flask import jsonify

def register_error_handlers(app):
    @app.errorhandler(404)
    def resource_not_found(e):
        return jsonify({
            "error": "Not Found",
            "message": str(e.description),
            "status": 404
        }), 404

    @app.errorhandler(500)
    def internal_server_error(e):
        return jsonify({
            "error": "Internal Server Error",
            "message": "An unexpected error occurred",
            "status": 500
        }), 500

Common Patterns

Modular Application Factory with Blueprints

Problem: Monolithic app.py script becoming unmaintainable as routes and extensions grow.

Solution: Use Flask Application Factory pattern:

# app/__init__.py
from flask import Flask
from .extensions import db
from .routes.api import api_bp

def create_app(config_name="default"):
    app = Flask(__name__)
    app.config.from_object(f"config.{config_name}")

    db.init_app(app)
    app.register_blueprint(api_bp, url_prefix="/api/v1")

    return app

Best Practices

Do:

  • Always structure applications using the Application Factory pattern (create_app()) and Blueprints.
  • Run Flask applications behind a production WSGI/ASGI server like Gunicorn or Uvicorn with Gevent workers.
  • Use environment variables for SECRET_KEY and database credentials (python-dotenv).
  • Use extensions like Flask-SQLAlchemy and Flask-Migrate for relational data management.

Don't:

  • Use the built-in development server (flask run) in production environments.
  • Commit default secret keys to version control; use cryptographically random secrets.
  • Use global state variables to store request-specific user data; use Flask's g context object.

Troubleshooting

ErrorCauseSolution
Working outside of application contextAccessing database or current_app outside request/app context.Wrap code with with app.app_context():.
RuntimeError: The session is unavailableapp.secret_key not configured.Set app.secret_key = "strong-random-key" in config.
Method Not Allowed (405)Route does not explicitly permit request method.Add method to decorator: @app.route('/path', methods=['GET', 'POST']).

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.