Build Slack messages in Python — without writing JSON by hand.
slackblocks is a typed, validating Python wrapper around the Slack Block Kit API. It exists because Block Kit JSON is verbose, easy to get subtly wrong, and unpleasant to maintain in source control.
This release conforms to the shared cross-language slackblocks specification.
Why slackblocks?
Concise — SectionBlock("Hello, *world*!") instead of a 10-line JSON object.
Validated — character limits, required fields, mutually-exclusive options, and element-type restrictions are enforced at construction time, so you find out before hitting Slack's API.
Drop-in compatible with both the official slack-sdk and the legacy slackclient — unpack a Message directly into client.chat_postMessage(**message).
— full type hints; ships .
Typed
py.typed
Zero runtime dependencies.
Installation
pip install slackblocks
slackblocks 4.x requires Python 3.10 or newer. Users on Python 3.8 / 3.9 should pin to the 1.x line — see the Compatibility page.
message can be sent in one line with the official Slack SDK:
import os
from slack_sdk import WebClient
client = WebClient(token=os.environ["SLACK_API_TOKEN"])
client.chat_postMessage(**message)
The ** operator unpacks slackblocksMessage objects directly into the SDK call — no to_dict() boilerplate required.
What's supported
Surface
Status
Blocks
✅ All current block types, including Alert, Card, Carousel, Container, Layout (3.2.0+), Context Actions, Data Table, Data Visualization, Plan, and Task Card
Elements
✅ Buttons, all select menus, date/time pickers, checkboxes, radio groups, all input types, overflow menus, workflow buttons
Block.from_dict(data) + per-class from_dict parsers — parse the supported subset of incoming Slack JSON into slackblocks objects.
Typed exception subclasses of InvalidUsageError (LengthError, RangeError, TypeMismatchError, MutualExclusivityError, MissingRequiredError) — existing except InvalidUsageError blocks continue to work.
Tighter type signatures: Literal narrowing on Button.style, ColumnSettings.align, ConversationFilter.include; @overload on Text.to_text so the return type narrows on allow_none.
Modern annotation syntax (list[X], X | Y) throughout.
Existing 1.x code continues to work unchanged; see the Migration Guide for the full diff.
The official slack-sdk ships its own block classes. slackblocks predates them and offers a more concise API, stricter up-front validation, and independent versioning. They produce equivalent JSON; pick whichever you find more ergonomic.
# slackblocks
SectionBlock("Hello, *world*!")
# slack-sdk equivalent
from slack_sdk.models.blocks import SectionBlock as SDKSectionBlock
from slack_sdk.models.blocks.basic_components import MarkdownTextObject
SDKSectionBlock(text=MarkdownTextObject(text="Hello, *world*!"))
Licensing
slackblocks is dual-licensed under MIT and BSD-3-Clause. Use whichever fits your project — this makes it safe to vendor into projects under either license.
Contributing
Contributions are welcome. Quick start (the project uses uv for dependency management):
git clone https://github.com/nicklambourne/slackblocks.git
cd slackblocks/python
uv sync --all-groups
uv run pytest test/unit test/conformance test/docs
uv run ruff format --check slackblocks test
uv run ruff check slackblocks test
uv run mypy slackblocks
Preview the documentation from the repository root with pnpm --filter @slackblocks/docs start.
For the full development guide — testing conventions, validation patterns, docstring style, release process, and a PR checklist — see the Contributing page.