Skip to content

Commit 93b42e3

Browse files
committed
Update docs with login/environment info
1 parent fd14ae9 commit 93b42e3

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

docs/tutorials/scripting-plans.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,37 @@
33
While the CLI can be used to query devices and run plans, it can be useful to
44
combine 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

1121
The 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
2645
bc = 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+
2956
Plans and devices are available via the `plans` and `devices` attributes of the
3057
client. It can be useful to alias these locally to reduce the boilerplate in
3158
scripts.
@@ -174,3 +201,5 @@ hnd = bc.add_callback(callback_function)
174201
# remove the callback using the returned handle
175202
bc.remove_callback(hnd)
176203
```
204+
205+
[_uv]:https://docs.astral.sh/uv/

0 commit comments

Comments
 (0)