{"record":{"id":"3ccff8d0c7715291","repo":"tiangolo/fastapi","slug":"form-data-requires-python-multipart-to-be-instal-3ccff8","errorCode":null,"errorMessage":"Form data requires \"python-multipart\" to be installed. \nYou can install \"python-multipart\" with: \n\npip install python-multipart\n","messagePattern":"Form data requires \"python-multipart\" to be installed\\. \nYou can install \"python-multipart\" with: \n\npip install python-multipart\n","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"fastapi/dependencies/utils.py","lineNumber":129,"sourceCode":"            # __version__ is available in both multiparts, and can be mocked\n            from multipart import (  # type: ignore[no-redef,import-untyped]\n                __version__,\n            )\n\n            assert __version__\n            try:\n                # parse_options_header is only available in the right multipart\n                from multipart.multipart import (  # type: ignore[import-untyped]\n                    parse_options_header,\n                )\n\n                assert parse_options_header\n            except ImportError:\n                logger.error(multipart_incorrect_install_error)\n                raise RuntimeError(multipart_incorrect_install_error) from None\n        except ImportError:\n            logger.error(multipart_not_installed_error)\n            raise RuntimeError(multipart_not_installed_error) from None\n\n\ndef get_parameterless_sub_dependant(*, depends: params.Depends, path: str) -> Dependant:\n    assert callable(depends.dependency), (\n        \"A parameter-less dependency must have a callable dependency\"\n    )\n    own_oauth_scopes: list[str] = []\n    if isinstance(depends, params.Security) and depends.scopes:\n        own_oauth_scopes.extend(depends.scopes)\n    return get_dependant(\n        path=path,\n        call=depends.dependency,\n        scope=depends.scope,\n        own_oauth_scopes=own_oauth_scopes,\n    )\n\n\ndef _get_flat_body_params(dependant: Dependant) -> list[ModelField]:","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/fastapi/dependencies/utils.py#L111-L147","documentation":"RuntimeError raised by ensure_multipart_is_installed when neither python-multipart nor the (wrong) multipart package is importable at all. It triggers as soon as a route uses Form()/File() and FastAPI needs a multipart parser to decode the request body. The error message tells you to install python-multipart.","triggerScenarios":"Any request that requires multipart parsing (a Form or File parameter) hits a route whose environment lacks python-multipart entirely, so ensure_multipart_is_installed() falls through both import attempts and raises.","commonSituations":"Slim fastapi install (pip install fastapi) without the standard extra; CI image that omitted python-multipart; deploying with a trimmed requirements list; adding a Form endpoint to an existing app without reinstalling deps.","solutions":["Install python-multipart: pip install python-multipart.","Install the standard extra: pip install \"fastapi[standard]\".","Pin python-multipart in requirements.txt / pyproject.toml so it is always present.","Restart the server/process after installing so the new import is picked up."],"exampleFix":"# before\npip install fastapi   # no multipart parser\n@app.post(\"/login\")\ndef login(username: str = Form()): ...\n# -> RuntimeError: Form data requires \"python-multipart\" to be installed.\n\n# after\npip install python-multipart\n@app.post(\"/login\")\ndef login(username: str = Form()): ...","handlingStrategy":"fallback","validationCode":"# Detect a missing multipart parser before relying on Form/File\nimport importlib.util, sys\nif importlib.util.find_spec(\"python_multipart\") is None:\n    print(\"python-multipart is not installed; Form/File routes will fail\")\n    sys.exit(1)","typeGuard":null,"tryCatchPattern":"try:\n    from python_multipart import __version__  # noqa: F401\nexcept ImportError:\n    raise RuntimeError(\"Install python-multipart to use Form/File endpoints\")","preventionTips":["Add python-multipart to requirements whenever you use Form() or File().","Install fastapi[standard] in dev/CI to get the parser automatically.","Restart the process after installing so the import resolves.","Write a smoke test that posts a form to confirm multipart parsing works."],"tags":["multipart","installation","form-data","dependency","fastapi"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}