Skip to content

FastAPI

POST Multiple Multipart-Encoded Files You can send multiple files in one request. For example, suppose you want to upload image files to an HTML form with a multiple file field "images":

To do that, just set files to a list of tuples of (form_field_name, file_info):

url = 'https://httpbin.org/post' multiple_files = [ ('images', ('foo.png', open('foo.png', 'rb'), 'image/png')), ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))] r = requests.post(url, files=multiple_files) r.text { ... 'files': {'images': 'data:image/png;base64,iVBORw ....'} 'Content-Type': 'multipart/form-data; boundary=3131623adb2043caaeb5538cc7aa0b3a', ... } Warning It is strongly recommended that you open files in binary mode. This is because Requests may attempt to provide the Content-Length header for you, and if it does this value will be set to the number of bytes in the file. Errors may occur if you open the file in text mode.

Backgrourd Task

https://www.fastapitutorial.com/blog/fastapi-background-tasks/

https://github.com/encode/starlette/tree/597071cd510be0405d21cc9f89a3b1da6e5af010

Logging with python

https://dev.to/tomas223/logging-tracing-in-python-fastapi-with-opencensus-a-azure-2jcm

https://requests.readthedocs.io/en/latest/user/advanced/#ca-certificates

Dependencies

Starlette only requires anyio, and the following dependencies are optional:

httpx - Required if you want to use the TestClient. jinja2 - Required if you want to use Jinja2Templates. python-multipart - Required if you want to support form parsing, with request.form(). itsdangerous - Required for SessionMiddleware support. pyyaml - Required for SchemaGenerator support. You can install all of these with pip3 install starlette[full].

Choose

Uvicorn supports HTTP/1.1 and WebSockets.

HTTP/1.1, HTTP/1.2 and HTTP/1.3