Skip to main content

Slack Blocks Wrapper

Slack blocks wrapper is a python3 wrapper around the slack blocks framework. It provides a simple way to create and send blocks to slack.

Installation

pip install slack-blocks-wrapper

Slack blocks wrapper has no dependencies outside python3. Currently, it is only supported and tested on python3.9.

Usage

You can use the wrapper to create blocks in a few different ways.

Here's an example of a section with a multi-static select menu:

from slack_blocks_wrapper import section

multistatic_select_node = section.multistatic_select_element(
    placeholder="Select a color",
    action_id="color_select",
    options=[
        section.text_element(
            text="Red",
            text_type=section.TextType.PLAIN_TEXT,
            value="red"
        ),
        section.text_element(
            text="Green",
            text_type=section.TextType.PLAIN_TEXT,
            value="green"
        ),
        section.text_element(
            text="Blue",
            text_type=section.TextType.PLAIN_TEXT,
            value="blue"
        )
    ]
)

You can use this element with the Bolt framework to create a multi-static select menu as follows:

import logging
import os
from flask import Flask, request
from slack_bolt import App

from slack_bolt.adapter.flask import SlackRequestHandler
from slack_blocks_wrapper import section, elements

block_element = section.multi_static_select(
    text="Select a color",
    action_id="color_select",
    options=[
        elements.text_element(
            text="Red",
            text_type=elements.TextType.PLAIN_TEXT,
            value="red"
        ),
        elements.text_element(
            text="Green",
            text_type=section.TextType.PLAIN_TEXT,
            value="green"
        ),
        elements.text_element(
            text="Blue",
            text_type=section.TextType.PLAIN_TEXT,
            value="blue"
        )
    ]
)
app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)
bolt_app = App()
handler = SlackRequestHandler(bolt_app)


@bolt_app.command("/hello-world")
def hello(ack):
    ack(blocks=[block_element])


@app.route("/slack/events", methods=["POST"])
def slack_events():
    return handler.handle(request)


# Only for local debug
if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 3000)))

Thus far, the following block kit builder elements are supported:

  1. Section - All section elements are supported.
  2. Actions - All action elements are supported.
  3. Context - All context elements are supported.
  4. Divider - All divider elements are supported.
  5. Image - All image elements are supported.
  6. Input - All input elements are supported.
  7. Header - All header elements are supported.
  8. Divider - All divider elements are supported.

Better documentation and implementation improvements are coming soon.

Metadata

Release files for slack-blocks-wrapper 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slack-blocks-wrapper 0.2.5
File Size Uploaded
slack-blocks-wrapper-0.2.5.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slack-blocks-wrapper 0.2.5
File Interpreter ABI Platform
slack_blocks_wrapper-0.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 31.0 kB

Release files / slack-blocks-wrapper-0.2.5.tar.gz

Download URL slack-blocks-wrapper-0.2.5.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ebdd0fd829cf5dde145fbce7328c35cae80a5ee9c567b04962bcd27a29f1c8d1
BLAKE2b-256 checksum
How to use checksums
9163dd43f42372eb1b361dc2dfed058f621d90ec4c696cbe0b59b83a8095143b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.7

Release files / slack_blocks_wrapper-0.2.5-py3-none-any.whl

Download URL slack_blocks_wrapper-0.2.5-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f19958fa00457417d0e6fe16da1e5ea33d361e942fe694770a6b1ead23c3cad
BLAKE2b-256 checksum
How to use checksums
7ce76313d11511aa8f642ecd1c821d41342c994681410018436cbbc45a18ebd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.7

Release history Release notifications | RSS feed

0.2.6

2 release files

This release

0.2.5 This release

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page