Client API

class happi.Client(database=None, **kwargs)

The client to control the contents of the Happi Database

Parameters:
  • database (happi.backends.Backend) – A already instantiated backend
  • kwargs – Passed to the db_type backend
device_types

dict – Mapping of Container namees to class types

Raises:DatabaseError: – Raised if the Client fails to instantiate the Database
add_device(device)

Add a new device into the database

Parameters:device (Device) – The device to store in the database
Raises:EntryError: – If all of the mandatory information for the device has not been specified or there is already a device with that id in the database
all_devices

A list of all contained devices

create_device(device_cls, **kwargs)

Create a new device

Parameters:
  • device_cls (Device or name of class) – The Device Container to instantiate
  • kwargs – Information to pass through to the device, upon initialization
Returns:

An instantiated version of the device

Return type:

device

Raises:

TypeError: – If the provided class is not a subclass of Device

Example

device = client.create_device(Device,   name='my_device' ...)
device = client.create_device('Device', name='my_device',...)

See also

device_types

export(path=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, sep='\t', attrs=None)

Export the contents of the database into a text file

Parameters:
  • path (File Handle) – File-like object to save text file
  • sep (str) – Separator to place inbetween columns of information
  • attrs (iterable) – Attributes to include, these will be a list of values
find_device(**post)

Used to query the database for an individual Device

If multiple devices are found, only the first is returned

Parameters:post – Information to pertinent to the device
Raises:SearchError – If no match for the given information is found
Returns:device – A device that matches the characteristics given
Return type:Device
find_document(**kwargs)

Load a device document from the database

If multiple matches are found, a single document will be returned to the user. How the database will choose to select this device is based on each individual implementation

Parameters:kwargs – Add information to locate the device in keyword pairs
Returns:document – A dict that matches the specified information.
Return type:dict
Raises:SearchError: – If no document with the given information is found
remove_device(device)

Remove a device from the database

Parameters:device (Device) – Device to be removed from the database
search(start=0.0, end=None, as_dict=False, **kwargs)

Search the database for a device or devices

Parameters:
  • as_dict (bool, optional) – Return the information as a list of dictionaries or a list of Device containers
  • start (float, optional) – Minimum beamline position to include devices
  • end (float, optional) – Maximum beamline position to include devices
  • kwargs – Information to filter through the database structured as key, value pairs for the desired pieces of EntryInfo
Returns:

  • Either a list of devices or dictionaries
  • Example
  • .. code:: – gate_valves = client.search(type=’Valve’) hxr_valves = client.search(type=’Valve’, beamline=’HXR’)

validate()

Validate all of the devices in the database by attempting to initialize them and asserting their mandatory information is present. Information is written to the logger

Returns:ids – List of device ids that have failed verification
Return type:list