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" "My Shell Comand Job"
Running without a config file
You can run the tool without first running the init command by passing in the API token and channel ID (and optionally the custom messages) as arguments. The arguments will override values in the config file if it does exist.
slacknotif run <script_path> [job_name] [--token TOKEN] [--channel CHANNEL] [--success-msg SUCCESS_MSG] [--failure-msg FAILURE_MSG]
Example:
slacknotif run my_script.py "Data Processing Job" --token "MY-API-TOKEN" --channel "Random"
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] - Run Script and Notify and override config settings:
slacknotif run <script_path> [job_name] [--token TOKEN] [--channel CHANNEL] [--success-msg SUCCESS_MSG] [--failure-msg FAILURE_MSG]
License
This project is licensed under the MIT License.
Metadata
Release files for slacknotifpy 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| slacknotifpy-1.0.7.tar.gz | 6.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slacknotifpy-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.2 kB
Release files / slacknotifpy-1.0.7.tar.gz
| Download URL | slacknotifpy-1.0.7.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e618b42e1e8e5be47c102261c4fba6b2d5c8073912b479bff4e5b2a3ad2c3a23
|
|
BLAKE2b-256 checksum How to use checksums |
48e6ba23f474c3c1dbd8cb9c3e5b29456b4bcde645003794983be5dbd77297e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Release files / slacknotifpy-1.0.7-py3-none-any.whl
| Download URL | slacknotifpy-1.0.7-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c77f1e9430282c4c91abbe364d4e43664eedef9c52520ed7dbfe3a2319380405
|
|
BLAKE2b-256 checksum How to use checksums |
14b74d55f5a644d8bb9d7602664ea7121e5dd3ccb3b0a6ae77112648b2ef1a82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Security for slacknotifpy 1.0.7
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.