Registry / communication / slackblocks

slackblocks

JSON →
library2.0.0pypypi✓ verified 90d ago

Python wrapper for the Slack Blocks API, providing a fluent interface for constructing Block Kit messages. Current version 1.2.3 works with Python >= 3.8.1, released occasionally with minor updates. It aims to simplify building complex Slack message layouts.

pip install slackblocks
INSTALL
IMPORT
SIG · SLACKBLOCKS
S
slackblocks
communicationpythonv2.0.0
Install
1.7s avg
Import
54ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.058s · 18.2MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.050s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Message
✓ from slackblocks import Message
Main entry point for creating Slack messages.
SectionBlock
✓ from slackblocks import SectionBlock
Used to add section blocks to messages.
ImageBlock
✓ from slackblocks import ImageBlock
Used to add image blocks.
DividerBlock
✓ from slackblocks import DividerBlock
Used to add a divider line.
ContextBlock
✓ from slackblocks import ContextBlock
Used to add context elements.

Construct a basic Slack message with a section and an image block, then send using slack_sdk.

import os from slackblocks import Message, SectionBlock, ImageBlock message = Message( channel="#general", text="Hello, world!", blocks=[ SectionBlock(text="This is a section block"), ImageBlock(image_url="https://example.com/image.png", alt_text="Example Image") ] ) # Send via slack_sdk or similar from slack_sdk import WebClient client = WebClient(token=os.environ.get("SLACK_TOKEN", "")) response = client.chat_postMessage(**message) print(response)
Debug
Known issues
gotcha`Message` does not directly send requests; it only builds the payload. You must use an HTTP client (e.g., slack_sdk) to send.
fix
Use `client.chat_postMessage(**message)` where `message` is a SlackBlocks Message object.
affects: all
gotchaBlocks must be passed as a list to `Message`; passing a single block without list wrapping will break.
fix
Always wrap blocks: `blocks=[SectionBlock(...)]` even if one block.
affects: all
deprecatedThe `channel` parameter in `Message` may be deprecated in future versions; prefer passing channel when sending via the client.
fix
Omit channel from Message constructor and set it in the HTTP call: `client.chat_postMessage(channel="#general", **message)`.
affects: >=1.0
gotchaText in SectionBlock must be a string, not a dict; using Block Kit object syntax incorrectly may cause errors.
fix
Use plain strings: `SectionBlock(text="Hello")`. For rich text, use `mrkdwn=True` or similar parameters.
affects: all
Errors
Common errors & fixes
TypeError: Object of type SectionBlock is not JSON serializable
Trying to serialize the Message object directly without calling its `build()` or using `**message`
fix
Use `**message` when passing to slack_sdk: `client.chat_postMessage(**message)`. Or call `message.build()` to get a dict.
ModuleNotFoundError: No module named 'slackblocks'
slackblocks is not installed or installed in a different environment.
fix
Run `pip install slackblocks` in your active environment.
KeyError: 'blocks'
The Slack API requires a 'blocks' field in the payload, but Message without blocks may omit it.
fix
Always provide a `blocks` parameter when constructing Message, even if empty list: `blocks=[]`.
Upgrade
Version history
2.0.0latest on PyPI · released May 15, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
37 hits · last 30 days
node
32
OpenAI (training)
1
Resources
slackblocks — pip install slackblocks · libregistry