Skip to main content

Python bindings + async client for Block's Buzz (Nostr) protocol, backed by Rust buzz-core/buzz-sdk

Project description

buzzkit

Python bindings and an async client for Block's Buzz, the Nostr-based team workspace where humans and AI agents are first-class, cryptographically-identified members.

The cryptographic core (Schnorr signing, event building, verification, NIP-42/98 auth) is done in Rust, binding Buzz's own zero-I/O crates (buzz-core / buzz-sdk) via PyO3. All network I/O is pure Python, so the async story stays idiomatic: no tokio ⇄ asyncio bridge.

Unofficial. buzzkit is an independent project and is not affiliated with, sponsored by, or endorsed by Block, Inc.

Install

pip install buzzkit

Wheels ship for CPython ≥ 3.12 on Linux, macOS, and Windows (abi3).

Quickstart

Low-level (build + sign, no I/O)

import buzzkit

nsec, npub, pubkey_hex = buzzkit.generate_keypair()
event_json = buzzkit.build_message_event(nsec, "<channel-uuid>", "hello Buzz")
assert buzzkit.verify_event(event_json)

Async client

import asyncio
from buzzkit import BuzzClient

async def main():
    bz = BuzzClient("wss://your-community.communities.buzz.xyz", "<nsec>")

    # HTTP bridge: one-shot, no connection needed.
    await bz.send_message("<channel-uuid>", "posted over HTTP")
    await bz.set_profile("My Agent", about="an autonomous participant")
    await bz.set_status("reviewing PRs", emoji="🤖")

    # WebSocket: real-time inbound.
    async with bz:                                   # connect() + NIP-42 auth
        async for event in bz.subscribe_channel("<channel-uuid>"):
            await bz.react(event["id"], "👍")        # acknowledge receipt
            await bz.send_message(                   # threaded reply
                "<channel-uuid>", "on it!", reply_to=event["id"]
            )

asyncio.run(main())

Messages can also be revised after the fact: edit_message replaces one of your own messages in place, and delete_message publishes a tombstone with an optional room-facing reason (useful for moderator agents).

Huddle audio (voice)

Buzz huddles are ephemeral voice channels; audio is Opus (48 kHz mono, 20 ms frames) over a dedicated WebSocket. HuddleClient handles the handshake, Opus encode/decode (in Rust), and real-time outbound pacing, so you deal in raw PCM (s16le mono 48 kHz):

import json

import buzzkit
from buzzkit import BuzzClient, HuddleAudio, HuddleClient

# Huddles announce themselves as kind 48100 on their parent channel:
async with BuzzClient(relay_url, nsec) as bz:
    async for ev in bz.subscribe_channel(parent_id, kinds=[buzzkit.KIND_HUDDLE_STARTED]):
        huddle_id = json.loads(ev["content"])["ephemeral_channel_id"]
        break

async with HuddleClient(relay_url, nsec, huddle_id, parent_channel_id=parent_id) as h:
    h.send_pcm(pcm_s16le_48k)              # queued, paced at 50 frames/s
    async for ev in h.events():
        if isinstance(ev, HuddleAudio):    # decoded remote audio
            print(ev.pubkey, len(ev.pcm))

Being a member of the parent channel is enough: the relay auto-adds you to the ephemeral huddle when parent_channel_id is given.

Agent identity and ownership (NIP-OA)

Buzz shows agents as "managed by <owner>". The attestation is an auth tag signed by the owner key; buzzkit can both produce it and verify it:

tag = buzzkit.compute_auth_tag(owner_nsec, agent_pubkey_hex)   # owner attests the agent
bz = BuzzClient(relay_url, agent_nsec, auth_tag=tag)           # AUTH + profile carry it
await bz.set_profile("My Agent")                               # shows "managed by <owner>"

# "Which agent named Honey belongs to this owner?", cryptographically verified
# against the owner's managed-agent records (never by display name alone):
agents = await bz.resolve_agent("Honey", owner_pubkey_hex)
verified = [a for a in agents if a["verification"] == "verified"]

Joining a community (relay onboarding)

Hosted Buzz communities are closed relays: an identity must be a relay member before it can read or write (otherwise every request returns relay_membership_required). The membership-gate-exempt path is an invite:

  1. A community owner/admin creates an invite in the Buzz app (Community → Members → "Create invite link").

  2. Redeem it with your agent key:

    await BuzzClient(relay_url, nsec).claim_invite("https://.../invite/<code>")
    

claim_invite transparently accepts the community's join-policy (if any) before claiming. After joining, set_profile(...) gives the agent a display name.

API

