Slack bot is used to send information about qcodes via Slack IMs. Some default commands are provided, and custom commands/tasks can be attached (see below).

To setup the Slack bot, a bot first has to be created via Slack by clicking ‘Create New App’ on https://api.slack.com/apps. Once created, the bot will have a name and unique token. These and other settings have to be saved in a config dict (see init( or Parameters) in Slack).

The App containing your bot needs to have the following bot token scopes to perform all methods successfully: - channels:history - channels:read - chat:write - files:write - users:read These can be set after clicking OAuth & Permissions in the left menubar after selecting your bot at https://api.slack.com/apps (or during creation).

Communication with the Slack bot is performed via instant messaging. When an IM is sent to the Slack bot, it will be processed during the next update() call (provided the username is registered in the config). Standard commands provided to the Slack bot are:

  • plot: Upload latest qcodes plot.

  • msmt/measurement: Print information about latest measurement.

  • notify finished: Send message once measurement is finished.

Custom commands can be added as (cmd, func) key-value pairs to self.commands. When cmd is sent to the bot, func is evaluated.

Custom tasks can be added as well. These are functions that are performed every time an update is called. The function must return a boolean that indicates if the task should be removed from the list of tasks. A custom task can be added as a (cmd, func) key-value pair to self.task_commands. They can then be called through Slack IM via:

notify/task {cmd} *args: register task with name cmd that is performed every time update() is called.

class qcodes.utils.slack.Slack(interval=3, config=None, auto_start=True, **commands)[source]

Bases: threading.Thread

Initializes Slack bot, including auto-updating widget if in notebook and using multiprocessing.

  • interval (int) – Update interval for widget (must be over 1s).

  • config (Optional[dict]) –

    Config dict If not given, uses qc.config[‘user’][‘slack’] The config dict must contain the following keys:

    • ’bot_name’: Name of the bot

    • ’bot_token’: Token from bot (obtained from slack website)

    • ’names’: Usernames to periodically check for IM messages

  • auto_start (bool) – Defaults to True.


Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.


Thread event loop that periodically checks for updates. Can be stopped via stop() , after which the Thread is stopped. :returns: None.


Stop checking for updates. Can be started again via start(). :returns: None.


Exit event loop, stop Thread. :returns: None


Retrieve user from user id. :param user_id: Id from which to retrieve user information.


User information.

Return type



Extracts user information for users. :param usernames: Slack usernames of users.


{username: user}

Return type



Adds IM ids of users to users dict. Also adds last_ts to the latest IM message :param users: {username: user} :type users: dict



get_im_messages(username, **kwargs)[source]

Retrieves IM messages from username. :param username: Name of user. :param **kwargs: Additional kwargs for retrieving IM messages.


List of IM messages.


Retrieves new IM messages for each user in self.users. Updates user[‘last_ts’] to ts of newest message. :returns: {username: [messages list]} newer than last_ts. :rtype: im_messages (Dict)


Performs tasks, and checks for new messages. Periodically called from widget update. :returns: None.


Return simple help message


Performs commands depending on messages. This includes adding tasks to be performed during each update.

add_task(command, *args, channel, **kwargs)[source]

Add a task to self.tasks, which will be executed during each update :param command: Task command. :param *args: Additional args for command. :param channel: Slack channel (can also be IM channel). :param **kwargs: Additional kwargs for particular.



upload_latest_plot(channel, **kwargs)[source]

Uploads latest plot (if any) to slack channel. The latest plot is retrieved from qcodes.plots.base.BasePlot, which is updated every time a new qcodes plot is instantiated. :param channel: Slack channel (can also be IM channel). :param **kwargs: Not used.



print_measurement_information(channel, **kwargs)[source]

Prints information about the current measurement. Information printed is percentage complete, and dataset representation. Dataset is retrieved from DataSet.latest_dataset, which updates itself every time a new dataset is created :param channel: Slack channel (can also be IM channel). :param **kwargs: Not used.



check_msmt_finished(channel, **kwargs)[source]

Checks if the latest measurement is completed. :param channel: Slack channel (can also be IM channel). :param **kwargs: Not used.


True if measurement is finished, False otherwise.

Return type


property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.


Return whether the thread is alive.

This method is deprecated, use is_alive() instead.


Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.


Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

exception qcodes.utils.slack.SlackTimeoutWarning[source]

Bases: UserWarning


Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.