Skip to main content

Welcome to slackblocks!

slackblocks logo

slackblocks builds Slack messages with the Block Kit API in Python and TypeScript — without writing JSON by hand.

It exists because Block Kit JSON is verbose, easy to get subtly wrong, and unpleasant to maintain in source control. slackblocks gives you:

  • Typed, idiomatic APIs for Python and TypeScript.
  • Validation as you build — 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 compatibility with the official Slack SDKs and their plain JSON payloads.
  • Zero runtime dependencies.

Quick Start

Ready to build your first message? The Quick Start guide takes you from installation to a validated Slack payload using the language selected in the top navigation.

Components

The Slack Block Kit API defines several resource types (all defined in JSON) that work together to build block-based messages.

The Python package mirrors that hierarchy with classes.

Objects

Objects (e.g. Text, Option, Confirm) are the lowest-level primitives — small composable pieces that populate Elements and Blocks.

For convenience, PlainText and Markdown are thin subclasses of Text that you can use anywhere a Text is expected — PlainText("Hi", emoji=True) reads more naturally than Text("Hi", type_=TextType.PLAINTEXT, emoji=True).

Elements

Elements are typically interactive UI controls that go inside blocks. The CheckboxGroup element, for instance, takes one or more Option items and presents a checkbox menu.

Blocks

Blocks are the core visual unit of a message. Different block classes produce different UI:

See Using Blocks for examples of all block types side-by-side with their JSON output and Slack rendering.

Messages

Messages are a convenience wrapper around blocks that can be unpacked directly into the Slack SDK's chat_postMessage (and friends).

Views

Views are an alternative usage of blocks that build custom UI surfaces in Slack — modal dialogs and the App Home tab — typically used by interactive Slack apps.

Utilities

Guides