Skip to main content

IPython Magic for sending notifications to Slack

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 ...

See also

Metadata

Release files for ipyslack 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ipyslack 1.2.1
File Size Uploaded Provenance Actions
ipyslack-1.2.1.zip 8.5 kB Without provenance Details for ipyslack-1.2.1.zip

Release files / ipyslack-1.2.1.zip

Download URL ipyslack-1.2.1.zip
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0c95e8f2bb59d8aebb779d54786b9c5bee0e8ec20ff328689566c45e70ae0494
BLAKE2b-256 checksum
How to use checksums
13d73c6cd4a2655fe997254e6145475e2521c5752221f90435c095dfb15dc7e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for ipyslack 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page