# slackblocks <img src="https://github.com/nicklambourne/slackblocks/raw/master/docs_src/img/sb.png" align="right" width="250px"/>
![Licence: MIT](https://img.shields.io/badge/License-MIT-green.svg)
![Licence: BSD-3-Clause](https://img.shields.io/badge/License-BSD_3_Clause-green.svg)
![Python Versions](https://img.shields.io/pypi/pyversions/slackblocks)
[![PyPI](https://img.shields.io/pypi/v/slackblocks?color=yellow&label=PyPI&logo=python&logoColor=white)](https://pypi.org/project/slackblocks/#history)
[![Downloads](https://static.pepy.tech/badge/slackblocks)](https://pepy.tech/project/slackblocks)
[![Build Status](https://github.com/nicklambourne/slackblocks/actions/workflows/unit-tests.yml/badge.svg?branch=master)](https://github.com/nicklambourne/slackblocks/actions)
[![Docs](https://img.shields.io/badge/Docs-8A2BE2.svg)](https://nicklambourne.github.io/slackblocks)
## What is it?
`slackblocks` is a Python API for building messages in the fancy Slack [Block Kit API](https://api.slack.com/block-kit)
## Documentation
Full documentation is provided [here](https://nicklambourne.github.io/slackblocks/latest/).
## Requirements
`slackblocks` requires Python >= 3.8.
As of version 0.1.0 it has no dependencies outside the Python standard library.
## Installation
```bash
pip install slackblocks
```
## Basic Usage
```python
from slackblocks import Message, SectionBlock
block = SectionBlock("Hello, world!")
message = Message(channel="#general", blocks=block)
message.json()
```
Will produce the following JSON string:
```json
{
"channel": "#general",
"mrkdwn": true,
"blocks": [
{
"type": "section",
"block_id": "992ceb6b-9ad4-496b-b8e6-1bd8a632e8b3",
"text": {
"type": "mrkdwn",
"text": "Hello, world!"
}
}
]
}
```
Which can be sent as payload to the Slack message API HTTP endpoints.
Of more practical use is the ability to unpack the objects directly into
the [(Legacy) Python Slack Client](https://pypi.org/project/slackclient/) in order to send messages:
```python
from os import environ
from slack import WebClient
from slackblocks import Message, SectionBlock
client = WebClient(token=environ["SLACK_API_TOKEN"])
block = SectionBlock("Hello, world!")
message = Message(channel="#general", blocks=block)
response = client.chat_postMessage(**message)
```
Or the modern Python [Slack SDK](https://pypi.org/project/slack-sdk/):
```python
from os import environ
from slack_sdk import WebClient
from slackblocks import Message, SectionBlock
client = WebClient(token=environ["SLACK_API_TOKEN"])
block = SectionBlock("Hello, world!")
message = Message(channel="#general", blocks=block)
response = client.chat_postMessage(**message)
```
Note the `**` operator in front of the `message` object.
## Can I use this in my project?
Yes, please do! The code is all open source and dual BSD-3.0 and MIT licensed
(use what suits you best).
Raw data
{
"_id": null,
"home_page": "https://github.com/nicklambourne/slackblocks",
"name": "slackblocks",
"maintainer": "Nicholas Lambourne",
"docs_url": null,
"requires_python": ">=3.8.0",
"maintainer_email": "dev@ndl.im",
"keywords": "slackblocks, slack, messaging, message generation, slack blocks, blocks",
"author": "Nicholas Lambourne",
"author_email": "dev@ndl.im",
"download_url": "https://files.pythonhosted.org/packages/68/f5/30bc8800ebee58f4a753606e702db5522b3149ebeaff9c13982e139390f5/slackblocks-1.0.13.tar.gz",
"platform": null,
"description": "# slackblocks <img src=\"https://github.com/nicklambourne/slackblocks/raw/master/docs_src/img/sb.png\" align=\"right\" width=\"250px\"/>\n\n![Licence: MIT](https://img.shields.io/badge/License-MIT-green.svg)\n![Licence: BSD-3-Clause](https://img.shields.io/badge/License-BSD_3_Clause-green.svg)\n![Python Versions](https://img.shields.io/pypi/pyversions/slackblocks)\n[![PyPI](https://img.shields.io/pypi/v/slackblocks?color=yellow&label=PyPI&logo=python&logoColor=white)](https://pypi.org/project/slackblocks/#history)\n[![Downloads](https://static.pepy.tech/badge/slackblocks)](https://pepy.tech/project/slackblocks)\n[![Build Status](https://github.com/nicklambourne/slackblocks/actions/workflows/unit-tests.yml/badge.svg?branch=master)](https://github.com/nicklambourne/slackblocks/actions)\n[![Docs](https://img.shields.io/badge/Docs-8A2BE2.svg)](https://nicklambourne.github.io/slackblocks)\n\n## What is it?\n`slackblocks` is a Python API for building messages in the fancy Slack [Block Kit API](https://api.slack.com/block-kit)\n\n## Documentation\nFull documentation is provided [here](https://nicklambourne.github.io/slackblocks/latest/).\n\n## Requirements\n`slackblocks` requires Python >= 3.8.\n\nAs of version 0.1.0 it has no dependencies outside the Python standard library.\n\n## Installation\n```bash\npip install slackblocks\n```\n\n## Basic Usage\n```python\nfrom slackblocks import Message, SectionBlock\n\n\nblock = SectionBlock(\"Hello, world!\")\nmessage = Message(channel=\"#general\", blocks=block)\nmessage.json()\n\n```\n\nWill produce the following JSON string:\n```json\n{\n \"channel\": \"#general\",\n \"mrkdwn\": true,\n \"blocks\": [\n {\n \"type\": \"section\",\n \"block_id\": \"992ceb6b-9ad4-496b-b8e6-1bd8a632e8b3\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"Hello, world!\"\n }\n }\n ]\n}\n```\nWhich can be sent as payload to the Slack message API HTTP endpoints.\n\nOf more practical use is the ability to unpack the objects directly into \nthe [(Legacy) Python Slack Client](https://pypi.org/project/slackclient/) in order to send messages:\n\n```python\nfrom os import environ\nfrom slack import WebClient\nfrom slackblocks import Message, SectionBlock\n\n\nclient = WebClient(token=environ[\"SLACK_API_TOKEN\"])\nblock = SectionBlock(\"Hello, world!\")\nmessage = Message(channel=\"#general\", blocks=block)\n\nresponse = client.chat_postMessage(**message)\n```\n\nOr the modern Python [Slack SDK](https://pypi.org/project/slack-sdk/):\n```python\nfrom os import environ\nfrom slack_sdk import WebClient\nfrom slackblocks import Message, SectionBlock\n\n\nclient = WebClient(token=environ[\"SLACK_API_TOKEN\"])\nblock = SectionBlock(\"Hello, world!\")\nmessage = Message(channel=\"#general\", blocks=block)\n\nresponse = client.chat_postMessage(**message)\n```\n\nNote the `**` operator in front of the `message` object.\n\n## Can I use this in my project?\nYes, please do! The code is all open source and dual BSD-3.0 and MIT licensed\n (use what suits you best).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python wrapper for the Slack Blocks API",
"version": "1.0.13",
"project_urls": {
"Homepage": "https://github.com/nicklambourne/slackblocks",
"Repository": "https://github.com/nicklambourne/slackblocks"
},
"split_keywords": [
"slackblocks",
" slack",
" messaging",
" message generation",
" slack blocks",
" blocks"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "856c5ec7d3a959eea4e36fa5bf809bc9748f2b23545498edd828765db24c20df",
"md5": "cd12e5ad52816126c990cf303f6ee59d",
"sha256": "366c0366657848fa1fb182e2bd7006eb5b855f834b4a2aba1de4696ceb6479d6"
},
"downloads": -1,
"filename": "slackblocks-1.0.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cd12e5ad52816126c990cf303f6ee59d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.0",
"size": 36398,
"upload_time": "2024-11-19T08:10:08",
"upload_time_iso_8601": "2024-11-19T08:10:08.397008Z",
"url": "https://files.pythonhosted.org/packages/85/6c/5ec7d3a959eea4e36fa5bf809bc9748f2b23545498edd828765db24c20df/slackblocks-1.0.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "68f530bc8800ebee58f4a753606e702db5522b3149ebeaff9c13982e139390f5",
"md5": "aaa2fc49a918d23c2caa32b80e8915b9",
"sha256": "221c4d900c313af87f9dd5b5cfdf5019c0b0f801b55f304ba8631fef9beafffb"
},
"downloads": -1,
"filename": "slackblocks-1.0.13.tar.gz",
"has_sig": false,
"md5_digest": "aaa2fc49a918d23c2caa32b80e8915b9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.0",
"size": 31083,
"upload_time": "2024-11-19T08:10:11",
"upload_time_iso_8601": "2024-11-19T08:10:11.831166Z",
"url": "https://files.pythonhosted.org/packages/68/f5/30bc8800ebee58f4a753606e702db5522b3149ebeaff9c13982e139390f5/slackblocks-1.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-19 08:10:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nicklambourne",
"github_project": "slackblocks",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "slackblocks"
}