Skip to content

Make FastAPI/JinjaX optional dependencies; add Flask and Litestar adapter stubs #4

@fsecada01

Description

@fsecada01

Problem

fastapi, uvicorn, and jinjax are currently listed as core (mandatory) dependencies in pyproject.toml:

dependencies = [
    "fastapi>=0.109.0",
    "uvicorn[standard]>=0.27.0",
    "jinjax>=0.41",
    "pydantic>=2.0",   # ← only this belongs here
]

This forces Django users (and any future Flask/Litestar users) to install FastAPI, Uvicorn, and JinjaX even when they will never use them. A Django app using django-cotton for templating must still pull in FastAPI and JinjaX as transitive baggage.

Root-cause analysis

The core package (component_framework/core/) has no imports from fastapi, uvicorn, or jinjax. Those imports exist only inside the adapter files:

File Imports
adapters/fastapi.py from fastapi import ...
adapters/fastapi_websocket.py from fastapi import ...
adapters/jinjax_renderer.py from jinjax import Catalog

Neither __init__.py is non-empty, so there are no eager re-exports that would force the adapters to load at install time. The fix is purely a pyproject.toml change.

Proposed fix

Move framework-specific packages to optional extras and keep only pydantic as a hard dependency:

dependencies = [
    "pydantic>=2.0",
]

[project.optional-dependencies]
fastapi = [
    "fastapi>=0.109.0",
    "uvicorn[standard]>=0.27.0",
    "jinjax>=0.41",
]
django = [
    "django>=4.2",
    "django-cotton>=0.9",
    "channels>=4.0",
    "channels-redis>=4.1",
]
websockets = [
    "websockets>=12.0",
]
dev = [...]

Install examples:

pip install component-framework[fastapi]        # FastAPI + JinjaX
pip install component-framework[django]         # Django + Channels
pip install component-framework[fastapi,django] # both

Note: This is a minor breaking change for users who relied on implicit FastAPI availability. Should be released in 0.3.0 or with a deprecation path.

Missing adapters

The project currently has no adapters for:

  • Flask — widely used WSGI framework; would need a renderer + event dispatcher + optional flask-sock for WebSockets
  • Litestar (formerly Starlite) — ASGI, similar surface to FastAPI, growing adoption

These can be tracked as follow-on issues once the optional-extras refactor lands.

CI impact

The test matrix should be updated to verify each extra in isolation (e.g. a [fastapi]-only install doesn't accidentally import django, and vice versa).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions