Installation
Choose a language from the site navigation. The selection applies across the documentation and is preserved as you move between pages.
Install the Python package from PyPI:
- pip
- Poetry
- Pipenv
- uv
pip install slackblocks
poetry add slackblocks
pipenv install slackblocks
uv add slackblocks
Python 2.x requires Python 3.10 or newer and has no runtime dependencies. See Compatibility for the support matrix and 1.x migration guidance.
Verify the installation:
from slackblocks import Message, SectionBlock
print(Message(channel="#general", blocks=SectionBlock("Hello, world!")).json())
Pin the current major release with slackblocks~=2.0, and uninstall with pip uninstall slackblocks (or the equivalent command for your package manager).
Install the ESM package from npm:
- pnpm
- npm
- Yarn
pnpm add @nicklambourne/slackblocks
npm install @nicklambourne/slackblocks
yarn add @nicklambourne/slackblocks
The package requires Node 20.19 or newer, is ESM-only, and emits no runtime imports beyond your own code.
Verify the installation in hello.mjs:
import { Message, SectionBlock } from "@nicklambourne/slackblocks";
console.log(
Message()
.channel("C0123456")
.blocks(SectionBlock().text("Hello, world!"))
.build(),
);
Run it with node hello.mjs. Stay on the 2.x release line with @nicklambourne/slackblocks@^2.1.0, and uninstall with pnpm remove @nicklambourne/slackblocks (or your package manager's equivalent).
From an existing Go module, install the v2 Go module directly from GitHub:
go get github.com/nicklambourne/slackblocks/go/v2
Go 1.22 or newer is required. Block builders implement slack.Block directly using the Go 1.22-compatible github.com/slack-go/slack release; go get installs that dependency automatically.
Verify the installation in main.go:
package main
import (
"fmt"
slackblocks "github.com/nicklambourne/slackblocks/go/v2"
)
func main() {
payload, err := slackblocks.NewMessage().
Channel("C0123456").
Blocks(slackblocks.NewSectionBlock().Text("Hello, world!")).
Build()
if err != nil {
panic(err)
}
fmt.Println(payload)
}
Run it with go run .. The /v2 suffix is part of the module path under Go's semantic import versioning; update within the current major line with go get -u github.com/nicklambourne/slackblocks/go/v2.
Install the Java artifact from Maven Central. Java 17 or newer is required.
- Maven
- Gradle (Kotlin)
- Gradle (Groovy)
<dependency>
<groupId>io.github.nicklambourne</groupId>
<artifactId>slackblocks</artifactId>
<version>2.5.0</version>
</dependency>
implementation("io.github.nicklambourne:slackblocks:2.5.0")
implementation 'io.github.nicklambourne:slackblocks:2.5.0'
The core artifact includes the official Slack Block Kit model interfaces so completed blocks can be passed directly to the Slack Java SDK. Add com.slack.api:slack-api-client separately when your application sends messages; keeping the transport client optional avoids pulling HTTP dependencies into applications that only construct payloads.
Verify the installation:
import io.github.nicklambourne.slackblocks.SlackblocksJson;
import io.github.nicklambourne.slackblocks.block.SectionBlock;
public final class HelloSlackblocks {
public static void main(String[] args) {
var block = SectionBlock.builder().markdownText("Hello, world!").build();
System.out.println(SlackblocksJson.write(block));
}
}
Import slackblocks types by name
Several slackblocks class names, such as SectionBlock, HeaderBlock, and ButtonElement, also exist in the Slack SDK's com.slack.api.model.block packages. Import slackblocks classes individually, as the examples on this site do. A file that combines import com.slack.api.model.block.*; with a slackblocks wildcard import fails to compile with a "reference to SectionBlock is ambiguous" error.
Pin compatible 2.x updates with Maven's dependency-management facilities or your usual version catalog. slackblocks' Java artifact uses the same release number as the Python, TypeScript, and Go packages.
Install the NuGet package. .NET 8 or newer is required.
- .NET CLI
- PackageReference
dotnet add package Slackblocks
<PackageReference Include="Slackblocks" Version="2.5.0" />
The package depends on nothing beyond .NET itself. It builds and validates payloads and leaves delivery to HttpClient or the Slack client library you already use.
Verify the installation:
using Slackblocks.Blocks;
var block = new SectionBlock(text: "Hello, world!");
Console.WriteLine(block.ToJson());
Alias a namespace when combining Slack libraries
Some slackblocks type names, such as SectionBlock and ButtonElement, also exist in .NET Slack client libraries such as SlackNet. A file that imports both namespaces fails to compile with an ambiguous reference error. Import only the namespaces a file needs, or alias one of them:
using Blocks = Slackblocks.Blocks;
var block = new Blocks.SectionBlock(text: "Hello, world!");
The NuGet package version moves in lockstep with the Python, TypeScript, Go, and Java packages. A floating version such as 2.* accepts compatible 2.x updates.
Install the gem from RubyGems after the coordinated Ruby release. MRI Ruby 3.3 or newer is required.
gem install slackblocks
Or add it to your Gemfile:
gem "slackblocks", "~> 2.6"
The runtime uses Ruby and the default json gem. It does not install a Slack transport client.
Verify the installation:
require "slackblocks"
message = Slackblocks::MessagePayload.new(
channel: "C01234567",
text: "Hello, world!",
blocks: [Slackblocks::SectionBlock.new(text: "Hello, world!")]
)
puts message.to_json
Uninstall with gem uninstall slackblocks.