Python API and CLI for sending message in Slack
toslack is a Python package that helps you send messages, images or files to slack channels with simple settings. Command line tools are also provided to do the same thing.
Requirements
- Python Version: Ensure you are using Python 3.6 or higher.
- Dependencies:
slack_sdk(version 3.31.0)dataclasses(built-in for Python 3.6+)typing(for type hinting)
Installation
pip install toslack
Sending a message to Slack
One of the most common use-cases is sending a message to Slack. If your app's bot user is not in a channel yet, invite the bot user before running the code snippet (or add chat:write.public to Bot Token Scopes for posting in any public channels).
import os
from toslack import SlackMessage
from toslack import SlackClient
client = SlackClient(token=os.environ['SLACK_BOT_TOKEN'], channel=os.environ['TO_SLACK_CHANNEL'])
message = SlackMessage(client=client)
message.post(text="Hello world!")
Or posting your message by the command line.
python slack.py --token xxx --channel C123456 post $message
Uploading files to Slack
You can just include a path to the file directly in the API call and upload it that way.
import os
from toslack import SlackMessage
from toslack import SlackClient
client = SlackClient(token=os.environ['SLACK_BOT_TOKEN'], channel=os.environ['TO_SLACK_CHANNEL'])
message = SlackMessage(client=client)
message.upload(file_path="./tmp.txt")
Or upload by specifying the file path on the command line.
python slack.py --token xxx --channel C123456 upload $file_path
Metadata
Release files for toslack 0.1.0
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 | Actions |
|---|---|---|---|---|
| toslack-0.1.0.tar.gz | 4.0 kB | Without provenance | Details for toslack-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toslack-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for toslack-0.1.0-py3-none-any.whl |
Total release size: 8.9 kB
Release files / toslack-0.1.0.tar.gz
| Download URL | toslack-0.1.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4cbac632dae6eb3470c845a74338a284db78ec30a20e45f27a6b74dd55be167
|
|
BLAKE2b-256 checksum How to use checksums |
f9f0298da143cee39424aeb94c5241a3ed0a8ed369fb23e2dd295dbdb1c14f06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.6
|
Release files / toslack-0.1.0-py3-none-any.whl
| Download URL | toslack-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
43a9a7b30e6ca3448c2afa00126311492bc06de67dd2524e31a77ca2967deb4d
|
|
BLAKE2b-256 checksum How to use checksums |
7b123b4eac584723c46d7fa8b8b1e3ad06c708e8e0ca1b0b4c3d01e3156aea5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.6
|
Security for toslack 0.1.0
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.