33While the CLI can be used to query devices and run plans, it can be useful to
44combine multiple plans within a better interface than bash/shell scripting.
55
6- For this, ` blueapi ` can be used as a library providing a ` BlueapiClient `
7- wrapping interactions with the server.
6+ For this, ` blueapi ` can be used as a library with the ` BlueapiClient ` wrapping
7+ interactions with the server.
8+
9+ To run a standalone script, it should be possible to use [ ` uv ` ] [ _uv ] directly.
10+
11+ ``` sh
12+ $ uv run --with blueapi path/to/script.py
13+ ```
14+
15+ To include as part of an existing virtual environment, add ` blueapi ` using
16+ whichever tool is being used to manage the environment, eg ` uv add blueapi ` ,
17+ ` pip install blueapi ` etc.
818
919## Login to blueapi
1020
1121The following steps require the user to have logged in blueapi. This can be done
12- via the ` blueapi login ` command.
22+ via the ` blueapi login ` command from a terminal before running the script.
23+
24+ ``` sh
25+ $ blueapi login
26+ $ python script.py # or however you are running the script
27+ ```
28+
29+ It is also possible to use the ` login() ` command on the client with the script
30+ although be aware this will cause the script to block waiting for the user to
31+ login which may not be required if being run without monitoring.
1332
1433## Create an instance of the client
1534
1635``` python
17- from blueapi.client.client import BlueapiClient
36+ from blueapi.client import BlueapiClient
1837
1938# A client can be created from either a config instance or the path to a config
2039# file. The minimal configuration required # is:
@@ -26,6 +45,14 @@ from blueapi.client.client import BlueapiClient
2645bc = BlueapiClient.from_config_file(" /path/to/config.yaml" )
2746```
2847
48+ If you are using the ` login() ` method in the script, it should be called before
49+ any further interactions. If the user is already logged in, the script will
50+ continue without prompting the user.
51+
52+ ``` python
53+ bc.login()
54+ ```
55+
2956Plans and devices are available via the ` plans ` and ` devices ` attributes of the
3057client. It can be useful to alias these locally to reduce the boilerplate in
3158scripts.
@@ -174,3 +201,5 @@ hnd = bc.add_callback(callback_function)
174201# remove the callback using the returned handle
175202bc.remove_callback(hnd)
176203```
204+
205+ [ _uv ] :https://docs.astral.sh/uv/
0 commit comments