Skip to content

defnull/multipart

Repository files navigation

Python multipart/form-data parser

Tests Status Latest Version License

This module provides a fast incremental non-blocking parser for multipart/form-data [HTML5, RFC7578], as well as blocking alternatives for easier use in WSGI or CGI applications:

  • PushMultipartParser: Fast SansIO (incremental, non-blocking) parser suitable for ASGI, asyncio and other IO, time or memory constrained environments.
  • MultipartParser: Streaming parser that reads from a byte stream and yields memory- or disk-buffered MultipartPart instances.
  • WSGI Helper: High-level functions and containers for WSGI or CGI applications with support for both multipart and urlencoded form submissions.

Features

  • Pure python single file module with no dependencies.
  • Optimized for both blocking and non-blocking applications.
  • 100% test coverage with test data from actual browsers and HTTP clients.
  • High throughput and low latency (see benchmarks).
  • Predictable memory and disk resource consumption via fine grained limits.
  • Strict mode: Spent less time parsing malicious or broken inputs.

Scope and compatibility

All parsers in this module implement multipart/form-data as defined by HTML5 and RFC7578, supporting all modern browsers or HTTP clients in use today. Legacy browsers (e.g. IE6) are supported to some degree, but only if the required workarounds do not impact performance or security. In detail this means:

  • Just multipart/form-data, not suitable for email parsing.
  • No multipart/mixed support (deprecated in RFC7578).
  • No base64 or quoted-printable transfer encoding (deprecated in RFC7578).
  • No encoded-word or name=_charset_ encoding markers (deprecated in HTML5).
  • No support for clearly broken clients (e.g. invalid line breaks or headers).

Installation

pip install multipart

Documentation

Examples and API documentation can be found at: https://multipart.readthedocs.io/

License

Code and documentation are available under MIT License (see LICENSE).