Skip to main content

handshake-prompt (Python Server SDK)

Core network component for the Handshake Prompt Protocol (HPP) — session pairing, token auth, HTTP + WebSocket transport.

Architecture

┌─────────────────────────────────────────┐
│  Application (your service)           │
│  form-fill UI, device pairing, etc.     │
└──────────────────┬──────────────────────┘
                   │ hooks + mode handlers
┌──────────────────▼──────────────────────┐
│  handshake_prompt (this package)        │
│  ProtocolEngine · Session · SessionStore│
│  auth · Flask adapter (HandshakeManager)│
└──────────────────┬──────────────────────┘
                   │
         HTTP / WebSocket + X-Handshake-Token

Core transport (always included):

  • Session creation with 128-bit sid + 192-bit token
  • Token auth on all Agent endpoints
  • Rate limiting, TTL, dynamic extension
  • WebSocket real-time push

Application plugins (optional, in handshake_prompt.modes):

  • form-fill — schema validation, field ownership, missing-field detection
  • default — opaque key/value context for generic Agent interactions

Prompt text generation is not part of the core transport — use handshake_prompt.prompt.build_prompt() if you want a default template.

Install

pip install handshake-prompt

Quick start (Flask)

from flask import Flask
from flask_sock import Sock
from handshake_prompt import HandshakeManager

app  = Flask(__name__)
sock = Sock(app)
hm   = HandshakeManager(app, sock)   # HPP endpoints mounted

if __name__ == '__main__':
    app.run(port=5000)

Endpoints (default prefix /handshake):

Endpoint Method Auth Purpose
/handshake/session POST Browser cookie (your app) Create session
/handshake/context/<sid> GET X-Handshake-Token Agent reads state
/handshake/action/<sid> POST X-Handshake-Token Agent submits actions
/handshake/notify/<sid> POST Browser (optional) User-side edits
/handshake/diff/<sid> GET X-Handshake-Token Incremental changes
/ws/handshake/<sid> WS ?token= Real-time push

Using without Flask

from handshake_prompt import ProtocolEngine, SessionStore

store = SessionStore()
engine = ProtocolEngine(store=store, prefix='/api/pair')

payload, code = engine.create_session({'mode': 'device-pair', 'data': {}})
# Wire payload/code into your own framework adapter

Form-fill mode (optional plugin)

{
  "mode": "form-fill",
  "schema": [
    {"key": "name", "label": "Name", "type": "string", "required": true}
  ],
  "context": {}
}

Custom mode handler

from handshake_prompt.modes import DEFAULT_HANDLERS

class MyHandler:
    def setup_session(self, sess, body): ...
    def context_response(self, sess): ...
    def process_actions(self, sess, actions, stream, interval, cbs, broadcast): ...
    def process_notify(self, sess, key, value): ...
    def process_ws_message(self, sess, msg): ...

hm = HandshakeManager(app, sock, mode_handlers={
    **DEFAULT_HANDLERS,
    'my-mode': MyHandler(),
})

Hooks

@hm.on_create_session
def bind_owner(sess, request):
    sess.owner = flask_session.get('user_id')

@hm.on_action
def audit(sess, action, request):
    return True  # return False to veto

@hm.on_extend
def cap_extension(sess, extra_seconds, request):
    return min(extra_seconds, 1800)

Security defaults

  • Token: 192-bit entropy, timing-safe comparison
  • Session ID: 128-bit entropy
  • TTL: 30 min default, dynamically extendable
  • Rate limit: 60 req/min/session
  • WebSocket: token verified at connect time

See SPEC.md for full protocol details.

License

MIT

Metadata

Release files for handshake-prompt 0.2.0

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

Source distribution (sdist)

Source distribution for handshake-prompt 0.2.0
File Size Uploaded
handshake_prompt-0.2.0.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for handshake-prompt 0.2.0
File Interpreter ABI Platform
handshake_prompt-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.9 kB

Release files / handshake_prompt-0.2.0.tar.gz

Download URL handshake_prompt-0.2.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fcd972c5f25f86f035855649494092ab4df6f3767dd4075611a3daa84e269ba2
BLAKE2b-256 checksum
How to use checksums
881de7b544af65a151822086d20aa0519c1c9bf21046ab90a97627821175aed0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / handshake_prompt-0.2.0-py3-none-any.whl

Download URL handshake_prompt-0.2.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0abf92c49a46ea50c3b920d24db9ddda9537017ae69b177e15cbdab939d3103
BLAKE2b-256 checksum
How to use checksums
24087641d8952463592a05a95eee1af37b32334f8a6b334fa2b7b5266c77c8bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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