ProvenPin Install

Flask 3 app factory + Flask-SQLAlchemy: working versions (tested 2026-10-15)

Flask application factory with Flask-SQLAlchemy 3, a JSON API and pytest fixtures using an in-memory database.

passed2 passed · 0 failed2026-10-15 11:35 UTC
Status
passed
Last passed
2026-10-15 11:35 UTC
Tests
2 / 2
Language
Python
Runtime
Python 3.13.16
pinned versions4
flask@3.1.3flask-sqlalchemy@3.1.1sqlalchemy@2.1.4pytest@9.1.1
run it
uv venv -q .venv && uv pip install -q --python .venv/bin/python -r requirements.txt
.venv/bin/python -m pytest -q
test environment
Python 3.13.16
linux 6.17.0-1022-azure
x64
runner: github-actions 38728226240

The code

Exactly the files that passed. Your agent can pull them with get_recipe("flask-sqlalchemy-app-factory") (install), or see them on GitHub.

requirements.txt
flask==3.1.3
flask-sqlalchemy==3.1.1
sqlalchemy==2.1.4
pytest==9.1.1
app/__init__.py
from flask import Flask, jsonify, request
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

class Base(DeclarativeBase):
    pass

db = SQLAlchemy(model_class=Base)

class Note(db.Model):
    id: Mapped[int] = mapped_column(primary_key=True)
    text: Mapped[str]

def create_app(config: dict | None = None) -> Flask:
    app = Flask(__name__)
    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db"
    app.config.update(config or {})
    db.init_app(app)
    with app.app_context():
        db.create_all()

    @app.post("/notes")
    def add_note():
        text = (request.get_json(silent=True) or {}).get("text")
        if not text:
            return jsonify(error="text required"), 400
        note = Note(text=text)
        db.session.add(note)
        db.session.commit()
        return jsonify(id=note.id, text=note.text), 201

    @app.get("/notes")
    def list_notes():
        notes = db.session.execute(db.select(Note).order_by(Note.id)).scalars()
        return jsonify([{"id": n.id, "text": n.text} for n in notes])

    return app
tests/test_app.py
import pytest
from app import create_app

@pytest.fixture
def client():
    return create_app({"TESTING": True, "SQLALCHEMY_DATABASE_URI": "sqlite://"}).test_client()

def test_add_and_list(client):
    assert client.post("/notes", json={"text": "hi"}).status_code == 201
    assert client.get("/notes").get_json() == [{"id": 1, "text": "hi"}]

def test_validation(client):
    assert client.post("/notes", json={}).status_code == 400
pytest.ini
[pytest]
pythonpath = .

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.