Skip to main content

IPython magic for sending slack notifications

Project description

Installation

$ pip install ipyslack

Usage

  1. Load the extension:

    %load_ext ipyslack
    
  2. Configure Slack API:

    %slack_setup -t <api_token> -c <target_channel>
    

    To obtain the API token visit this page. The <target_channel> parameter may either denote a channel (e.g. #general) or a user (e.g. @me).

    Adding the option -u true to %slack_setup will make yourself the sender of all messages. Otherwise (default) the messages originate from slackbot.

    In order to avoid having to write the API token in every notebook, you can create a file containing the same configuration line:

    -t <api_token> -c <target_channel> -u false
    

    You can then load this configuration in the notebook by invoking:

    %slack_setup <filename>
    

    Even simpler, if you don’t call %slack_setup at all, the extension will try to auto-configure itself on first use by searching for the files ~/.ipyslack.cfg and .ipyslack.cfg (in this order) and trying to load configuration from these.

    Later files in this search order override the settings of the previous ones. That is, you can specify -t <api_token> -c #default_group in the global ~/.ipyslack.cfg, and only override -c #project_group in the local .ipyslack.cfg.

  3. Now adding:

    %%slack_notify <message>
    

    at the top of any cell will send <message> to <target_channel> whenever cell execution is completed.

    The patterns {out} and {err} within <message> will be substituted with stdout or stderr from the cell’s execution. The pattern {exc} denotes the exception (if any was thrown). The string \n denotes a new line. Simiarly, any variable named x in your workspace can be referred to as {x} (in fact, you can use the standard format string notation).

    Example:

    %%slack_notify *Completed {len(results)} trials. Last result: {results[-1]}!* :heavy_plus_sign:\nStdout: {out}\nStderr: {err}\nException: {exc}
    
  4. In addition, the line-magic %slack_send <message> lets you send notifications about partial results. E.g.:

    %%slack_notify Completed. Final accuracy: {accuracy}. {exc}
    ... computation ...
    %slack_send Half-way! Current accuracy: {accuracy}
    ... computation ...
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
ipyslack-1.2.1.zip (8.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page