Streaming parser for multipart/form-data
Project description
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 Poetry installed.
Git clone the repository -
git clone https://github.com/siddhantgoel/streaming-form-data
Install the packages required for development -
poetry install
That’s basically it. You should now be able to run the test suite -
poetry run py.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for streaming-form-data-1.7.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20f6b8371587b960b43baee4de63f7d33c67919e199dea416d835611a0edcaca |
|
MD5 | e5fbf216d8696972da1d1a90d46c74bd |
|
BLAKE2b-256 | 278f642c1a86ab1eea7a5bdee698464d3de81ed6728103bc02f558c3a09f8fbe |