bluesky_queueserver_api.BItem

class bluesky_queueserver_api.BItem(*args, **kwargs)[source]

A helper class that generates dictionary with queue item parameters. The class performs validation of values to ensure that the dictionary is formatted correctly. A queue item can be represented as a plain Python dictionary. Using this class to represent is queue items is optional.

The item can be instantiated from a dictionary that contains valid item parameters or by passing item type, item name, args and kwargs or from another BItem object. The class implements public properties that allow to access all important item parameters, such as item_type, name, args, kwargs, meta and item_uid.

Parameters:
*args: list

The first two arguments are required and should represent item type (allowed values are 'plan', 'instruction' and 'function') and item name (name of the plan, instruction or function represented as a string). The remaining arguments are optional and represent args of the plan or function. Alternatively, an item may be instantiated from a valid dictionary of item parameters or another item object. In this case the constructor should be passed a single argument that contains the dictionary or the object and no keyword arguments.

**kwargs: dict

Keyword arguments of the plan or function.

Raises:
KeyError, ValueError, TypeError

Missing parameter or invalid parameter types or values

Examples

plan1 = BItem("plan", "count", ["det1", "det2"], num=10, delay=1)
plan2 = BItem(plan1)  # Creates a copy of a plan
plan3 = BItem({
    "item_type": "plan",
    "name": "count",
    "args": [["det1", "det2]],
    "kwargs": {"num": 10, "delay": 1}
})

item_type = plan1.item_type  # Require, always set
item_name = plan1.name  # Required, always set
item_args = plan1.args  # Optional, [] if not set
item_kwargs = plan1.kwargs  # Optional, {} if not set
item_uid = plan1.item_uid  # Usually set by the server, None if not set
item_meta = plan1.meta  # Optional, {} if not set

# Convert 'plan1' into 'queue_stop' instruction (properties are writable)
plan1.item_type = "instruction"
plan1.name = "queue_stop"
plan1.args = []
plan1.kwargs = {}
plan1.meta = {}

plan1_dict = plan1.to_dict()  # Returns a copy of the internal dictionary
plan2.from_dict(plan1_dict)  # Makes 'plan2' a copy of 'plan1'
plan2.from_dict(plan1)  # Works exactly the same

# Access to internal dictionary
dict_ref = plan3.dict_ref
dict_ref["args"] = [["det1"]]
__init__(*args, **kwargs)[source]

Methods

__init__(*args, **kwargs)

from_dict(item_dict)

The method copies item parameters from a dictionary.

to_dict()

The method returns the copy of the dictionary with item parameters, which is ready to be passed to the server.

Attributes

args

The read-write property sets or gets the list of item args.

dict_ref

The property returns reference to iternal item dictionary.

item_type

The property for read-write access to the item type.

item_uid

The property for read-write access to the item uid.

kwargs

The read-write property sets or gets the copy of the dictionary of item kwargs.

meta

The read-write property that sets or gets the item metadata.

name

The property for read-write access to the item name.

recognized_item_types

The read-only property returns the list of item types recognized by the queue server.