Getting Started¶
Installation¶
Requires Python 3.9+. Linux and macOS are supported.
Your first service¶
Create two files:
1_service.py
from daffi import Service, callback
@callback
def add(a: int, b: int) -> int:
print(f"[service] add({a}, {b})")
return a + b
if __name__ == "__main__":
svc = Service(app_name="calc-service", host="127.0.0.1", port=5001)
svc.start()
print("Service running on 127.0.0.1:5001 — press Ctrl+C to stop.")
svc.join()
2_client.py
from daffi import Client
if __name__ == "__main__":
client = Client(app_name="calc-client", host="127.0.0.1", port=5001)
conn = client.connect()
result = conn.rpc(timeout=5).add(3, 4)
print(f"add(3, 4) = {result}") # → 7
client.stop()
Run them:
What just happened?¶
Servicestarts a native TCP listener.@callbackregistersaddwith the framework; it is advertised to callers during the handshake.Client.connect()performs a handshake, receives the list of available callbacks.conn.rpc(timeout=5)returns a proxy. Calling.add(3, 4)on it serialises the arguments, sends them to the Service, and blocks until the result arrives.
Next steps¶
| Topic | Link |
|---|---|
| Direct Client → Service communication | Client → Service |
| Scalable Router + Worker topology | Client → Router → Worker |
| rpc vs cast (broadcast) | Call Styles |
| Serialization formats | Serialization |
| Event subscriptions | Events |
| Browser / JavaScript client | JavaScript Client |