Skip to content

siddhantgoel/streaming-form-data

Repository files navigation

Streaming multipart/form-data parser

image image Downloads Ruff

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

Testimonials

this speeds up file uploads to my Flask app by more than factor 10

Thanks a lot for your fix with streaming-form-data. I can finally upload gigabyte sized files at good speed and without memory filling up!

huge thanks to @siddhantgoel with his "streaming-form-data" that saves me from the slow file reads I get with @FastAPI!

Installation

$ pip install streaming-form-data

In case you prefer cloning the Github repository and installing manually, please note that main 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 FileTarget, NullTarget, GCSTarget, S3Target, ValueTarget
>>>
>>> headers = {"Content-Type": "multipart/form-data; boundary=boundary"}
>>>
>>> parser = StreamingFormDataParser(headers=headers)
>>>
>>> parser.register("name", ValueTarget())
>>> parser.register("file-local", FileTarget("/path/to/file.txt"))
>>> parser.register("file-s3", S3Target("s3://bucket/path/to/key"))
>>> parser.register("file-gcs", GCSTarget("gs://bucket/path/to/key"))
>>> 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.9+, uv, and task installed.

Since this package includes a C extension, please make sure you have a working C compiler available. On Debian-based distros this usually means installing the build-essentials package.

  1. Git clone the repository: git clone https://github.com/siddhantgoel/streaming-form-data

  2. Install the packages required for development: uv sync

  3. That's basically it. You should now be able to run the test suite: task test

Note that if you make any changes to Cython files (.pyx, .pxd, .pxi), you'll need to re-compile (task compile) and re-install streaming_form_data before you can test your changes.

About

Streaming (and fast!) parser for multipart/form-data written in Cython

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 14

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy