Snap Notify
A Python tool for sending notifications to Slack using a modular DSL template system. This tool allows you to define message templates in YAML format and send them to Slack channels with variable interpolation support.
Features
- YAML-based message templates
- Variable interpolation using Jinja2
- Support for threaded messages
- Simple CLI interface
- Secure token management
- Programmatic usage with Python API
Installation
pip install snap-notify
Prerequisites
- Python 3.13 or higher
- A Slack Bot Token (set as
SLACK_BOT_TOKENenvironment variable)
Usage
1. Create a Message Template
Create a YAML file with your message template. Example:
channel: "#your-channel"
blocks:
- type: "section"
text: "Hello {{ name }}! Here's your daily update:"
- type: "context"
elements:
- type: "mrkdwn"
text: "Report generated at {{ timestamp }}"
interpolate:
name: "John"
timestamp: "2024-03-20 10:00:00"
2. Send the Message
Using the CLI
snap-notify --file path/to/template.yaml
You can specify the template format using the --format or -t option:
snap-notify --file path/to/template.yaml --format yaml
# or using the short form
snap-notify -f path/to/template.yaml -t yaml
Using the Client API
from snap_notify import SnapNotifyClient
from snap_notify.parser import parse_template
# Initialize the client
client = SnapNotifyClient() # Uses SLACK_BOT_TOKEN from environment
# Or provide token directly
# client = SnapNotifyClient(token="your-slack-token")
# Parse your template
template = parse_template("path/to/template.yaml")
# Send the message
response = client.send(template)
You can also create message payloads programmatically:
from snap_notify import SnapNotifyClient
client = SnapNotifyClient()
# Create a message payload
payload = {
"channel": "#your-channel",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello from Python!"
}
}
]
}
# Send the message
response = client.send(payload)
Working with Threads
You can create threaded conversations by using the thread_ts parameter:
from snap_notify import SnapNotifyClient
client = SnapNotifyClient()
# Create a parent message
parent_message = {
"channel": "#your-channel",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is the parent message"
}
}
]
}
# Send the parent message and get its timestamp
parent_response = client.send(parent_message)
thread_ts = parent_response["ts"]
# Create a child message in the thread
child_message = {
"channel": "#your-channel",
"thread_ts": thread_ts, # Link to parent message
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a reply in the thread"
}
}
]
}
# Send the child message
client.send(child_message)
You can also use templates with threads:
# parent.yaml
channel: "#your-channel"
blocks:
- type: "section"
text: "Parent message with {{ variable }}"
interpolate:
variable: "interpolated value"
# child.yaml
channel: "#your-channel"
thread_ts: "{{ parent_ts }}" # Will be replaced with actual timestamp
blocks:
- type: "section"
text: "Child message in thread"
interpolate:
parent_ts: "1234567890" # Replace with actual parent message timestamp
variable: "test message" # Repalce with actual message text
Currently supported formats:
yaml(default): YAML template format
Template Structure
The template supports the following fields:
channel: The Slack channel to send the message to (required)thread_ts: Thread timestamp for threaded messages (optional)blocks: Array of Slack block elementsinterpolate: Dictionary of variables for template interpolation
Environment Variables
SLACK_BOT_TOKEN: Your Slack Bot User OAuth Token (required)
License
MIT License - see LICENSE for details.
Metadata
Release files for snap-notify 0.2.1
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 | |
|---|---|---|---|---|
| snap_notify-0.2.1.tar.gz | 4.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| snap_notify-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / snap_notify-0.2.1.tar.gz
| Download URL | snap_notify-0.2.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1418f2dbb42906a7a578d4feb854ccdf481e9dbe26e7a4afd83d36d8aca963cc
|
|
BLAKE2b-256 checksum How to use checksums |
0b8e970372e0f0c6ae4575c0d292ab11915d412306084ef9cec70c1893409f45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.13.3 Darwin/24.4.0
|
Release files / snap_notify-0.2.1-py3-none-any.whl
| Download URL | snap_notify-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2edbfb787f9e3bc247e4664b2d6d12557bb08d68ea729cccf969563a5d05fdcb
|
|
BLAKE2b-256 checksum How to use checksums |
e2872c2e2992b16eee4a580eda44555bf957e109ea54318d97a99e90de51e905
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.13.3 Darwin/24.4.0
|
Security for snap-notify 0.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.