Skip to main content

SBP Python Client

Python SDK for the Stigmergic Blackboard Protocol.

Installation

pip install sbp-client

Quick Start

from sbp import SbpClient, ThresholdCondition

# Connect to the blackboard
with SbpClient("http://localhost:3000") as client:
    # Emit a pheromone
    client.emit(
        trail="market.signals",
        type="volatility",
        intensity=0.8,
        payload={"symbol": "BTC-USD", "vix": 45.2},
    )

    # Sniff the environment
    result = client.sniff(trails=["market.signals"])
    for p in result.pheromones:
        print(f"{p.trail}/{p.type}: {p.current_intensity:.2f}")

Local Mode (No Server Required)

You can run SBP entirely in-memory within a single process. This is useful for testing, simulations, or simple multi-agent scripts where you don't want to manage a separate server process.

from sbp import SbpClient, SbpAgent

# Client in local mode
with SbpClient(local=True) as client:
    client.emit("local.test", "signal", 0.9)

# Agent in local mode
# Note: In a single process, all local=True instances share the same blackboard state.
agent = SbpAgent("my-agent", local=True)

@agent.when("local.test", "signal", value=0.5)
async def handle(trigger):
    print("Received signal locally!")

Async Usage

import asyncio
from sbp import AsyncSbpClient, ThresholdCondition

async def main():
    async with AsyncSbpClient() as client:
        # Emit
        await client.emit("signals", "event", 0.7)

        # Register a scent (trigger condition)
        await client.register_scent(
            "my-scent",
            condition=ThresholdCondition(
                trail="signals",
                signal_type="event",
                aggregation="max",
                operator=">=",
                value=0.5,
            ),
        )

        # Subscribe to triggers via WebSocket
        async def on_trigger(trigger):
            print(f"Triggered! {trigger.scent_id}")

        await client.subscribe("my-scent", on_trigger)

asyncio.run(main())

Declarative Agent Framework

from sbp import SbpAgent, TriggerPayload, run_agent

agent = SbpAgent("my-agent", "http://localhost:3000")

@agent.when("tasks", "new_task", operator=">=", value=0.5)
async def handle_task(trigger: TriggerPayload):
    print(f"Got task: {trigger.context_pheromones}")
    await agent.emit("tasks", "completed", 1.0)

run_agent(agent)

API Reference

SbpClient / AsyncSbpClient

Method Description
emit(trail, type, intensity, ...) Deposit a pheromone
sniff(trails, types, ...) Read environment state
register_scent(scent_id, condition, ...) Register a trigger
deregister_scent(scent_id) Remove a trigger
subscribe(scent_id, handler) Listen for triggers (async only)
inspect(include) Get blackboard metadata
evaporate(...) Force cleanup

Condition Types

# Simple threshold
ThresholdCondition(
    trail="market.signals",
    signal_type="volatility",
    aggregation="max",  # sum, max, avg, count, any
    operator=">=",      # >=, >, <=, <, ==, !=
    value=0.7,
)

# Composite (AND/OR/NOT)
CompositeCondition(
    operator="and",
    conditions=[condition1, condition2],
)

# Rate-based
RateCondition(
    trail="events",
    signal_type="click",
    metric="emissions_per_second",
    window_ms=10000,
    operator=">=",
    value=5.0,
)

Decay Models

from sbp.types import exponential_decay, linear_decay, immortal

# Exponential (default) - half-life in milliseconds
decay = exponential_decay(half_life_ms=300000)  # 5 minutes

# Linear - rate per millisecond
decay = linear_decay(rate_per_ms=0.0001)

# Immortal - never decays
decay = immortal()

License

MIT

Metadata

Release files for sbp-client 0.2.1

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

Source distribution (sdist)

Source distribution for sbp-client 0.2.1
File Size Uploaded Provenance Actions
sbp_client-0.2.1.tar.gz 20.7 kB Without provenance Details for sbp_client-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sbp-client 0.2.1
File Interpreter ABI Platform Actions
sbp_client-0.2.1-py3-none-any.whl Python 3 none any Details for sbp_client-0.2.1-py3-none-any.whl

Total release size: 41.9 kB

Release files / sbp_client-0.2.1.tar.gz

Download URL sbp_client-0.2.1.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9371b17c66061dc1265e5d3e7f9d5d3ed026ad54120274add3d49cfc2b312f6a
BLAKE2b-256 checksum
How to use checksums
7276bae62bf5f88f9a9531d4cf48538a4feb77888632d4d074efdb53f8ceb887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / sbp_client-0.2.1-py3-none-any.whl

Download URL sbp_client-0.2.1-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1724de37261cf585cf4836a4a0a803f64ee46eccd661e83c5989ebf1241b3c6
BLAKE2b-256 checksum
How to use checksums
62d51a108cf2218590c8f9ee51bf89c77167e06b7fa06285971d385a630bd8bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for sbp-client 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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