Once your device is implemented, you can expose it over TCP/IP using the SDK's built-in server and client. This allows experiments and other applications to control the device remotely.
Starting the server
Use build_server() to wrap your device in a TCP server:
from plesty.lib.service import build_server
# Create your device
device = MyDevice()
# Start the server
server = build_server(
device=device,
fixed_threading=False,
address="tcp://*:5555",
)
# The server is now listening for connections
The server listens on the specified address and dispatches incoming ZMQ messages to the device's methods.
Connecting with a client
Use build_client() to connect to a running server:
from plesty.lib.service import build_client
client = build_client(
address="tcp://localhost:5555",
timeout=5000,
resources=None,
client_id=None,
connect_kwargs=None,
)
# Now you can call device methods through the client
Client parameters
| Parameter | Type | Description |
|---|---|---|
address |
str |
Server address (e.g., tcp://localhost:5555) |
timeout |
int |
Response timeout in milliseconds |
resources |
dict |
Optional resource configuration |
client_id |
str |
Optional client identifier |
connect_kwargs |
dict |
Additional connection parameters |
Full example
# server.py
from plesty.lib.service import build_server
device = MyDevice()
device.connect()
server = build_server(device, address="tcp://*:5555")
server.serve_forever()
# client.py
from plesty.lib.service import build_client
client = build_client(address="tcp://localhost:5555")
print(client.identity()) # "MyDevice v1.0"
client._write_("voltage", 5.0)
print(client._query_("voltage")) # 5.0
Running as a module
The scaffold generates a main.py that can serve as an entry point:
uv run python -m plesty.my_device
Next steps
- Pass gate d1 — the device API pipeline
- Learn about composite devices for multi-device experiments