multipart-reader

raw JSON →
0.2 verified Fri May 01 auth: no python maintenance

A multipart/* reader extracted from the aiohttp project (version 0.2, 2018). Provides a simple API to parse multipart form data and file uploads. Low release cadence, last updated in 2018.

pip install multipart-reader
error AttributeError: 'MultipartReader' object has no attribute 'from_response'
cause Using an outdated or incorrect import path; trying to call a method that may not exist in this version.
fix
Use 'from multipart_reader import MultipartReader' and create reader via 'MultipartReader.from_response(stream, headers)' if available; else use 'MultipartReader.from_stream'.
error ModuleNotFoundError: No module named 'multipart'
cause Trying to import from the wrong module name; correct module is 'multipart_reader'.
fix
Run 'pip install multipart-reader' and import as 'from multipart_reader import MultipartReader'.
error TypeError: 'NoneType' object is not iterable
cause Iterating over the reader without calling 'release_all()' first, or the reader is already exhausted.
fix
Call 'reader.release_all()' before iterating, or use 'for part in reader: ...' only once.
deprecated multipart-reader is no longer actively developed. For new projects, use aiohttp's built-in multipart handling or python-multipart.
fix Replace with python-multipart or aiohttp
gotcha The reader does not automatically decode file content. Body parts are returned as bytes; you must manually decode if text is expected.
fix Call part.text (which decodes) or part.file for raw bytes.
gotcha MultipartReader expects a BytesIO-like object, not a file path or string. Passing a string will fail silently.
fix Wrap your data in io.BytesIO(...) before passing.

Parse multipart/form-data from bytes and headers.

from multipart_reader import MultipartReader
import io

# Example multipart data
body = b'--boundary\r\nContent-Disposition: form-data; name="field1"\r\n\r\nvalue1\r\n--boundary--'
headers = {'Content-Type': 'multipart/form-data; boundary=boundary'}

reader = MultipartReader.from_response(io.BytesIO(body), headers)
parts = []
reader.release_all()  # iterate all parts
for part in reader:
    print(part.name, part.text)
    parts.append(part)
print('Done')