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 and encryption (standard Ascon, NIST SP 800-232), 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)

0.2.0 uses Boho 3 (Ascon). It logs in only to IOSignal servers 10.0.0 or newer; anonymous connections work with any server. Device keys made for 9.x servers must be issued and registered again, and boards need the 0.2.0 package (reinstall over USB). See CHANGELOG.md.

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 Boho (Ascon).
  • 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 Boho (Ascon), 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).
  • More examples: examples/board_iris.py (an iris.2 light with four RGB LEDs; hold button 2 to show the Wi-Fi signal and connection on the LEDs), examples/board_light.py, and short scripts to run once: blink.py, button_read.py, board_info.py. board_default.py is the plain main.py (link only).
  • A logged-in board without a name keeps the name registered for its CID. A burst of commands (a dragged slider) is answered with at most one $state per 300 ms, always ending with the latest state.

Wi-Fi on small boards

  • /iosignal.json "txpower": 8.5 sets the Wi-Fi send power in dBm. Small ESP32-C3 boards (for example iris, C3 SuperMini) lose sent packets at full power until the connection stalls; 8.5 fixes that near the router, raise it (11, 15) in a far room. Wi-Fi power save is always off.
  • "wifi_mode": "b" uses 802.11b only: slower, but it holds on a much weaker signal. The router must allow 802.11b.
  • The link reconnects by itself when its sending stalls (no PONG to a ping, or nothing sent for 10 s), also while commands keep arriving. Every drop and reconnect is written to /linklog.txt with the UTC time, the reason and the signal (kept near 4 KB; "linklog": false turns it off).

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.

# REPL key (64 hex digits): paste it when asked (not shown), or export REPL_KEY=<key>, -k <key>, or a key file ~/.iosignal/repl-<board>.key
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.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 iosignal 0.2.1
File Size Uploaded Provenance Actions
iosignal-0.2.1.tar.gz 113.2 kB Without provenance Details for iosignal-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 188.4 kB

Release files / iosignal-0.2.1.tar.gz

Download URL iosignal-0.2.1.tar.gz
Size 113.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e72eac942e34a253ed49b43586a435413b2d307e2c9e925dbcec4394aee0da9b
BLAKE2b-256 checksum
How to use checksums
486a58b07a7eecc984f388472e6d5cb124df4514e285f7a8a8a50fb98f2ada56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

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

Download URL iosignal-0.2.1-py3-none-any.whl
Size 75.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2aafeadab08bf478d75b9492881b8f90013ce97e2aff00310e6144732f7e4482
BLAKE2b-256 checksum
How to use checksums
45370025eb7ee7f17deb5223744cb1a29c4b7635d166869b608dda3c6375f7e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Security for iosignal 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