Skip to main content

Slack API Types in Python

Project description

slack-types

Pydantic v2 type definitions for the Slack APIs:

  • Web API (slack_types.web_api)
  • Events API (slack_types.events_api)
  • Real Time Messaging API (slack_types.rtm_api)
  • App backend payloads (slack_types.app_backend.{dialogs,interactive_components,slash_commands,views})
  • Audit Logs API (slack_types.audit_api.v1)
  • SCIM API (slack_types.scim_api.{v1,v2})

PyPI: https://pypi.org/project/slack-types

Install

uv add slack-types
# or
pip install slack-types

Use

from typing import Callable

from slack_bolt.async_app import AsyncApp
from slack_sdk.web.async_client import AsyncWebClient
from slack_types.events_api.app_mention_payload import Event as AppMentionEvent

app = AsyncApp()


@app.event("app_mention")
async def handle_mentions(event: dict, client: AsyncWebClient, say: Callable):
    mention = AppMentionEvent.model_validate(event)
    await client.reactions_add(
        channel=mention.channel,
        timestamp=mention.ts,
        name="eyes",
    )
    await say("What's up?")


if __name__ == "__main__":
    app.start(3000)

Web API responses use the same Pydantic interface:

from slack_types.web_api.conversations_history_response import ConversationsHistoryResponse

response = await client.conversations_history(channel="C123")
history = ConversationsHistoryResponse.model_validate(response.data)
for message in history.messages or []:
    print(message.ts, message.text)

All fields are Optional with defaults of None because Slack does not guarantee any field on any response. Validate at the boundary; don't rely on required-ness.

How types are generated

Input samples come from java-slack-sdk (recorded JSON responses). Each sample is converted to a JSON Schema with genson, then handed to datamodel-code-generator to emit a Pydantic v2 module.

Coverage may not be 100% and some properties may be incorrect. File issues at https://github.com/warrenseine/slack-types/issues.

To re-generate:

uv sync --group dev
uv run python scripts/build.py  # clones java-slack-sdk/ on first run
uv run pytest                   # smoke + round-trip tests

To publish:

uv build
uv publish

License

MIT

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

slack_types-1.2.0.tar.gz (177.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slack_types-1.2.0-py3-none-any.whl (463.5 kB view details)

Uploaded Python 3

File details

Details for the file slack_types-1.2.0.tar.gz.

File metadata

  • Download URL: slack_types-1.2.0.tar.gz
  • Upload date:
  • Size: 177.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for slack_types-1.2.0.tar.gz
Algorithm Hash digest
SHA256 034c9fdf365d630a041ee325660fe0146f0b6e83ec136ed07ba63373f8a8da18
MD5 af0c471459650fed3647363d934a549c
BLAKE2b-256 752382f08e17cb9b6a40f10293c1ab036dd128d0f8aeecd24526501123fbfd79

See more details on using hashes here.

File details

Details for the file slack_types-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: slack_types-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 463.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for slack_types-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82e4725a13458f02a4fe1b9b5cbf4ce31df7ca652257c6afb3713e653c1ba7e0
MD5 dc18e60a500fdfb27ea2d437a1a8ac2f
BLAKE2b-256 71124b97f09bb2b4b0fe119d048021d6e104cf859e1204b569605116fd8f5c4e

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