A python client library for the bliss REST API
Project description
blissclient
A python client for the BLISS REST API, the high-level client is fully typed ready for auto-completion in any modern IDE.
Getting Started
Set the BLISSAPI_URL
export BLISSAPI_URL=http://localhost:5000
Then:
from blissclient import BlissClient
client = BlissClient()
omega = client.hardware.get("omega")
print(omega.position)
future = omega.move(100)
# Wait for the call to temrinate, blocking
future.get()
Execute calls in the session:
import time
from blissclient import BlissClient, get_object
client = BlissClient()
test_session = client.session
future = test_session.call("ascan", get_object("omega"), 0, 10, 10, 0.1, get_object("diode"))
# Ask for the current future state
print(future.state)
# Block until terminated
result = future.get()
# The redis scan key, can be used with `blissdata``
print(result["key"])
get_object("<name>") are translated to the relevant beacon objects.
See the test suite for more examples.
Events
Events are propagated via a websocket using socket.io. blissclient provides a helper function to create connect functions to instantiate the socket.io connection in either threaded or asyncio forms:
connect = self._client.create_connect()
connect()
connect = self._client.create_connect(async_client=True)
await connect()
This function should be run somewhere in the background to ensure event reception. After that objects will be set in evented mode to limit polling.
The client can then subscribe to hardware object events:
omega = client.hardware.get("omega")
def property_event(data: dict[str, any]):
for key, value in data.items():
# for example position
logger.info(f"property event key=`{key}` value=`{value}`")
def online_event(online: bool):
logger.info(f"onine event {online}")
def locked_event(reason: str):
logger.info(f"locked event {reason}")
omega.subscribe("property", property_event)
omega.subscribe("online", online_event)
omega.subscribe("locked", locked_event)
Events also allow stdout to be captured from a session call:
connect = client.create_connect(async_client=True)
task = asyncio.create_task(connect())
future = test_session.call(
"ascan",
get_object("robx"),
0,
5,
5,
0.2,
get_object("diode1"),
in_terminal=True,
emit_stdout=True,
)
response = future.get()
print(future.stdout)
Future API
The future returned by each call tries to emulate a celery future.
future = test_session.call(...)
# Any progress if the task supports it
future.progress
# Assume the called function returns a bliss `Scan` object
future = test_session.call(
"ascan",
...
has_scan_factory=True,
)
# Wait for the scan to start
progress = future.wait_scan()
# Now access the bliss `Scan` key that can be used with blissdata
print(progress["scan"]["key"])
# Ask for the current state (a single REST call)
future.state
# Blocking until terminated (polls the REST API in the background)
# default `monitor_interval` = 5s
future.get(monitor_interval=1)
# Kill the current task
future.kill()
# If socketio was connected and the call requested `emit_stdout=True`
print(future.stdout)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file blissclient-1.3.0.tar.gz.
File metadata
- Download URL: blissclient-1.3.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2cd774c0bc159e29d49bc1e2a287e6a399db0d431e92b427a5b48ddae0007c8
|
|
| MD5 |
d895459c14af7021d651d5a1318fbd3e
|
|
| BLAKE2b-256 |
bd62ecbc135007cd3c6d4a92abadf30776bddac9e5d283fa6d241823501fbd7e
|
File details
Details for the file blissclient-1.3.0-py3-none-any.whl.
File metadata
- Download URL: blissclient-1.3.0-py3-none-any.whl
- Upload date:
- Size: 37.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c90cfa49faaccc94841d8d0f0be55411b173c0a934188bddbd77e61621acdb
|
|
| MD5 |
02bab10aade731973ed986a6d9a582ab
|
|
| BLAKE2b-256 |
cb3cb635e354487bf4b096c169ddab34c95356ff53f1fb96e4a81d8175881264
|