Skip to main content

Slack API client library for kiarina namespace

Project description

kiarina-lib-slack

PyPI version Python License: MIT

English | 日本語

[!NOTE] What is this? A package for managing Slack app credentials and OAuth information with pydantic-settings-manager.

Dependencies

Package Version License
Pydantic Settings >=2.10.1 MIT
pydantic-settings-manager >=3.2.0 MIT

A Slack SDK is not included as a dependency. Add one to the application that creates the Slack client.

Installation

pip install kiarina-lib-slack

Features

  • Configuring a Slack App Store Slack app credentials, OAuth scopes, and workspace information.
  • Managing Multiple Apps Switch between named settings for multiple Slack apps.
  • Loading Environment Variables Load environment variables with the KIARINA_LIB_SLACK_ prefix.
  • Using Socket Mode Store an app-level token for Socket Mode.
  • Protecting Secrets Store client secrets, signing secrets, and tokens as SecretStr.

Configuring a Slack App

app_id, client_id, client_secret, and signing_secret are required.

from kiarina.lib.slack import SlackSettings

settings = SlackSettings(
    app_id="A0123456789",
    client_id="123456789.123456789",
    client_secret="client-secret",
    signing_secret="signing-secret",
    bot_token="xoxb-...",
    scopes=["chat:write"],
)

Managing Multiple Apps

settings_manager uses multiple-settings mode. Place named settings under configs.

kiarina.lib.slack:
  default: production
  configs:
    development:
      app_id: A_DEVELOPMENT
      client_id: development-client
      client_secret: development-secret
      signing_secret: development-signing-secret
    production:
      app_id: A_PRODUCTION
      client_id: production-client
      client_secret: production-secret
      signing_secret: production-signing-secret
import yaml
from pydantic_settings_manager import load_user_configs

from kiarina.lib.slack import settings_manager

with open("config.yaml", encoding="utf-8") as file:
    load_user_configs(yaml.safe_load(file) or {})

settings = settings_manager.get_settings("production")

Loading Environment Variables

Set the scopes list as a JSON array.

export KIARINA_LIB_SLACK_APP_ID="A0123456789"
export KIARINA_LIB_SLACK_CLIENT_ID="123456789.123456789"
export KIARINA_LIB_SLACK_CLIENT_SECRET="client-secret"
export KIARINA_LIB_SLACK_SIGNING_SECRET="signing-secret"
export KIARINA_LIB_SLACK_SCOPES='["chat:write"]'
from kiarina.lib.slack import SlackSettings

settings = SlackSettings()

Using Socket Mode

For Socket Mode, set an xapp- token as app_token.

settings = SlackSettings(
    app_id="A0123456789",
    client_id="123456789.123456789",
    client_secret="client-secret",
    signing_secret="signing-secret",
    app_token="xapp-...",
)

Protecting Secrets

Extract secret values only where they are passed to an SDK.

bot_token = (
    settings.bot_token.get_secret_value()
    if settings.bot_token is not None
    else None
)

API Reference

kiarina.lib.slack

from kiarina.lib.slack import (
    SlackSettings,
    settings_manager,
)

SlackSettings

class SlackSettings(BaseSettings):
    def __init__(
        self,
        *,
        app_id: str,
        client_id: str,
        client_secret: SecretStr,
        signing_secret: SecretStr,
        app_token: SecretStr | None = None,
        scopes: list[str] = [],
        team_id: str | None = None,
        enterprise_id: str | None = None,
        bot_token: SecretStr | None = None,
    ) -> None: ...

Slack app settings.

Fields

  • app_id (str): Slack app ID.
  • client_id (str): Slack OAuth client ID.
  • client_secret (SecretStr): Slack OAuth client secret.
  • signing_secret (SecretStr): Slack request signing secret.
  • app_token (SecretStr | None): App-level token for Socket Mode.
  • scopes (list[str]): OAuth scopes requested by the Slack app.
  • team_id (str | None): Slack workspace ID.
  • enterprise_id (str | None): Slack Enterprise Grid organization ID.
  • bot_token (SecretStr | None): Slack bot user OAuth token.

settings_manager

settings_manager: SettingsManager[SlackSettings]

Global instance that manages named Slack app settings.

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

kiarina_lib_slack-2.3.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

kiarina_lib_slack-2.3.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file kiarina_lib_slack-2.3.1.tar.gz.

File metadata

  • Download URL: kiarina_lib_slack-2.3.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kiarina_lib_slack-2.3.1.tar.gz
Algorithm Hash digest
SHA256 44fae230bb19c73419d262d0d1626292e7ff9a5e731155fb89b7df1e29d05b0c
MD5 a89199996cf1289461e3818b19c9927b
BLAKE2b-256 6d7baebf8b0092f3339d8bac298ae670a6a9c59560ee6c5368e69ccf394ceb92

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiarina_lib_slack-2.3.1.tar.gz:

Publisher: release-pypi.yml on kiarina/kiarina-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kiarina_lib_slack-2.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for kiarina_lib_slack-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f7dd0a70076faedbcc1497fcbd4ec47674d11335814b68653fcd7b8fd3580bd
MD5 73b1cfa513d4cc005968e66c25f3b976
BLAKE2b-256 21820b73002f42c55298d0365fa44406853be536bd943017a67cae88f119f234

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiarina_lib_slack-2.3.1-py3-none-any.whl:

Publisher: release-pypi.yml on kiarina/kiarina-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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