Skip to main content

Slack UI Blocks is a Python library that makes it easy to create and manage Slack UI blocks. It provides a high-level API that abstracts away the details of the Slack Block Kit JSON format, making it easy to build complex UIs with just a few lines of code.

Project description

slackuiblocks - Simplify Slack UI Block Creation with Python Classes

PyPI Version License

slackuiblocks is a Python library that provides an intuitive and elegant way to create Slack UI blocks using Python classes instead of dealing with complex JSON structures. With this library, you can easily craft interactive and visually appealing messages for your Slack channels or direct messages.

Features

  • Simplified Syntax: Define Slack UI blocks using Python classes, making it easier to structure your messages.
  • Interactive Elements: Create buttons, menus, and other interactive components effortlessly.
  • Customization: Customize the appearance and behavior of UI elements using Python attributes.
  • Well-Organized: Maintain a clear and organized codebase by encapsulating UI elements within classes.

Installation

You can install slackuiblocks using pip:

pip install slackuiblocks

Usage Example

Here's a simple example of how you can use slackuiblocks to create a message with interactive buttons:

from slack_sdk import WebClient
from slackuiblocks import Section, MarkdownText, Datepicker, PlainText

message = Blocks(
    blocks=[
        Section(
            text=MarkdownText(
                text=(
                    "*Sally* has requested you set the deadline for the Nano "
                    "launch project"
                )
            ),
            accessory=Datepicker(
                action_id="datepicker123",
                initial_date="1990-04-28",
                placeholder=PlainText(text="Select a date"),
            ),
        )
    ]
)

# Get the JSON representation of the block
block_json = message.dict(exclude_none=True)

# Use block_json in your Slack API request
channel = "your channel id"
try:
    client.chat_postMessage(
        channel=channel,
        text="message",
        blocks=block_json.get("blocks"),
    )
except Exception as e:
    print(e)

For more complex interactions, you can create menus, input fields, and more using Python classes just like the example above.

Documentation

For detailed usage instructions, examples, and a comprehensive list of available UI elements, refer to the Documentation.

Contributing

Contributions are welcome! To contribute to slackuiblocks, follow the guidelines outlined in CONTRIBUTING.md.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slackuiblocks-0.0.7.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file slackuiblocks-0.0.7.tar.gz.

File metadata

  • Download URL: slackuiblocks-0.0.7.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for slackuiblocks-0.0.7.tar.gz
Algorithm Hash digest
SHA256 05a4361d4adb409c7630e117a9224ad17b4696ad028cc2afafb4c0910c872c6e
MD5 26a96dea565e3dc5a008bef7fd3fc38b
BLAKE2b-256 6333664eb53c1d01f6b178b6e76a74102200ed9a408a1579b0212a876207e989

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page