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 by default, and provides a modern alternative to REST. It includes examples for Django, FastAPI, and Flask.
To learn more about BLEST, please visit the website: https://blest.jhunt.dev
For a front-end implementation in React, please visit https://github.com/jhuntdev/blest-react
Features
- Built on JSON - Reduce parsing time and overhead
- Request Batching - Save bandwidth and reduce load times
- Compact Payloads - Save even more bandwidth
- Single Endpoint - Reduce complexity and facilitate introspection
- Fully Encrypted - Improve data privacy
Installation
Install BLEST Python from PyPI.
python3 -m pip install blest
Usage
Router
The following example uses Flask, but you can find examples with other frameworks here.
from flask import Flask, make_response, request
from blest import Router
# Instantiate the Router
router = Router({ 'timeout': 1000 })
# Create some middleware (optional)
@router.before_request
async def user_middleware(body, context):
context['user'] = {
# user info for example
}
return
# Create a route controller
@router.route('greet')
async def greet_controller(body, context):
return {
'greeting': f"Hi, {body['name']}!"
}
# Instantiate a Flask application
app = Flask(__name__)
# Handle BLEST requests
@app.post('/')
async def index():
result, error = await router.handle(request.json, { 'headers': request.headers })
if error:
resp = make_response(error, error.status or 500)
resp.headers['Content-Type'] = 'application/json'
else:
resp = make_response(result, 200)
resp.headers['Content-Type'] = 'application/json'
return resp
HttpClient
from blest import HttpClient
async def main():
# Create a client
client = HttpClient('http://localhost:8080', {
'max_batch_size': 25,
'buffer_delay': 10,
'http_headers': {
'Authorization': 'Bearer token'
}
})
# Send a request
try:
result = await client.request('greet', { 'name': 'Steve' })
# Do something with the result
except Exception as error:
# Do something in case of error
License
This project is licensed under the MIT License.
Metadata
Release files for blest 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| blest-1.0.3.tar.gz | 8.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| blest-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / blest-1.0.3.tar.gz
| Download URL | blest-1.0.3.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c47f095afad4abeba9470656e28d5bb224fc983b56cb2707cdf8233e4c72d63
|
|
BLAKE2b-256 checksum How to use checksums |
508d5e065057c823346eae30d48c001704a7ba0cb979780bf65cde95e2fb34d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.6
|
Release files / blest-1.0.3-py3-none-any.whl
| Download URL | blest-1.0.3-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27889d4e67345096a63de458d34eac92b3d2f670531cf11f7165c33058f7539a
|
|
BLAKE2b-256 checksum How to use checksums |
0a0f6a752d09ebe2087b4af208f4e3aed5f7456d8aae62b6dddcf17985b374d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.6
|