Skip to main content

psyclone-client (Python)

Talk to a running Psyclone system from outside it: post messages into the system by post name and receive what its triggers send out by trigger name, over UDP, TCP or WebSocket. Messages are CMSDK DataMessages, byte-identical with the C++ library (full or packed form). Pure Python, standard library only: one wheel for Python 3.8+ on every OS.

pip install psyclone-client
from psyclone_client import PsycloneClient, DataMessage

with PsycloneClient.websocket("ws://host:18600/phone", device="py-1") as psy:   # or .udp(host, port), .tcp(...)
    psy.on_trigger("Playout", lambda m: print("got", m.get_data("audio")))      # pushed by the system
    psy.post("AudioFrame", DataMessage().set_data("audio", b"..."))             # into the system
    reply = psy.request("Question", DataMessage().set_string("Text", "hi"), timeout=3)   # or None

The service it talks to (any Psyclone 2.3+ system):

<service name="Phone">
  <post name="AudioFrame" type="Mimir.Audio.Frame"/>
  <trigger name="Playout" type="Mimir.Playout.Chunk"/>
</service>
<interface name="PhoneTCP" port="18600" protocol="HTTP" service="Phone"/>           <!-- HTTP + WebSocket -->
<interface name="PhoneUDP" port="18600" ip="UDP" protocol="Message" service="Phone"/>

DataMessage

m = DataMessage().set_string("Name", "x").set_int("N", 42).set_double("Gain", 0.7).set_data("pcm", b"\0\1")
m["Other"] = 5                     # by Python type: str, int, float, bytes, DataMessage
m.to_bytes(); m.to_packed_bytes()  # the two wire forms
DataMessage.from_bytes(wire)       # either form

setString/getInt/getBytes/fromBytes... (the names of the C++ binding cmsdk3) work too, so code moves between the two. Header fields are attributes (time, serial, type, tag, ...).

Behaviour

  • post(name, msg) sets PsyPost (and PsyDevice) on msg and sends it; False when the pipe is down (nothing is queued; reliability belongs in the modules, as with every Psyclone service).
  • Received messages go to the on_trigger(name, handler) handlers by their PsyTrigger, then to on_any_message. Handlers run on the reader thread; pass callback=loop.call_soon_threadsafe (or any callable that runs a function) to move them, e.g. into asyncio.
  • request() / request_async() add PsyClientRequestID and wait for the reply carrying it back. A responder that copies the request (the built-in Simple crank) does; one that builds a new message must copy PsyClientRequestID and PsyServiceConnection.
  • TCP and WebSocket reconnect by themselves (0.5 s doubling to 10 s, on_state_changed); WebSocket pings every 20 s. A UDP service learns a peer's address from its first datagram; with device set it follows the peer across address changes.
  • Packed form: packed_mode=PackedMode.AUTO (the default) sends the full form until the service shows it reads the packed form (its keepalive reply, Psyclone 2.3.2+), then packed (about 3x less overhead); PackedMode.FULL / PackedMode.PACKED (or packed=False / packed=True) force one. Psyclone answers in the form a peer used.
  • Keepalive every keepalive_interval (15 s) and right after connecting: a Psyclone 2.3.2+ service answers with the round-trip time, PsyVersion and (2.3.2+) PsyFeatures, and posts nothing; an older one drops it. Once the service has answered, keepalive_miss_limit (3) silent intervals mean a dead link: TCP/WebSocket reconnect, UDP reports the link down and opens a new socket. Reconnect delays have +-20 % jitter (reconnect_jitter).
  • stats() returns a ConnectionStats snapshot (connects, drops, failures, bytes, messages, requests, keepalives, RTT last/smoothed/min/max, server version and features, last error); wait_server(timeout).
  • WebSocket text frames: send_text(), on_text(handler).
  • PsycloneHttp(base_url).request(path, post, fields) for a service's HTTP interface.

Remote modules (Psyclone 2.3.2+)

RemoteModule makes this process a module of the system: the PsySpec declares <module name="Asr" type="remote" service="Modules"> (triggers, posts, retrieves, queries) and a service with <modules auth="key|token|none"> hosts it (User Guide ch. 11, "Remote modules").

