SlackPush provides a wrapper on requests to push messages, logs, exceptions and attachments to slack. It also supports basic formating: Bold and Perforated.
To get started, clone the repository and run
PYPI distribution
pip install slackpush
Conda Distribution
conda install -c chaiitanyasangani88 slackpush
- Import the SlackPush object.
from slackpush import SlackPush
- Initialise SlackPush object with a webhook_url and channel to be posted in. To know more about incoming webhooks read here.
slackpush = SlackPush(webhook_url= <your webhook_url>, channel=<your channel>)
- Push messages/ logs using
send_message
method.
slackpush.send_message('It is up and running')
- Similarly you can push specific exceptions as alerts to slack using
send_exception
method. This pushes the whole stack trace of the error to slack.
try:
< your code here>
except Exception as e:
slackpush.send_exception(e)
- To send attachments to slack, you need to pass Slack OAuth token. More details can be found here.
Note: See that the token has relevant persmissions to post the attachement
To add token to the object use add_token
method. To send an attachment to Slack:
slackpush.send_attachment(<path to attachment>)