PySpec is a Python implementation of the SPEC server and client protocol, providing tools for remote control, data acquisition, and automation in scientific instrumentation environments. It enables Python-based clients to interact with a SPEC server, control motors, read/write variables, and execute commands or functions remotely.
- Async client-server architecture for high-performance remote control
- Remote property and function access (read/write variables, call functions)
- Motor control and status monitoring
- Associative array and data array support
PySpec requires Python 3.9+ and depends on cython, h5py, numpy, and pyee.
pip install chess-pyspec
# or for development
git clone https://github.com/Verdant-Evolution/chess-pyspec
cd chess-pyspec
pip install -e .[dev]import asyncio
from pyspec.client import Client
async def main():
async with Client("127.0.0.1", 6510) as client:
# Get a reference to "var/foo" on the server.
foo = client.var("foo", int)
await foo.set(42)
value = await foo.get()
print("foo:", value) # foo: 42
result = await client.call("add", 2, 3)
print("add(2, 3):", result)
# Wait for a property to have a specific value. This returns immediately
# when the value already matches.
async with foo.subscribed():
await foo.wait_until(15, timeout=10)
# To wait specifically for a future matching update (an event/pulse):
await foo.wait_for_update(15, timeout=10)
asyncio.run(main())async with Client("127.0.0.1", 6510) as client:
motor = client.motor("theta")
# Read and write motor properties and parameters
await motor.sign.get()
await motor.offset.get()
await motor.position.get()
...
# Move motors on the server
async with motor:
await motor.move(10.0)
pos = await motor.position.get()
print("Motor position:", pos) # "Motor position: 10.0"async with Client("127.0.0.1", 6510) as client:
async with client.output("tty").capture() as lines:
await client.exec('print("Hello, world!")')
print(lines[-1]) # Should print 'Hello, world!\n'from pyspec.server import Server, Property, remote_function
import asyncio
class MyServer(Server):
foo = Property[int]("foo", 0)
@remote_function
def add(self, a: str, b: str):
return float(a) + float(b)
async def main():
async with MyServer(host="127.0.0.1", port=6510, test_mode=True) as server:
await server.serve_forever()
asyncio.run(main())Hardware servers currently support properties and remote function calls. Connect with a PySpec or spec client to interface with a PySpec server.
Currently unsupported server features:
- Associative Arrays
- Motor Protocols (through
../start_oneor../start_all)
Run the test suite with:
pytestSee the docs/ directory for full API documentation and usage details.
See LICENSE or the source headers for license details. Portions copyright Certified Scientific Software.