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.6.tar.gz (8.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: slackuiblocks-0.0.6.tar.gz
  • Upload date:
  • Size: 8.8 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.6.tar.gz
Algorithm Hash digest
SHA256 ae65a6e63a3ea3bbe5c3ed0c48b507a971767ee69d01b19b67ea8bb74bb138a9
MD5 20d94235ea19c35f81702a5311b7f416
BLAKE2b-256 86898645291ac3b92904ba35d2d78d9d117d5f41542c704e9cc7740d591d355e

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