Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Streaming parser for multipart/form-data

Project description

https://github.com/siddhantgoel/streaming-form-data/workflows/streaming-form-data/badge.svg https://badge.fury.io/py/streaming-form-data.svg https://readthedocs.org/projects/streaming-form-data/badge/?version=latest https://img.shields.io/badge/code%20style-black-000000.svg

streaming_form_data provides a Python parser for parsing multipart/form-data input chunks (the most commonly used encoding when submitting data over HTTP through HTML forms).

Installation

$ pip install streaming-form-data

In case you prefer cloning the Github repository and installing manually, please note that master is the development branch, so stable is what you should be working with.

Usage

>>> from streaming_form_data import StreamingFormDataParser
>>> from streaming_form_data.targets import ValueTarget, FileTarget, NullTarget
>>>
>>> headers = {'Content-Type': 'multipart/form-data; boundary=boundary'}
>>>
>>> parser = StreamingFormDataParser(headers=headers)
>>>
>>> parser.register('name', ValueTarget())
>>> parser.register('file', FileTarget('/tmp/file.txt'))
>>> parser.register('discard-me', NullTarget())
>>>
>>> for chunk in request.body:
...     parser.data_received(chunk)
...
>>>

Documentation

Up-to-date documentation is available on Read the Docs.

Development

Please make sure you have Python 3.5+ and pip-tools installed.

  1. Git clone the repository - git clone https://github.com/siddhantgoel/streaming-form-data
  2. Install the packages required for development - pip install -r requirements-dev.txt
  3. That’s basically it. You should now be able to run the test suite - make test.

Please note that tests/test_parser_stress.py stress tests the parser with large inputs, which can take a while. As an alternative, pass the filename as an argument to py.test to run tests selectively.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for streaming-form-data, version 1.7.1
Filename, size File type Python version Upload date Hashes
Filename, size streaming-form-data-1.7.1.tar.gz (743.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page