Resources / Data Nexus
DeveloperSyva Service SDK
Lightweight Python client that runs inside your AI microservice so it can register into Data Nexus, stay healthy in the registry, and leave cleanly on shutdown.
Package: syva-service-sdk (syva_sdk). Requires Python ≥ 3.9. The SDK talks to the local Node Agent — it does not register directly with the control plane.
What the SDK does
- Registers the service with the local Node Agent
- Sends heartbeats so the service stays healthy in the registry
- Deregisters cleanly on shutdown so traffic stops promptly
- Maintains a persistent instance id across process restarts
Hardware telemetry is owned by the Node Agent, not the SDK. Place a Node Agent on every machine that hosts services you want in the mesh.
Architecture
Installation
Distribution depends on your engagement (platform bundle, private index, or source path). Typical editable install during development:
cd syva_service_sdk
pip install -e .
# Optional FastAPI extras (uvicorn + fastapi for example apps)
pip install -e ".[fastapi]"Configuration
Configure primarily via environment variables (read when constructing the client):
| Variable | Description | Default |
|---|---|---|
SYVA_NODE_URL | Base URL of the local Node Agent | http://localhost:8080 |
SERVICE_NAME | Stable service name (proxy path identity) | unknown-service |
SERVICE_HOST | Hostname/IP advertised to the mesh. Prefer auto on host-networked workers. | localhost |
SERVICE_PORT | Port your service listens on | 8000 |
SERVICE_TOKEN | Bearer token for registry authentication (treat as a secret) | unset |
SERVICE_TYPE | Category metadata (llm, tts, microservice, …) | microservice |
SYVA_GROUP | Logical load-balancing group name | unset |
SYVA_LB_POLICY | Load-balancing policy string | round-robin |
On first run the SDK writes .syva_instance_id in the working directory. Keep it unless you intentionally want a new instance identity.
Core API
from syva_sdk import SyvaClient
client = SyvaClient()
if client.register():
client.start_heartbeat()
# ... run your service ...
client.deregister() # also stops heartbeat
else:
raise SystemExit("Failed to register with Syva Node Agent")| Method | Description |
|---|---|
register() | Register with retries/backoff; returns True on success |
start_heartbeat() | Start daemon heartbeat thread |
stop_heartbeat() | Stop heartbeat without deregistering |
deregister() | Stop heartbeat, then remove the service from the local agent registry |
FastAPI lifespan pattern
from fastapi import FastAPI
from syva_sdk import SyvaClient
import contextlib
@contextlib.asynccontextmanager
async def lifespan(app: FastAPI):
client = SyvaClient()
if not client.register():
raise RuntimeError("Syva registration failed")
client.start_heartbeat()
app.state.syva_client = client
try:
yield
finally:
client.deregister()
app = FastAPI(lifespan=lifespan)
@app.get("/health")
def health():
return {"status": "ok"}Consume path after registration
Once the service is active, consumers call through the Data Plane proxy:
https://<nexus-host>/v1/proxy/<SERVICE_NAME>/<path>
# Optional group route for pooled replicas
https://<nexus-host>/v1/proxy/group/<group>/...Best practices
- Always call
deregister()on shutdown (or use a lifespanfinally). - Prefer
SERVICE_HOST=autoon workers so the gateway receives a routable IP. - Keep
SERVICE_NAMEstable — it is part of the public proxy path. - Use
SYVA_GROUPwhen running multiple replicas of the same capability. - Treat
SERVICE_TOKENas a secret — never bake real tokens into images or examples. - Do not send hardware stats from the SDK — rely on the Node Agent.
Troubleshooting (high level)
| Symptom | Likely cause | Action |
|---|---|---|
| Connection errors on register | Node Agent down or wrong URL | Start the agent; verify SYVA_NODE_URL |
| Permanent conflict on register | Host/port already owned | Change SERVICE_PORT or free the port |
| Service stuck pending | Missing token or approval workflow | Provide a valid token or approve in Admin UI |
| Gateway cannot reach service | Advertised host wrong | Use SERVICE_HOST=auto on host network |
Related: How it works · Platform overview · Request pilot access for operator manuals and connector guides.