Flask-Batch
Batch multiple requests at the http layer. Flask-Batch is inpsired by how google cloud storage does batching.
It adds a /batch route to your API which can execute batched HTTP requests against your API server side. The client wraps several requests in a single request using the multipart/mixed content type.
Installation
pip install Flask-Batch
# to include the dependencies for the batching client
pip install Flask-Batch[client]
Getting Started
Server
from flask import Flask
from flask_batch import add_batch_route
app = Flask(__name__)
add_batch_route(app)
# that's it!
Client
The client wraps a requests session.
from flask_batch.client import Batching
import json
alice_data = bob_data = {"example": "json"}
with Batching("http://localhost:5000/batch") as s:
alice = s.patch("/people/alice/", json=alice_data)
bob = s.patch("/people/bob/", json=bob_data)
alice # <Response [200]>
alice.json() # {"response": "json"}
Why Batch?
Often the round-trip-time from a client to a server is high. Batching requests reduces the penalty of a high RTT, without the added complexity of request parallelization.
Batching Done Right
Often API designers will create custom batch endpoints for specific operations. Creating custom API endpoints for performing bulk operations usually end up being clunky. Each one ends up unique. This means more code to maintain, and more bugs.
It can be difficult to reason about bulk json API endpoints. For example, what happens on error? Does the bulk operation fail? continue? roll back?
Batching at the HTTP layer results in clear and expected behaviors that are easy to reason about. HTTP batching simply behaves the same way as all of the individual requests that are sent in the batch.
Status
This project is in alpha. I’m hoping to eventually get it approved as a flask extension.
Metadata
Release files for flask-batch 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-Batch-0.0.2.tar.gz | 7.9 kB | Without provenance | Details for Flask-Batch-0.0.2.tar.gz |
Release files / Flask-Batch-0.0.2.tar.gz
| Download URL | Flask-Batch-0.0.2.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c84b51bf8d874d4e1405140e8666a0602551efce0983115a3b1bcaffceefc00a
|
|
BLAKE2b-256 checksum How to use checksums |
6b2aaf2c708fd8c115f4b4fb6ad2c85be7f908cfc464e0c56b6c7792b5d31a4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|
Security for flask-batch 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.