{"id":22379,"library":"slackblocks","title":"Slack Blocks API Python Wrapper","description":"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.","status":"active","version":"1.2.3","language":"python","source_language":"en","source_url":"https://github.com/nicklambourne/slackblocks","tags":["slack","blocks","api","messaging","chat"],"install":[{"cmd":"pip install slackblocks","lang":"bash","label":"Install slackblocks"}],"dependencies":[],"imports":[{"note":"Main entry point for creating Slack messages.","symbol":"Message","correct":"from slackblocks import Message"},{"note":"Used to add section blocks to messages.","symbol":"SectionBlock","correct":"from slackblocks import SectionBlock"},{"note":"Used to add image blocks.","symbol":"ImageBlock","correct":"from slackblocks import ImageBlock"},{"note":"Used to add a divider line.","symbol":"DividerBlock","correct":"from slackblocks import DividerBlock"},{"note":"Used to add context elements.","symbol":"ContextBlock","correct":"from slackblocks import ContextBlock"}],"quickstart":{"code":"import os\nfrom slackblocks import Message, SectionBlock, ImageBlock\n\nmessage = Message(\n    channel=\"#general\",\n    text=\"Hello, world!\",\n    blocks=[\n        SectionBlock(text=\"This is a section block\"),\n        ImageBlock(image_url=\"https://example.com/image.png\", alt_text=\"Example Image\")\n    ]\n)\n# Send via slack_sdk or similar\nfrom slack_sdk import WebClient\nclient = WebClient(token=os.environ.get(\"SLACK_TOKEN\", \"\"))\nresponse = client.chat_postMessage(**message)\nprint(response)","lang":"python","description":"Construct a basic Slack message with a section and an image block, then send using slack_sdk."},"warnings":[{"fix":"Use `client.chat_postMessage(**message)` where `message` is a SlackBlocks Message object.","message":"`Message` does not directly send requests; it only builds the payload. You must use an HTTP client (e.g., slack_sdk) to send.","severity":"gotcha","affected_versions":"all"},{"fix":"Always wrap blocks: `blocks=[SectionBlock(...)]` even if one block.","message":"Blocks must be passed as a list to `Message`; passing a single block without list wrapping will break.","severity":"gotcha","affected_versions":"all"},{"fix":"Omit channel from Message constructor and set it in the HTTP call: `client.chat_postMessage(channel=\"#general\", **message)`.","message":"The `channel` parameter in `Message` may be deprecated in future versions; prefer passing channel when sending via the client.","severity":"deprecated","affected_versions":">=1.0"},{"fix":"Use plain strings: `SectionBlock(text=\"Hello\")`. For rich text, use `mrkdwn=True` or similar parameters.","message":"Text in SectionBlock must be a string, not a dict; using Block Kit object syntax incorrectly may cause errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `**message` when passing to slack_sdk: `client.chat_postMessage(**message)`. Or call `message.build()` to get a dict.","cause":"Trying to serialize the Message object directly without calling its `build()` or using `**message`","error":"TypeError: Object of type SectionBlock is not JSON serializable"},{"fix":"Run `pip install slackblocks` in your active environment.","cause":"slackblocks is not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'slackblocks'"},{"fix":"Always provide a `blocks` parameter when constructing Message, even if empty list: `blocks=[]`.","cause":"The Slack API requires a 'blocks' field in the payload, but Message without blocks may omit it.","error":"KeyError: 'blocks'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}