Streaming parser for multipart/form-data
Project description
streaming_form_data provides a Python parser for parsing
multipart/form-data input chunks. Chunk size is determined by the API user, but
currently there are no restrictions on what the size should be, since the parser
works byte-by-byte. Although, this also means that passing the entire input as a
single chunk should also work.
The main entry point is the StreamingFormDataParser class, which expects
a dictionary of request headers.
The parser is fed chunks of (byte) input, and takes action depending on what the
current byte is. In case it notices input that’s expected, it passes on the
input to the configured Target, which then decides what to do with it.
In case there’s a part that we don’t need, this input is simply discarded using
a NullTarget object.
Currently three targets are included with this library - ValueTarget,
FileTarget, and SHA256Target. ValueTarget stores the
input in memory, and FileTarget pipes the input to a file on disk. Any
new targets should inherit streaming_form_data.targets.BaseTarget and
define a data_received function.
Please note, that this library has only been tested with Python 3 (specifically, versions 3.3, 3.4, 3.5, and 3.6). Python 2.7 is not supported yet, but pull requests are always welcome!
Usage
>>> from streaming_form_data import StreamingFormDataParser
>>> from streaming_form_data.targets import ValueTarget, FileTarget
>>>
>>> headers = {'Content-Type': 'multipart/form-data; boundary=boundary'}
>>>
>>> parser = StreamingFormDataParser(headers=headers)
>>>
>>> parser.register('name', ValueTarget())
>>> parser.register('file', FileTarget('/tmp/file.txt'))
>>>
>>> parser.data_received(chunk)
Development
To work on this package, please make sure you have a working Python 3 installation on your system.
Create a virtualenv -
python -m venv venv && source venv/bin/activate.Git clone the repository -
git clone https://github.com/siddhantgoel/streaming-form-dataInstall the packages required for development -
pip install -r requirements.dev.txtInstall this package -
pip install ..You should now be able to run the test suite -
py.test tests/.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streaming_form_data-0.4.2.tar.gz.
File metadata
- Download URL: streaming_form_data-0.4.2.tar.gz
- Upload date:
- Size: 50.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17ff9fa7141f4081d7f220fe44a63d9089d1fd7b69d53e6483ed391df7987680
|
|
| MD5 |
78b2d26e06b32f63f97d3b8b02378a08
|
|
| BLAKE2b-256 |
7ac8e5f225298a920c978d8163a508c4c08ff739cada3a3c3ae948924135ef2d
|
File details
Details for the file streaming_form_data-0.4.2-py3.6-linux-x86_64.egg.
File metadata
- Download URL: streaming_form_data-0.4.2-py3.6-linux-x86_64.egg
- Upload date:
- Size: 152.1 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8581bffaef6476366166425cbb3719f8ac0f257bd73d93605b181564062119bf
|
|
| MD5 |
dad1892161c6c1ef46dd572770361220
|
|
| BLAKE2b-256 |
c6a13af04038aaa294c2dc98bb8f4a5297563fae3403e61173fd5f31929ee02d
|