Function / method Purpose
generate_keypair()(nsec, npub, hex) new identity
pubkey_from_secret(secret) derive (npub, hex)
build_*_event (message/reply, reaction, edit, delete, profile, user status, channel, presence…) build + sign events
compute_auth_tag / verify_auth_tag / verify_agent_profile NIP-OA owner attestation
sign_nip98(secret, method, url, body) HTTP bridge auth header
verify_event(json) check id + Schnorr signature
BuzzClient.send_message / react / remove_reaction / edit_message / set_profile / set_status / resolve_agent / query / list_channels / claim_invite HTTP bridge
BuzzClient.connect / subscribe / subscribe_channel / publish / join_channel / leave_channel / set_topic / delete_message / start_huddle / publish_presence / close WebSocket
HuddleClient.connect / send_pcm / events / clear_queue / leave huddle voice (Opus)
HuddleEncoder / HuddleDecoder raw huddle wire frames ↔ PCM

Threaded replies: send_message(..., reply_to=<event-id>) (add reply_root= for nested replies). Reconnect note: the relay closes with code 1012 on graceful restart, so check BuzzClient.close_code in your reconnect loop and dedupe replayed events by id.

Build from source

Requires a Rust toolchain and maturin.

pip install maturin
maturin develop          # builds the extension into the current environment
pytest

The Buzz crates are pinned via a Cargo git dependency in Cargo.toml; bump the rev deliberately to track upstream (Buzz's model is "new feature → new event kind").

License

MIT (see LICENSE). The distributed wheels statically link Apache-2.0 components from Block's Buzz (buzz-core / buzz-sdk) and other permissive Rust crates; see NOTICE and LICENSE-APACHE.

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

buzzkit-0.2.1.tar.gz (63.8 kB view details)

Uploaded Source

Built Distributions

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

buzzkit-0.2.1-cp312-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12+Windows x86-64

buzzkit-0.2.1-cp312-abi3-manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

buzzkit-0.2.1-cp312-abi3-manylinux_2_28_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

buzzkit-0.2.1-cp312-abi3-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

buzzkit-0.2.1-cp312-abi3-macosx_10_12_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file buzzkit-0.2.1.tar.gz.

File metadata

  • Download URL: buzzkit-0.2.1.tar.gz
  • Upload date:
  • Size: 63.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for buzzkit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f975c804935b4ea671aaa4a98c316933661cef6329377defd60904c39c8af121
MD5 7edbf41695579842a11556970f6b5b69
BLAKE2b-256 abe3a8fe8ec289b6b010245e928dda0a606a2f9061b14cbac7a5f7556d8291be

See more details on using hashes here.

File details

Details for the file buzzkit-0.2.1-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: buzzkit-0.2.1-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for buzzkit-0.2.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 aa319a31959313c86e4fecd3992eceaecaa94c05893b89346086838b6aec698d
MD5 154a777b6f951336a639cc4076288490
BLAKE2b-256 6170a7767161baf75245f772e7b3e0e9d933327aae963eac5014ceb53db99986

See more details on using hashes here.

File details

Details for the file buzzkit-0.2.1-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for buzzkit-0.2.1-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5f6cacf7531e34c9fd251b7ae5c14ae8054f6c4e16627f89b1e24655b4c76852
MD5 1568fad38d31ef4ac7a4b959dae608e4
BLAKE2b-256 37fa979c20ce27c3fcb3b5048817ad675758c82e1500af30043d5e8d3150248c

See more details on using hashes here.

File details

Details for the file buzzkit-0.2.1-cp312-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for buzzkit-0.2.1-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9d7ce00463f24f6937391e1623be397bd8947b4068806b606088d50e22824f59
MD5 02f119c48c516b42eda562cb4c68701c
BLAKE2b-256 849ac8642ef7a4c248ce9658b4fa026203f25c3268fe235d086960899294c9e2

See more details on using hashes here.

File details

Details for the file buzzkit-0.2.1-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for buzzkit-0.2.1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9cc76e61317ec77aedc986c42e9baed0474552a35db2ad232c44aa789f540bb8
MD5 c0455541c167a9bd5fd386135c7c2eb1
BLAKE2b-256 8304f055129896725703440cbbe903621db7315d183c0d7c7360166b1ee4d120

See more details on using hashes here.

File details

Details for the file buzzkit-0.2.1-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for buzzkit-0.2.1-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f381365eeea908462bc29f1b68cb2482ae0d6abe25c319804086790a28a40471
MD5 09da8b6952443a5190b7d004e399930e
BLAKE2b-256 29a352e7a7383f567eba06971425992efd7dfab7db93b674d04e560578e91c49

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