Skip to main content

A Python tool for sending Slack notifications on job completion.

Project description

SlackNotifPy

A Python command-line tool to send Slack notifications for job completion. This tool allows you to set up a Slack bot token and channel ID for each project, enabling job-specific notifications.

Installation

Install the package in your project:

pip install .

Usage

1. Set the Slack Configuration

To configure the Slack token and channel for the project, run:

slacknotif config setconfig <job_script.py>

This command prompts you to enter your Slack bot token and channel ID, storing them in a .slacknotif_config file in the project directory where <job_script.py> is located.

2. Run a Job and Notify

Once configured, you can run a job and send a notification to the specified Slack channel upon completion:

slacknotif <job_script.py> <job_name>
  • <job_script.py>: The Python script you want to run.
  • <job_name>: A name for the job, used in the Slack message.

For example, if job_script.py completes successfully, the Slack message will read:

"job_name completed successfully"

If the script fails, the message will read:

"job_name failed"

Configuration Details

The configuration file .slacknotif_config is saved in the same directory as the job script. It contains:

  • SLACK_TOKEN: Your Slack bot token, which is used for authentication.
  • CHANNEL_ID: The Slack channel ID where notifications will be sent.

Each project directory with a .slacknotif_config file can have its own Slack configuration, making it easy to set up notifications for different projects.

Security

The .slacknotif_config file is saved with restricted permissions (readable and writable only by the file owner) to ensure the security of your Slack token and channel ID.

Example

  1. Set Configuration:
slacknotif config setconfig job_script.py

Enter your Slack token and channel ID when prompted.

  1. Run Job with Notification:
slacknotif job_script.py "Data Processing Job"

This will run job_script.py and send a message to Slack with the status of "Data Processing Job".

Dependencies

  • slack_sdk: Used for sending messages to Slack.

License

This project is licensed under the MIT License.

Project details


Download files

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

Source Distribution

slacknotifpy-1.0.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

slacknotifpy-1.0.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file slacknotifpy-1.0.3.tar.gz.

File metadata

  • Download URL: slacknotifpy-1.0.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for slacknotifpy-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4e2639b08c9fd5731d23f91d25e118d6573cb34a8b5b6a3d15b6aff3236dcc58
MD5 74d5c5da882fef0e42e1db6cd2fc44bc
BLAKE2b-256 88dcdecc56b1fc54a3469ed2b5525dc3a9cdd26fdd472f63cb54a47b49f377de

See more details on using hashes here.

File details

Details for the file slacknotifpy-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for slacknotifpy-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a9eb7bd5f63f20894ba4c5a9b64823807b000d94242f931fb4105e45431385c
MD5 77967aa2a57c81c7f474e1943e77386e
BLAKE2b-256 b9653e7bcf0d89866b55b3c156b17567d32ba609e28355c62993f89e7c06e29c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page