from psyclone_client import PsycloneClient, RemoteModule, RemoteModuleError, Auth, DataMessage
psy = PsycloneClient.tcp("host", 18700, "asr-box-1")
asr = RemoteModule.attach(psy, "Asr", Auth.key("psy_<id>_<secret>"))   # or Auth.token(t), Auth.none()
print(asr.posts, asr.triggers)                                        # the contract, from the server
asr.on_trigger("Audio", lambda m: asr.post("Text", DataMessage().set_string("Text", recognise(m))))
recent = asr.retrieve("Recent", max_count=5)                          # list of DataMessage
notes = asr.query("Notes", DataMessage().set_string("List", "1"))
asr.on_stop(lambda reason: pause()); asr.on_detached(print)
m = asr.wait_for_new_message(1.0)                                     # crank-style pull; asr.current_trigger_name
asr.close()                                                           # detach

Refusals raise RemoteModuleError with .status = the host's PsyStatus (denied, unknown, busy, timeout, ...). An API key's secret never travels (HMAC proof on a hello nonce); the key's account needs modules.attach.<Module>. After a reconnect the module resumes its session (Resume + LastSeq): the host replays the triggers it missed (its resume buffer, 256 messages / 5 s by default) and reports what it could not keep through on_dropped(count, from_seq, reason); after a lease expiry it attaches again (auto_reattach).

Dynamic modules (a host with <modules allowdynamic="yes"> and an <allow> policy) build their contract at run time; every type is checked against <allow> (a refusal raises denied):

from psyclone_client import Trigger
ext = RemoteModule.attach(psy, "Ext.Logger")                      # a name inside <allow names>
ext.subscribe(Trigger("All", "Mimir.*").max_age(1000).has_key("Text"))
ext.declare_post("Note", "Ext.Logger.Note")
ext.declare_parameter("Mode", "quiet"); ext.on_parameter(lambda n, v: print(n, v))
rows = ext.retrieve_from("ConvWB", type="Mimir.Asr.*", max_count=20)   # ad hoc, inside <allow retrieve>
reply = ext.query_catalog("FileCat", DataMessage().set_string("Query", "List"))
ext.unsubscribe("All")

The subscriptions and declarations are kept and sent again when a new session starts (after a lease expiry). retrieve, query, post_confirmed and describe block for the reply: call them from a handler only when the client has a callback that runs handlers on another thread.

Not to be confused with cmsdk3, the C++ binding that runs Python cranks inside Psyclone; this package is for programs outside it. Licence: BSD with the CADIA clause (CMSDK).

Tests

python3 -m unittest discover -s tests        # codec conformance (C++ golden messages), local transports, keepalive
# live, against bin/<arch>/Psyclone spec=CMSDK/tools/client-test.xml port=18700:
PSYCLONE_LIVE=127.0.0.1 python3 -m unittest tests.test_client tests.test_keepalive
# remote modules: start their own Psyclone (ports 18770-18774 and 18780-18784)
PSYCLONE_BIN=<psyclone2>/bin/linux64/Psyclone python3 -m unittest tests.test_remote_module tests.test_remote_module_dynamic

Metadata

Release files for psyclone-client 2.3.2

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

Source distribution (sdist)

Source distribution for psyclone-client 2.3.2
File Size Uploaded Provenance Actions
psyclone_client-2.3.2.tar.gz 51.8 kB Without provenance Details for psyclone_client-2.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for psyclone-client 2.3.2
File Interpreter ABI Platform Actions
psyclone_client-2.3.2-py3-none-any.whl Python 3 none any Details for psyclone_client-2.3.2-py3-none-any.whl

Total release size: 89.2 kB

Release files / psyclone_client-2.3.2.tar.gz

Download URL psyclone_client-2.3.2.tar.gz
Size 51.8 kB
Tags Source
SHA-256 checksum
How to use checksums
60057718227cd469724e82234507a14464262ec2d74a4b34dc081d7d86bdb3b2
BLAKE2b-256 checksum
How to use checksums
769819fa11708c3869bcaa688285a18b3ce4055ec2aea3fa4b846d581a8171d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / psyclone_client-2.3.2-py3-none-any.whl

Download URL psyclone_client-2.3.2-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed34d5c38b0e4c6a222d5ea0cec17339d11b153bd55b3dc9f1eb1728a9bcf829
BLAKE2b-256 checksum
How to use checksums
19a03eea2f7579abeb13bd980350495674a5f047d2462d49109909575a92ca8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for psyclone-client 2.3.2

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.

Release history Release notifications | RSS feed

This release

2.3.2 This release

2 release files No provenance

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