# python-multipart — card for AI agents

Streaming multipart parser for handling file uploads in Python web frameworks.

Category: HTTP servers and APIs · PyPI package `python-multipart` · latest version 0.0.33 (checked 2026-11-01)
Install: `pip install python-multipart`
License: Apache-2.0 (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## python-multipart
- Import it as `python_multipart`. The old `import multipart` still works, with a warning, only when the separate `multipart` package is not installed. If both are installed, you must use `python_multipart`.
- One builder's lesson, from a FastAPI plugin host: a dependency a feature cannot work without is that feature's own requirement, so declare `python-multipart` for an upload feature rather than leaving it out to keep `pyproject.toml` tidy.
- For whole forms, call `python_multipart.parse_form(headers, stream, on_field, on_file)`. The library does not assume WSGI, so build the headers dict with `Content-Type` and, if present, `Content-Length` yourself.
- Check that the Content-Type is multipart/form-data before you create a parser. If it is not, skip parsing.
- For streaming, get the boundary with `parse_options_header(content_type)` and build `MultipartParser(boundary, callbacks)` with `on_part_begin`, `on_part_data` and `on_part_end`.
- Feed the body in chunks with `parser.write(data)`. The docs' example reads at most 1024 * 1024 bytes at a time and stops when a read comes back short. In `on_part_data`, use `data[start:end]`.

## What it is
- python-multipart describes itself as an "Apache2-licensed streaming multipart parser for Python". The GitHub repository was created on 2013-03-25, and the latest release is 0.0.32.
- The docs show two ways in. The quick example calls `python_multipart.parse_form(headers, stream, on_field, on_file)` and passes two callbacks. In that example they record the name of each parsed value and file parameter. The in-depth example uses the lower-level `MultipartParser(boundary, callbacks)`. It feeds bytes in with `parser.write(data)` and defines `on_part_begin`, `on_part_data` and `on_part_end` callbacks. It uses them to hash every uploaded file without storing it.
- The README's case for the library is about large files: "streaming uploads are awesome for large files." The examples on the docs page run on plain WSGI. The library does not assume WSGI, so those examples build the headers dict and pass the input stream themselves.

## Caveats
- The import name clashes with another package: The package used to be imported as `multipart`. The docs say that name still works, with a warning, only as long as the separate `multipart` package is not installed. If both are installed, you need to import `python_multipart`.
- The walkthrough carries Python 2 workarounds: A comment in the in-depth example says Python 2 lacks the `nonlocal` keyword, so the code sets attributes on a dummy class instead. Its sample curl output reports Python/2.7.3, with Date headers from 2013.
- The docs page examples use plain WSGI: The docs name Flask, Django and Tornado but choose to "stick to plain WSGI" with `wsgiref`. Both examples on the docs page run on that setup.
- The low-level parser leaves setup to you: With `MultipartParser`, you parse the Content-Type yourself with `parse_options_header` to get the boundary. You also write the chunked read loop. The docs say to skip parsing when the type is not multipart/form-data.
- Missing it stopped one host's upload feature: One builder writes that this package is what lets FastAPI parse a multipart/form-data body. When it was missing, their own plugin host's check refused to load the upload feature. The builder says the host would otherwise have mounted a route returning 500 on every upload.

## Numbers (AgentGid data)
- Gid Score: 67.2 (#537 of all tools, 20 of 102 in its category)
- Used in 187 public projects set up for AI coding agents (3.0%)
- Downloads last week: 126,959,172 (as of 2026-11-24), +24.6% over 4 weeks
- GitHub stars: 541 (as of 2026-11-24)
- Last push: 2026-11-22

## Often used with
Uvicorn 95.2%, FastAPI 90.4%, Pydantic 80.7%, python-dotenv 63.1%, Pydantic Settings 48.7%, Requests 47.1%

## Links
- AgentGid page: https://agentgid.com/tools/python-multipart/
- Homepage: https://github.com/Kludex/python-multipart
- Repository: https://github.com/Kludex/python-multipart
- Source: https://github.com/Kludex/python-multipart#readme
- Source: https://github.com/Kludex/python-multipart
- Source: https://github.com/Kludex/python-multipart/releases
- Source: https://multipart.fastapiexpert.com/

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
