Documentation
EasySync shares object state across scripts, processes or machines with minimal boilerplate. It wraps your class attributes in transparent proxies that transmit every change automatically.
Installation
pip install py-easysync
The core only needs the standard library. For heavy data (NumPy / Torch) or the remote desktop example, install the matching extras:
terminalextras
pip install "py-easysync[numpy]" pip install "py-easysync[torch]" pip install "py-easysync[remote]"
First synced object
One process hosts the SyncServer; every process (including the host) connects to it and decorates the class to share.
dnsserver.py
from easysync import SyncedObject, SyncServer, connect server = SyncServer(port=5000) server.start_thread() client = connect("127.0.0.1", 5000) @SyncedObject(client) class GameState: def __init__(self): self.score = 0 self.players = [] state = GameState() state.score = 42 # propagated to all clients state.players.append("A") # propagated too
lanclient.py
from easysync import SyncedObject, connect client = connect("192.168.1.10", 5000) @SyncedObject(client) class GameState: def __init__(self): self.score = 0 self.players = [] state = GameState() print(state.score) # 42, updated in real time print(state.players) # ['A']
SHM mode (no-socket IPC)
For processes on the same machine, shm_connect() replaces the network with shared memory, powered by EasySHM.
| Criterion | TCP | SHM |
|---|---|---|
| Scope | Any machine on the network | Same machine |
| Server | SyncServer | None |
| Measured latency, one-way (median) | 100 µs | 230 µs |
| Overhead | TCP/IP stack | Direct RAM |
codeexample
from easysync import shm_connect, SyncedObject # Every process using the same name syncs together client = shm_connect("my_cluster") @SyncedObject(client) class State: def __init__(self): self.score = 0
Hybrid TCP/UDP
Each decorated class chooses its transport protocol through the transport argument.
- play_arrow TCP (default): guaranteed delivery. Best for scores, inventories and configuration.
- play_arrow UDP: no delivery or ordering guarantee. Best for positions, rotations and streams, where the next value replaces a lost one.
codemixing transports
@SyncedObject(client, transport="udp") class PlayerPosition: # streamed over UDP def __init__(self): self.x = 0 self.y = 0 @SyncedObject(client) # TCP by default class Inventory: def __init__(self): self.items = []
Codecs & Delta Sync
The Delta Sync engine computes differentials between states to save bandwidth. It is especially effective for NumPy arrays.
state.frame[0] = 1) are not intercepted: reassign the attribute (state.frame = state.frame) to send them as a delta.
Custom types plug in through the codec registry, without touching the library source:
extensioncustom codec
import easysync @easysync.codec("torch.Tensor") class TorchCodec: deep_proxy = False def match(self, obj): ... def encode(self, obj): ... def decode(self, data): ...
API reference
codesignatures
@SyncedObject(client=None, transport="tcp") connect(host="localhost", port=5000, auth_payload=None, auto_reconnect=True, auto_resync=True) shm_connect(cluster_name="default") SyncServer(host="0.0.0.0", port=5000)
| Name | Description |
|---|---|
| client | SyncClient or SHM client to use. Defaults to the last connected client. |
| transport | "tcp" (reliable, default) or "udp" (low latency, lossy). |
| auth_payload | Any value sent to the server's on_auth handler on connection. |
| auto_reconnect | Reconnect automatically when the connection drops; auto_resync then requests the current state again. |
Server authentication
lockon_auth
server = SyncServer(port=5000) @server.on_auth def check(addr, payload): return payload == "secret-token" server.start_thread() client = connect("127.0.0.1", 5000, auth_payload="secret-token")
Telemetry & stats
Every network client tracks real-time statistics in its stats dictionary.
monitoringstats
client.ping() # refresh latency_ms print(client.stats["latency_ms"]) print(client.stats["bytes_sent"], client.stats["bytes_recv"]) print(client.stats["packets_sent"], client.stats["packets_recv"])
Security
Received data is deserialized with a restricted unpickler: only plain data is rebuilt (numbers, strings, bytes, lists, tuples, dicts, sets, datetime, Decimal, UUID, NumPy arrays…). Anything else is refused, so a peer cannot run code on your machine with a crafted packet. The server never deserializes updates: it only reads their routing fields and relays the original bytes.
verified_useryour own types
import easysync # Allow classes whose construction has no side effect easysync.allow_types(MyDataclass, "mypackage.module.OtherClass") # Every peer is trusted: accept any picklable object (e.g. pandas) easysync.trust_all_types()
- play_arrow
The first message of every connection must be the handshake (64 KB max): nothing is relayed before
on_authaccepts it. - play_arrow UDP datagrams are only relayed from authenticated clients, and clients only accept datagrams coming from the server.
- play_arrow
SyncServer(max_message_size=…)bounds every message; a client whose queue stays full forslow_client_timeoutseconds (10 by default) is disconnected instead of freezing the others.
auth_payload: use a VPN or an SSH tunnel on untrusted networks.