Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

python-multipart

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

HTTP servers and APIsPYPI

GitHubWebsite

1. License

License from PyPI license expression.

github.com/Kludex/python-multipart

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

67 / 100
Gid Score, #537 overall
127M
downloads a week, pypi
541
GitHub stars
187
agent projects use it
python-multipart: downloads per weekPyPI, python-multipart 127,218,974
python-multipart: GitHub starsKludex/python-multipart 541

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

94 projects, 3.1%
93 projects, 2.8%
73 projects, 3.0%
10 projects, 3.0%
9 projects, 3.2%
8 projects, 1.7%
7 projects, 6.3%
7 projects, 1.5%

Often used with

In 95.2% of its projects
In 90.4% of its projects
In 80.7% of its projects
In 63.1% of its projects
In 48.7% of its projects
In 47.1% of its projects
In 45.5% of its projects
In 41.2% of its projects

python-multipart in practice

Strengths

Each part is handled as its bytes arrive

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."

Events, not a request object

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.

Does not assume WSGI

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>.

Created in 2013, released again in 2026

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 import name clashes with another package

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>.

The walkthrough carries Python 2 workarounds

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 page examples use plain WSGI

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 :
        break

More about python-multipart

Funding
  • GitHub Sponsors: https://github.com/Kludex
  • 30 GitHub sponsors

See all

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
More in HTTP servers and APIs

Alternatives

python-multipart This page

Apache-2.0Gid 67127M/wk

Compare python-multipart with another tool

Get started

Install it.

pip install python-multipart

Rules for your agent

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]`.