Skip to content

thrum (Python)

the thrum client for a bee written in Python

A Python bee reaches humd through hum’s own client. Bee runs hum bee link, which enters the bee, signs its hello, reads humd’s verdict, reconnects when humd restarts, and checks every tone against the thrum. Every language gets that same client, so a Python bee behaves exactly as a Rust, TS, Go or C one.

import asyncio
from thrum import Bee, Chi, PetalKind, Role
async def main():
bee = Bee(hive="my-hive", as_="main", role=Role.NURSE, hello={"models": ["my-model"]})
def on_prompt(tone):
bee.send({"chi": Chi.UNFURL, "sid": tone["sid"], "petal": 0, "kind": PetalKind.TEXT, "text": "hello"})
bee.send({"chi": Chi.WILT, "sid": tone["sid"], "reason": "stop"})
bee.on(Chi.PROMPT, on_prompt)
await bee.start()
await bee.closed()
asyncio.run(main())
Bee(hive, as_, role, hello)a bee’s client; nothing runs until start
on(chi, fn), on_sid(sid, fn), off_sid(sid), on_any(fn)a tone goes to its sid’s handler, else its chi’s, else on_any
on_nestled(fn), on_astray(fn), on_advisory(fn)humd admitted the bee; humd went away; something to fix
await start()returns once humd admits the bee; raises Refused or LinkError
send(tone), hello(patch)send a tone, given a rid if it has none; change the hello
await close(), await closed()close the link; how the link ended

hum is found at $HUM_CLI, else on PATH, else ~/.local/bin/hum.

Every source under thrum/ is generated by cargo run -p codegen: chi.py and protocol.py from thrum-core, link.py and __init__.py from codegen/templates/python with the link’s constants from hum-thrum. examples/echo_bee.py is the bee the conformance run (cargo test -p hum --test conform) drives in every language.