Skip to main content

iosignal (Python)

English | 한국어

Python client for IOSignal, a real-time signal broker for web apps, devices and boards. The same package runs on CPython 3.10+ (asyncio or blocking) and on MicroPython boards (ESP32, ESP32-C3, ESP32-S3).

  • Signals, subscriptions, RPC calls and server ping, byte-compatible with the JS client
  • Boho login with ENC_488 encryption, end-to-end sealed signals
  • WebSocket (ws://, wss://) and TCP (cong://, the same link Arduino boards use)
  • Device rules: make devices that appear in IOSignal apps, find and command them
  • MicroPython: a board becomes a device, and a sealed remote REPL with file transfer (iosignal-repl)

Install

pip install iosignal

The only dependency is websockets.

Blocking (scripts)

from iosignal.sync import IOSignal

with IOSignal("wss://io.iosignal.net/ws") as io:
    io.ready()                              # returns the CID
    inbox = io.listen("room#t")             # without a handler: a queue.Queue
    io.signal("room#t", "hello")
    print(inbox.get(timeout=3).text)
    print(io.ping_server(), "ms")

Handlers run on a background thread. They may send (signal() and so on), but not wait (ready(), call()).

asyncio

import asyncio
from iosignal import IOSignal

async def main():
    io = IOSignal("wss://io.iosignal.net/ws")
    io.auth("dev1", "key")                  # or io.auth("dev1.key"); anonymous without it
    io.listen("room#t", lambda s: print(s.tag, s.args))
    io.on_event("state", print)
    async with io:
        await io.ready()
        io.signal("room#t", "value", b"\x01")
        print(await io.ping_server(), "ms")
        await asyncio.sleep(10)

asyncio.run(main())
  • Sending (signal, subscribe, unsubscribe, iam) is synchronous and returns False without a connection.
  • Handlers are functions or coroutines and receive a Signal (tag, type, data, text, args, is_direct).
  • Events: state, ready, message, direct, server_signal, iam, pong, over_size, error.
  • Subscriptions are remembered and sent again after a reconnect. A logged-in ws:// connection is encrypted with ENC_488.
  • await io.call(target, topic, *args) calls a server service (RpcError on failure).
  • await io.ping_server(timeout=3.0) returns the round trip in milliseconds. It raises PingError with code NOT_READY, BUSY (one at a time), TIMEOUT, CONNECTION_CLOSED or INVALID_ARGUMENT.

Values and payload types (as JS signal())

signal(tag, ...) type receiver args
nothing EMPTY []
"text", 42, 3.5 TEXT ["text"], ["42"]
b"..." BINARY [b"..."]
{...}, [...], None OBJECT [value]
several values, no bytes MJSON [value, ...]
several values with bytes MBA [value, ...]

TCP and E2E signals

  • A cong://host:port address connects over TCP. Logged in, it is encrypted with ENC_488, and a TCP switcher redirect is followed: IOSignal("cong://io.iosignal.net:55488").
  • io.signal_e2e(tag, data, key) seals data with a key the server never sees (logged-in connections only). A received Signal with e2e True opens with io.decrypt_e2e(sig.data, key) (None for a wrong key or a forgery).

Devices

from iosignal.sync import IOSignal

with IOSignal("wss://io.iosignal.net/ws") as io:
    lamp = io.device("Python lamp:Living room", type="dimmer.1", state={"on": "0", "level": "60"})
    io.ready()
    io.run(lambda: lamp.set(level=80))      # change device state on the client's thread

    for d in io.discover():                 # devices on the same home channel (same public IP)
        print(d.id, d.name, d.category, d.ui.type, d.fields)
    io.command(d, "toggle")

A Device answers #search, announces $panel, $view, $name, $ui, $state and #notify in that order, and answers every command with $state. on_command(cmd, device) returning True means it handled the command; otherwise the standard commands apply (on, off, toggle, all=, key=value). Examples: examples/virtual_lamp.py, examples/virtual_home.py (five devices, --minutes to stop).

MicroPython boards

Install on a board

With network on the board (MicroPython 1.28+):

import mip
mip.install("github:remocons/iosignal-python")

or from a computer: mpremote mip install github:remocons/iosignal-python. tools/mpy_board_setup.py installs precompiled .mpy files over USB with the board configuration, and tools/mpy_wifi_setup.py writes the Wi-Fi settings.

The board as a device

import iosignal.board
from machine import Pin

iosignal.board.start()
led = Pin(2, Pin.OUT)
lamp = iosignal.board.device(type="light.1", state="on=0",
                             on_change=lambda d: led.value(d.get("on") == "1"))
lamp.set(on="1")   # changes from your own code show in the apps at once
  • One board is one CID and one device. Options: name, type, state ("on=0;level=50", key order kept), buttons, panel, view, on_command(cmd, device), on_change(device).
  • Callbacks run in the link's timer: keep them short. Their errors go to board.status() and the link keeps running.
  • Other devices: board.subscribe("abc-123@$state", fn) and board.signal("abc-123@", "r1=1"). Example: examples/board_relay_buttons.py.
  • Without code: a "device" entry in /iosignal.json, for example {"type": "relay4.1", "pins": [16, 17, 18, 19], "invert": true}, makes a pin device (light.1, dimmer.1 PWM, relay4.1, switch2.1~8.1).

Remote REPL: iosignal-repl

A board with a REPL key can be used like mpremote from anywhere, through IOSignal. Sessions are sealed with the REPL key and one-time X25519 keys (forward secrecy), so the broker relays only sealed bytes.

export REPL_KEY_FILE=~/.iosignal/repl-myboard.key   # or -k FILE
iosignal-repl find                    # boards on the same network
iosignal-repl repl                    # interactive (Ctrl-] leaves, Ctrl-C goes to the board)
iosignal-repl exec "print(1+1)"       # streamed output, exit code 1 on an exception
iosignal-repl run app.py              # run a local file without copying it
iosignal-repl ls / | cat /main.py | get /log.txt | put main.py | rm /x | mkdir /d | rmdir /d | mv /a /b
iosignal-repl info | reset

Server: -s or IOSIGNAL_SERVER (default wss://io.iosignal.net/ws). Board: -b or IOSIGNAL_BOARD; without it, the only board on the network. Make a REPL key with tools/mpy_repl_key.py.

Not supported

JS echo and link.

Tests

python3 -m unittest discover -s tests          # no server needed
micropython tests/mpy_vectors.py               # byte layer on the MicroPython unix port

License

MIT

Metadata

Release files for iosignal 0.1.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 iosignal 0.1.0
File Size Uploaded Provenance Actions
iosignal-0.1.0.tar.gz 93.0 kB Without provenance Details for iosignal-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iosignal 0.1.0
File Interpreter ABI Platform Actions
iosignal-0.1.0-py3-none-any.whl Python 3 none any Details for iosignal-0.1.0-py3-none-any.whl

Total release size: 158.9 kB

Release files / iosignal-0.1.0.tar.gz

Download URL iosignal-0.1.0.tar.gz
Size 93.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9adf9546b5a2a634d80ef15c5a379a3b73d221b143ac415d548ab1466013ceff
BLAKE2b-256 checksum
How to use checksums
642f3d6448d33bfd8f26b0d883588b4bf117e0495dd2f5c399ad8e5e8efd6b12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / iosignal-0.1.0-py3-none-any.whl

Download URL iosignal-0.1.0-py3-none-any.whl
Size 65.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8411b398cc537abf7b50578168074f525767d62ed326cebd3267a396d586d3c
BLAKE2b-256 checksum
How to use checksums
c25733f553285335f77076c0528af03e537d44734124af605c1b397056592d55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for iosignal 0.1.0

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