GithubHelp home page GithubHelp logo

flask-batch's Introduction

Flask-Batch

Travis CI build status GitHub license Latest Version

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.

flask-batch's People

Contributors

dtkav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flask-batch's Issues

not (too) update

This package looks pretty cool - but nothing has changed since couple of years before corrona :-)
Would be nice if it were checked and updated for python 3.13 or whatever.

Reference (use) results of previous sub-request in further sub-requests of the batch request

Would you consider anything like that? The idea is helpful when you have a real life scenario, let's say create an object, then create two more settings or children objects and want to attach them, and do it all in batch.

One of options that come into my mind is (in pseudo):

{
   (1) create parent object -> {'name': 'parent1'},
   (2) create child -> {'name': 'child1', 'parentId': '@[1].id'} (random syntax, we expect that result of first request will contain json field 'id' and server will allow to use it for subsequent sub-requests)
}

Would like to hear your opinion or alternative approaches.

Any interest in modernizing the library?

Hey there,

Do you have any interest in modernizing the library?

I've been experimenting with your code today and leaving the core functionality the same, I have striped out all of the py2 compat stuff and added type hints. I'd be happy to put together some PRs if you are interested.

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.