Metadata-Version: 2.1
Name: connekt
Version: 0.1.0
Summary: Zero-dependency Python client and Sidecar SDK for connekt-daemon
License: MIT
Requires-Python: >=3.9
Project-URL: Homepage, https://github.com/K0ST/Connekt
Project-URL: Repository, https://github.com/K0ST/Connekt
Keywords: connekt,adb,usbmux,sidecar,rpc,stream
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Testing
Description-Content-Type: text/markdown

# `connekt` Python Client SDK

Zero-dependency Python 3.9+ client for `connekt-daemon` (pure Python standard library) with the same orthogonal API model as the Android and TypeScript SDKs:

- **Root `ConnektClient`**: `connect`, `close`, `health`, `peers`, `refresh_peers`, `on_peers_changed`, `subscribe_filter`, `channel(name)`, `on_any_message`
- **Channel `ConnektChannel`**:
  - `send(to, data)` — single `peer_id`, multicast sequence `Sequence[str]`, or `Target.ALL` (`"*"`)
  - `request(to, data="", timeout_ms=None)` — strict 1-to-1 RPC returning `Payload`
  - `open_stream(to, meta=None)` — 0-RTT binary WebSocket stream (`with ... as s:`, `write`, `try_write`, `close`, `abort`) supporting single peer, subset list, or `Target.ALL`
  - `on_message(listener)` / `on_request(handler)` / `on_stream(handler)` — all return `Subscription` (`cancel()`)
- **Unified types**: `Payload` (`.text`, `.bytes`, `.json()`), `OutboundStream`, `InboundStream` (iterable of `Payload`, `meta`, `reject(reason)`, `cancel(reason)`), `Target.ALL`, `Subscription.cancel()`

## Quick Start (Managed Sidecar)

```python
from connekt import Target, spawn_daemon

with spawn_daemon(binary_path="./connekt-daemon") as daemon:
    client = daemon.client

    # 1. Incoming DATA & stream handler with early meta reject
    msg_sub = client.channel("network").on_message(lambda m: print("HTTP:", m.src, m.text))

    def handle_file(stream):
        if stream.meta.get("mime") == "video/mp4":
            stream.reject("video/mp4 rejected")
            return
        for chunk in stream:
            process_chunk(chunk.bytes)

    stream_sub = client.channel("files").on_stream(handle_file)

    # 2. RPC, multicast send, and binary streaming
    peers = client.refresh_peers()
    targets = [p.peer_id for p in peers[:2]]

    resp = client.channel("echo").request(targets[0], "hello")
    print(resp.text)

    client.channel("notice").send(targets, "group-sync")
    client.channel("notice").send(Target.ALL, "reload")

    with client.channel("files").open_stream(targets, {"mime": "image/png"}) as s:
        s.write(png_bytes)  # auto-chunked into 64 KiB binary WS frames

    msg_sub.cancel()
    stream_sub.cancel()
```

## Quick Start (Connect to Running Daemon)

```python
from connekt import ConnektClient

with ConnektClient("http://127.0.0.1:9527") as client:
    print(client.refresh_peers())
```
