{"record":{"id":"50d0e766d787f89d","repo":"pallets/flask","slug":"install-flask-with-the-async-extra-in-order-to-u","errorCode":null,"errorMessage":"Install Flask with the 'async' extra in order to use async views.","messagePattern":"Install Flask with the 'async' extra in order to use async views\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/flask/app.py","lineNumber":1099,"sourceCode":"\n    def async_to_sync(\n        self, func: t.Callable[..., t.Coroutine[t.Any, t.Any, t.Any]]\n    ) -> t.Callable[..., t.Any]:\n        \"\"\"Return a sync function that will run the coroutine function.\n\n        .. code-block:: python\n\n            result = app.async_to_sync(func)(*args, **kwargs)\n\n        Override this method to change how the app converts async code\n        to be synchronously callable.\n\n        .. versionadded:: 2.0\n        \"\"\"\n        try:\n            from asgiref.sync import async_to_sync as asgiref_async_to_sync\n        except ImportError:\n            raise RuntimeError(\n                \"Install Flask with the 'async' extra in order to use async views.\"\n            ) from None\n\n        return asgiref_async_to_sync(func)\n\n    def url_for(\n        self,\n        /,\n        endpoint: str,\n        *,\n        _anchor: str | None = None,\n        _method: str | None = None,\n        _scheme: str | None = None,\n        _external: bool | None = None,\n        **values: t.Any,\n    ) -> str:\n        \"\"\"Generate a URL to the given endpoint with the given values.\n","sourceCodeStart":1081,"sourceCodeEnd":1117,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/app.py#L1081-L1117","documentation":"Raised by Flask's async-to-sync bridge when asgiref is not importable. Flask supports async view functions but requires the asgiref package to wrap them for the synchronous WSGI server. Without it the runtime cannot call the coroutine.","triggerScenarios":"Defining an async def view, running under WSGI, and the asgiref package is absent. Flask calls async_to_sync internally which triggers the ImportError path.","commonSituations":"Installed Flask without the async extra (pip install flask instead of pip install flask[async]); a fresh/trimmed environment; asgiref removed by a dependency resolver.","solutions":["Install the async extra: pip install flask[async] (equivalently pip install asgiref).","Pin asgiref in requirements.txt if dependency resolution drops it.","If async is not needed, convert the view to a synchronous def and avoid the bridge entirely."],"exampleFix":"// before\nasync def index(): ...\n# Flask with no asgiref installed -> raises at request time\n// after\npip install \"flask[async]\"\n# or convert to sync:\ndef index(): ...","handlingStrategy":"fallback","validationCode":"import importlib.util\nif importlib.util.find_spec('asgiref') is None:\n    raise SystemExit('Install: pip install flask[async]')","typeGuard":"import importlib.util\ndef async_support_available() -> bool:\n    return importlib.util.find_spec('asgiref') is not None","tryCatchPattern":"try:\n    from asgiref.sync import async_to_sync  # noqa\nexcept ImportError:\n    # define sync-only views\n    ...\nelse:\n    # async views are safe","preventionTips":["Pin flask[async] (or asgiref) in requirements.","Fail fast at startup with a find_spec check if you use async views.","Document the async dependency in the project README."],"tags":["async","dependencies","runtime-error"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}