Parlay top level membersΒΆ

These functions and classes are defined in submodules, but are so commonly used that they are made available directly as members of the parlay module.

parlay.open_protocol(protocol_name, **kwargs)[source]

Sets up a protocol to be opened after the Broker initializes.

This function has the same effect as opening a new protocol from the browser-based user interface.

Parameters:
  • protocol_name (str) – name of protocol class to call the open method
  • kwargs – keyword arguments to pass to the protocol’s _open_ method
Returns:

none

Example Usage:

from parlay import open_protocol, start
open_protocol("ASCIILineProtocol", port="/dev/ttyUSB0", baudrate=57600)
start()
parlay.local_item(auto_connect=False)[source]

A class decorator for python Items that are not part of an external protocol.

Local items are self-contained, and do not communicate over external protocols, for example a serial port. They are typically used for simulators or pure python computation items.

Parameters:auto_connect – whether to automatically connect to the Parlay broker when the item is created.
Returns:decorator function

Example usage of local_item decorator:

# motor_sim.py

@local_item()
class MotorSimulator(ParlayCommandItem):

    def __init__(self, item_id, item_name):
        ...

Example usage of defined local item:

import parlay
from motor_sim import MotorSimulator

MotorSimulator("motor1", "motor 1")  # motor1 will be discoverable
parlay.start()
class parlay.ParlayCommandItem(item_id=None, name=None, reactor=None, adapter=None)[source]

This is a Parlay Item that defines functions that serve as commands, with arguments.

This class enables you to use the parlay_command() decorator over your command functions. Then, those functions will be available as commands that can be called from the user interface, scripts, or by other items.

Example: How to define a class as a ParlayCommandItem:

from parlay import local_item, ParlayCommandItem, parlay_command

@local_item()
class MotorSimulator(ParlayCommandItem):

    def __init__(self, item_id, item_name):
        self.coord = 0
        ParlayCommandItem.__init__(self, item_id, item_name)

    @parlay_command
    def move_to_coordinate(self, coordinate)
        self.coord = coordinate

Example: How to instantiate an item from the above definition:

import parlay
from motor_sim import MotorSimulator

MotorSimulator("motor1", "motor 1")  # motor1 will be discoverable
parlay.start()

Example: How to interact with the instantiated item from a Parlay script:

# script_move_motor.py

setup()
discover()
motor_sim = get_item_by_name("motor 1")
motor_sim.move_to_coordinate(500)
class parlay.ParlayProperty(default=None, val_type=<type 'str'>, read_only=False, write_only=False, custom_read=None, custom_write=None)[source]

A convenience class for creating properties of ParlayCommandItems.

Example: How to define a property:

class MyItem(ParlayCommandItem):
    x = ParlayProperty(default=0, val_type=int)

    def __init__(self, item_id, item_name):
        ParlayCommandItem.__init__(self, item_id, item_name)
    ...

Example: How to access a property from a script:

setup()
discover()
my_item = get_item_by_name("MyItem")
original_value = my_item.x
my_item.x = 5
class parlay.ParlayDatastream(default=None, val_type=None, units='', callback=<function <lambda>>)[source]

A convenience class for creating datastreams within ParlayCommandItems.

Example Usage:

class Balloon(ParlayCommandItem):
    altitude = ParlayDatastream(default=0, units="ft")
parlay.parlay_command(async=False, auto_type_cast=True)[source]

Make the decorated method a parlay_command.

Parameters:
  • async – If True, will run as a normal twisted async function call. If False, parlay will spawn a separate thread and run the function synchronously (Default false)
  • auto_type_cast – If true, will search the function’s docstring for type info about the arguments, and provide that information during discovery
parlay.start(mode='DEVELOPER_MODE', ssl_only=False, open_browser=True, http_port=8080, https_port=8081, websocket_port=8085, secure_websocket_port=8086, ui_path=None, log_level=10)

Run the default Broker implementation. This call will not return.