{"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":"critical","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/42a41db11f6882807ac3c057b942178d53b97438/fastapi/dependencies/utils.py#L111-L147","documentation":"RuntimeError raised by ensure_multipart_is_installed() at dependencies/utils.py:129 when form-data handling is required and NEITHER `python-multipart` nor `multipart` is importable. The function tries python_multipart (with version > 0.0.12 assertion), then falls back to `multipart`; if both imports fail it logs multipart_not_installed_error and raises RuntimeError. It is triggered the first time a Form/File/UploadFile parameter is processed.","triggerScenarios":"Declaring a Form(), File(), or UploadFile parameter while python-multipart is not installed at all. The dependency is detected when FastAPI builds the body model for the path operation, so the error surfaces on first form-handling request (or at app setup in stricter modes).","commonSituations":"Bare `pip install fastapi` (python-multipart is an optional extra); fresh env where the form library was forgotten; production image that strips optional deps; upgrading FastAPI without re-adding python-multipart.","solutions":["Install python-multipart: pip install python-multipart (or pip install 'fastapi[standard]').","Add python-multipart to requirements.txt/pyproject.toml dependencies.","Rebuild the virtualenv/image after updating requirements.","Verify: python -c 'import python_multipart; print(python_multipart.__version__)'."],"exampleFix":"# before\npip install fastapi\n# after\npip install python-multipart","handlingStrategy":"validation","validationCode":"import importlib.util, sys, subprocess\nif importlib.util.find_spec('python_multipart') is None:\n    subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'python-multipart'])","typeGuard":"def multipart_installed() -> bool:\n    import importlib.util\n    return importlib.util.find_spec('python_multipart') is not None","tryCatchPattern":"from fastapi.dependencies.utils import ensure_multipart_is_installed\ntry:\n    ensure_multipart_is_installed()\nexcept RuntimeError:\n    import subprocess, sys\n    subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'python-multipart'])","preventionTips":["Install python-multipart whenever you use Form/File/UploadFile.","Or install 'fastapi[standard]' which includes it.","Add python-multipart to requirements.","Verify with: python -c 'import python_multipart; print(python_multipart.__version__)'."],"tags":["multipart","forms","installation","packaging","fastapi"],"analyzedSha":"42a41db11f6882807ac3c057b942178d53b97438","analyzedAt":"2026-08-04T19:23:32.007Z","schemaVersion":2}