Use `python-multipart` to parse forms and files

I just stumbled with python-multipart. It looks really interesting because you can actually work with its stream processing engine to deal with files (something I think would be nice to have in Sanic) and parameters. It haves some neat examples and I don’t think it would be hard to do it. The only con I see would be:

  • Add a new dependency

One thing I don’t know if it’s a con or not (@ahopkins, your expertise here would be awesome), is that python-multipart is licensed under the Apache License version 2.0, which as a dependency I don’t know the caveats of its usage.

Even if the license would not be an issue but adding another dependency is, I guess it may help a lot of people to make their own protocol implementations using it if absolutely required.

Would it help sort the issues around #1314?

Note quite. It can sure help, since we would not need to write this part by ourselves, as well make it easy to work with streams (instead of having all files in memory).


Regarding #1314, we’ll have to choose between:

  1. Leave as it is and let the developer do the work if he wants to (like using the mimetypes on top of the file_name);
  2. Make this a Config option key, so if True, will use mimetypes (default to False);
  3. Create a optional key in the File namedtuple (which would need to be a regular class this way), to add the guess_type result from mimetypes.