tiangolo/fastapi · error · RuntimeError
Form data requires "python-multipart" to be installed. You…
Error message
Form data requires "python-multipart" to be installed. You can install "python-multipart" with: pip install python-multipart
What it means
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.
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.
Example fix
# before
pip install fastapi # no multipart parser
@app.post("/login")
def login(username: str = Form()): ...
# -> RuntimeError: Form data requires "python-multipart" to be installed.
# after
pip install python-multipart
@app.post("/login")
def login(username: str = Form()): ... Defensive patterns
Strategy: fallback
Validate before calling
# Detect a missing multipart parser before relying on Form/File
import importlib.util, sys
if importlib.util.find_spec("python_multipart") is None:
print("python-multipart is not installed; Form/File routes will fail")
sys.exit(1) Try / catch
try:
from python_multipart import __version__ # noqa: F401
except ImportError:
raise RuntimeError("Install python-multipart to use Form/File endpoints") Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Form data requires "python-multipart" to be installed. It…
- To use the fastapi command, please install…
- Expected UploadFile, received
- No Jessica token provided
- X-Key header invalid
AI-assisted analysis of tiangolo/fastapi@3e8d1526d8 (2026-08-11).
Data as JSON: /api/errors/3ccff8d0c7715291.
Report an issue: GitHub.
Appendix: source
Thrown at fastapi/dependencies/utils.py:129
# __version__ is available in both multiparts, and can be mocked
from multipart import ( # type: ignore[no-redef,import-untyped]
__version__,
)
assert __version__
try:
# parse_options_header is only available in the right multipart
from multipart.multipart import ( # type: ignore[import-untyped]
parse_options_header,
)
assert parse_options_header
except ImportError:
logger.error(multipart_incorrect_install_error)
raise RuntimeError(multipart_incorrect_install_error) from None
except ImportError:
logger.error(multipart_not_installed_error)
raise RuntimeError(multipart_not_installed_error) from None
def get_parameterless_sub_dependant(*, depends: params.Depends, path: str) -> Dependant:
assert callable(depends.dependency), (
"A parameter-less dependency must have a callable dependency"
)
own_oauth_scopes: list[str] = []
if isinstance(depends, params.Security) and depends.scopes:
own_oauth_scopes.extend(depends.scopes)
return get_dependant(
path=path,
call=depends.dependency,
scope=depends.scope,
own_oauth_scopes=own_oauth_scopes,
)
def _get_flat_body_params(dependant: Dependant) -> list[ModelField]:View on GitHub (pinned to 3e8d1526d8)