Skip to content

feat(flask): add Flask adapter (closes #5)#19

Merged
fsecada01 merged 2 commits into
masterfrom
feat/5-flask-adapter
Jun 24, 2026
Merged

feat(flask): add Flask adapter (closes #5)#19
fsecada01 merged 2 commits into
masterfrom
feat/5-flask-adapter

Conversation

@fsecada01

Copy link
Copy Markdown
Owner

Summary

Closes #5. Adds a Flask adapter so users can pip install "component-framework[flask]" and serve server-side components from Flask, mirroring the FastAPI / Litestar / Django adapters and following the constitution's Adapter Contract.

Changes

  • adapters/flask.py
    • FlaskRenderer(Renderer) — Jinja2-backed; accepts a Flask app (or a Jinja2 Environment) and shares the app's jinja_env so component templates inherit the app's filters, globals, and extensions.
    • Synchronous component endpoint (component_view) using Component.dispatch, exposed via create_component_blueprint() / register_component_routes()POST /components/<name>.
    • Parses both JSON and HTMX form-encoded bodies; returns JSON errors (404 unknown component, 400 bad request, 500 handler error). Import-guarded via _require_extra.
  • pyproject.tomlflask extra (flask>=3.0 only); added to all and dev.
  • examples/flask_example.py — runnable counter app.
  • Teststests/test_flask_adapter.py (renderer + endpoint: dispatch, mount, form-encoded, 404/400/500) guarded by pytest.importorskip("flask"); plus a flask ImportError-guard test in tests/test_optional_extras.py.
  • README — Flask marked ✅ Supported (adapter table, install matrix, Quick Start example).

Constitution gates

  • Renderer subclass in adapters/flask.py implementing core/renderer.py.
  • HTTP endpoint dispatching to the component registry.
  • Optional extras group; [flask] pulls only flask — no FastAPI/Django/JinjaX.
  • Working example in examples/.
  • pdoc-compatible docstrings on all public symbols.
  • Adapter tests use pytest.importorskip("flask").
  • No imports from core/ using framework-specific types; no cross-adapter imports.

WebSocket support is left as a follow-up (the contract lists it as optional).

Testing

  • tests/test_flask_adapter.py: 8 passed; flask guard test added.
  • Full suite: 419 passed.
  • prek run --all-files clean (ruff, ruff-format, ty).

🤖 Generated with Claude Code

Adds a Flask adapter so users can `pip install "component-framework[flask]"`
and serve server-side components from Flask, mirroring the FastAPI/Litestar/
Django adapters and following the constitution's Adapter Contract.

- adapters/flask.py: FlaskRenderer (Jinja2; shares the app's jinja_env for
  consistent filters/globals/extensions) + a synchronous component endpoint
  exposed via a blueprint (create_component_blueprint /
  register_component_routes). Parses JSON and HTMX form-encoded bodies; JSON
  404/400/500 errors. Import-guarded with _require_extra.
- pyproject: `flask` extra (flask>=3.0 only — no FastAPI/Django/JinjaX);
  added to `all` and `dev`.
- examples/flask_example.py: runnable counter app.
- tests/test_flask_adapter.py: renderer + endpoint coverage (dispatch, mount,
  form-encoded, 404/400/500), guarded by pytest.importorskip("flask").
- tests/test_optional_extras.py: ImportError guard test for the flask adapter.
- README: Flask marked supported (adapter table, install matrix, Quick Start).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hdmTV88wAXU8ew1rorMjt
@fsecada01 fsecada01 added the enhancement New feature or request label Jun 24, 2026
Review caught a real integration bug: component-client.js posts to
"/components/<name>/" (trailing slash), but the blueprint rule only matched
the no-slash form, so real usage 404'd while the no-slash tests passed.
Add strict_slashes=False and a regression test for the trailing-slash URL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hdmTV88wAXU8ew1rorMjt
@fsecada01 fsecada01 self-assigned this Jun 24, 2026
@fsecada01 fsecada01 merged commit 6b1980c into master Jun 24, 2026
7 checks passed
@fsecada01 fsecada01 mentioned this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Flask adapter

1 participant