Skip to main content

The Python reference implementation of BLEST (Batch-able, Lightweight, Encrypted State Transfer)

Project description

BLEST Python

The Python reference implementation of BLEST (Batch-able, Lightweight, Encrypted State Transfer), an improved communication protocol for web APIs which leverages JSON, supports request batching and selective returns, and provides a modern alternative to REST. It includes examples for Django, FastAPI, and Flask.

To learn more about BLEST, please refer to the white paper:


  • Built on JSON - Reduce parsing time and overhead
  • Request Batching - Save bandwidth and reduce load times
  • Compact Payloads - Save more bandwidth
  • Selective Returns - Save even more bandwidth
  • Single Endpoint - Reduce complexity and improve data privacy
  • Fully Encrypted - Improve data privacy


Install BLEST Python from PyPI.

pip install blest



Use the create_server function to create a standalone HTTP server, or use the create_request_handler function to create a request handler suitable for use in an existing Python application. Both functions allow you to define middleware in your router.


from blest import create_server

# Create some middleware (optional)
def auth_middleware(params, context):
    context.user = {
    raise Exception('Unauthorized')

# Create a route controller
def greet_controller(params, context):
  return {
    'greeting': f'Hi, {}!'

# Define your router
router = {
  'greet': [auth_middleware, greet_controller]

run = create_server(router)

if __name__ == '__main__':


The following example uses Flask, but you can find examples with other frameworks here.

from flask import Flask, make_response, request
from blest import create_request_handler

async def greet(params, context):
  return {
    'geeting': 'Hi, ' + params.get('name') + '!'

routes = {
  'greet': greet

router = create_request_handler(routes)

app = Flask(__name__)'/')
async def index():
  result, error = await router(request.json)
  if error:
    resp = make_response(error, 500)
    resp.headers['Content-Type'] = 'application/json'
    resp = make_response(result, 200)
    resp.headers['Content-Type'] = 'application/json'
    return resp


Client-side libraries assist in batching and processing requests and commands. Currently available for React with other frameworks coming soon.


import React from 'react'
import { useBlestRequest, useBlestCommand } from 'blest-react'

// Use the useBlestRequest hook for fetching data
const MyComponent = () => {
  const { data, loading, error } = useBlestRequest('listItems', { limit: 24 })

  return (
    // Render your component

// Use the useBlestCommand hook for sending data
const MyForm = () => {
  const [submitMyForm, { data, loading, error }] = useBlestCommand('submitForm')
  const handleSubmit = (values) => {
    return submitMyForm(values)

  return (
    // Render your form


We actively welcome pull requests. Learn how to contribute for more information.


This project is licensed under the MIT License.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

BLEST-0.0.4.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

BLEST-0.0.4-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page