Skip to main content

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: https://jhunt.dev/BLEST%20White%20Paper.pdf

Features

  • 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

Installation

Install BLEST Python from PyPI.

pip install blest

Usage

Server-side

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.

create_server

from blest import create_server

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

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

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

run = create_server(router)

if __name__ == '__main__':
  run()

create_request_handler

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__)

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

Client-side

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

React

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
  )
}

Contributing

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

License

This project is licensed under the MIT License.

Release files for blest 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blest 0.0.4
File Size Uploaded
BLEST-0.0.4.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blest 0.0.4
File Interpreter ABI Platform
BLEST-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 7.0 kB

Release files / BLEST-0.0.4.tar.gz

Download URL BLEST-0.0.4.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ddca8f7222c88958904ea62d8694fafcbc563d13c5ff70b68c796a89113b098c
BLAKE2b-256 checksum
How to use checksums
1eaab69acdbf48d438b5212cf9bed7ad7baca4587ce1826337be0396f055c63e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release files / BLEST-0.0.4-py3-none-any.whl

Download URL BLEST-0.0.4-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef9c6ebc48b931f3709b6fbb775968074878b642a40edcd51ff423e2f4a65dbc
BLAKE2b-256 checksum
How to use checksums
8876e1ac75814c384e169073330ee35f82b32ddba8b0ef7f3ef2fd1af3240fe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release history Release notifications | RSS feed

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

This release

0.0.4 This release

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page