python-multipart
Streaming multipart parser for handling file uploads in Python web frameworks.
3. Used by agents' projects
Dependency in 187 public GitHub projects set up for AI coding agents that we scanned (3.0%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What python-multipart does
python-multipart reads multipart/form-data bodies as they stream in and hands each piece to your callbacks, so an upload never has to be held whole in memory.
python-multipart popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How python-multipart is used
- python-multipart is a dependency in 187 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (11.5% of the 1,623 Python ones), #5 of 102 in http servers and apis.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,503; those are left out of every share on this page.
- Projects that use it most often also use Uvicorn (95.2%), FastAPI (90.4%), Pydantic (80.7%).
- It is more common in projects set up for Roo Code (6.3%) than for Gemini CLI (1.5%).
By coding agent
Often used with
python-multipart in practice
Strengths
The in-depth example reads the request in chunks and updates a SHA-256 hash inside <code>on_part_data</code>. The docs describe the goal as reaching each part "as it arrives, without needing to store any parts in memory."
You write small functions and the parser calls them. <code>on_part_begin</code> runs when a new part starts. <code>on_part_data(data, start, end)</code> passes you a buffer and the slice bounds that belong to the current part.
The docs say the library "does not assume that you are using WSGI". The quick example therefore copies <code>CONTENT_TYPE</code> and <code>CONTENT_LENGTH</code> from the WSGI environ into a headers dict before it calls <code>parse_form</code>.
The repository dates from 2013. The release notes for 0.0.32, published 2026-06-04, list one change: it replaces a per-byte partial-boundary scan with an <code>rfind</code> lookbehind.
Watch out for
The package used to be imported as <code>multipart</code>. The docs say that name still works, with a warning, only as long as the separate <code>multipart</code> package is not installed. If both are installed, you need to import <code>python_multipart</code>.
A comment in the in-depth example says Python 2 lacks the <code>nonlocal</code> 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 name Flask, Django and Tornado but choose to "stick to plain WSGI" with <code>wsgiref</code>. Both examples on the docs page run on that setup.
Feed a MultipartParser in chunks (from the in-depth example)
# Callbacks dictionary.
callbacks = { 'on_part_begin' : on_part_begin , 'on_part_data' : on_part_data , 'on_part_end' : on_part_end , }
# Create the parser.
parser = python_multipart . MultipartParser ( boundary , callbacks )
# The input stream is from the WSGI environ.
inp = environ [ 'wsgi.input' ]
# Feed the parser with data from the request.
size = int ( environ [ 'CONTENT_LENGTH' ])
while size > 0 :
to_read = min ( size , 1024 * 1024 )
data = inp . read ( to_read )
parser . write ( data )
size -= len ( data )
if len ( data ) != to_read :
breakMore about python-multipart
Funding
- GitHub Sponsors: https://github.com/Kludex
- 30 GitHub sponsors
Packages around it
- uvicorn: ASGI server
- fastapi: API framework
- pydantic: Data validation
- python-dotenv: .env file loader
- requests: HTTP client
- pydantic-settings: Settings from env vars
Alternatives
python-multipart This page
Get started
Install it.
pip install python-multipartRules for your agent
## 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]`.