A Python tool for sending Slack notifications on job completion.
Project description
SlackNotifPy
slacknotifpy
is a Python CLI tool that sends notifications to a specified Slack channel on job completion. This can be especially useful for tracking automated job results, such as success or failure, directly in Slack.
Features
- Runs a Python script or shell command and sends a Slack notification upon completion.
- Customizable success and failure messages.
- Simple configuration for Slack tokens and channel IDs.
Installation
Install slacknotifpy
from PyPI:
pip install slacknotifpy
Configuration
To use slacknotifpy
, you need to configure it with your Slack token and channel ID. These settings will be saved in a .slacknotif_config
file.
- Run the following command to set up the configuration:
slacknotif init
- Follow the prompts to enter:
- Slack Token
- Slack Channel ID
- Custom success and failure messages (optional)
You can find the Slack token and channel ID in your Slack app settings.
Custom Messages
To update the success and failure messages for a project, use:
slacknotif config setmessages
Resetting the Configuration
The initialized config file can be reset using the command:
slacknotif config setconfig
and following the prompts.
Usage
After configuring slacknotifpy
, you can use it to run scripts and send notifications:
slacknotif run <script_path> [job_name]
script_path
: The path to the Python script you want to run.job_name
(optional): A name for the job, used in the Slack message. Defaults to the script filename.
Example:
slacknotif run my_script.py "Data Processing Job"
A shell command can be run instead of a Python script by using the --cmd
or -c
flag:
slacknotif run -c "<SHELL COMMAND>" [job_name]
Example:
slacknotif run -c "ls -l /tmp" [job_name]
Example Slack Notification Messages
- Success: "Data Processing Job completed successfully"
- Failure: "Data Processing Job failed"
You can customize these messages using {job_name}
as a placeholder in the config.
You can also tag users using thier real or display names using {@John Doe}
or {@JohnDoe42}
Command Reference
- Configure SlackNotifPy:
slacknotif init
- Re-Configure SlackNotifPy:
slacknotif config setconfig
- Set Custom Messages:
slacknotif config setmessages
- Run Script and Notify:
slacknotif run <script_path> [job_name]
- Run Shell Command and Notify:
slacknotif run -c "<SHELL COMMAND>" [job_name]
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file slacknotifpy-1.0.6.tar.gz
.
File metadata
- Download URL: slacknotifpy-1.0.6.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ef6b0c831dff886c36156595a681dd5162557849e9b36e64b2e38d5b4116981 |
|
MD5 | 69836eee6c30b8afa45eb52ab4d67f9f |
|
BLAKE2b-256 | 6154e84c919e80d12c86587aac89182016c1cb91a9de24baf97e2770f7df1f45 |
File details
Details for the file slacknotifpy-1.0.6-py3-none-any.whl
.
File metadata
- Download URL: slacknotifpy-1.0.6-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b787574dabc5902a48600dcc6422304f6ea706139efadd75d8ae72824bfb0dc5 |
|
MD5 | 692bc6e6a8fb5a0c305cc5c0a4986dad |
|
BLAKE2b-256 | fd849834188837a8b29bd9eb1e92a7d86c9338baadccf5fe4d346f2acae4e2d4 |