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

Features

  • JSON Payloads - 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_request_handler function to create a request handler suitable for use in a Python application. 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') + '!'
  }

router = create_request_handler({
  'greet': greet
})

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

  // Render your component
  // ...
};

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

  // 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.

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.3.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

BLEST-0.0.3-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file BLEST-0.0.3.tar.gz.

File metadata

  • Download URL: BLEST-0.0.3.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for BLEST-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2fe2b12684176eec1eef5175edd4062f09e8dd3e7701e18c6514e4125b509336
MD5 c1fe51a0cd6723d99ab34aa2e54f6a4b
BLAKE2b-256 a04faf6971be85ac49c4f5c7ec86efbe6fed304553a2e1e0b0185944444d5f92

See more details on using hashes here.

File details

Details for the file BLEST-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: BLEST-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for BLEST-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 24d42430ba918e50395d024a2f4844c8eb0c80835d46f7174260fec8fea7a17b
MD5 01e7ad1d6f158fda502ca4b87ff6a658
BLAKE2b-256 a2c62191029b186523cc94e51f448544fc435bea9adf7c0dad1d77d134fc0ffc

See more details on using hashes here.

Supported by

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