Skip to main content

deco_slack notifies you if a method has completed successfully or not.

Project description

decoslack

decoslack notifies you via Slack if a method has completed successfully or not.

Description

  • Notify Slack when a process starts, ends normally, or ends abnormally.
  • Each notification can be set on or off.
  • Support dynamic message formatting based on function results or errors.

Configurations

Environment variables to set

  • {DECO_SLACK_PREFIX}SLACK_TOKEN
    • Slack bot token that can be used with chat:write.public scope.
  • {DECO_SLACK_PREFIX}SLACK_CHANNEL
    • Channel name to be notified without # (like notify_xxx not #notify_xxx)
  • DECO_SLACK_PREFIX (optional)
    • Prefix for environment variables.
      • If not set, defaults to "".

Example

from deco_slack import deco_slack


@deco_slack(
    # These parameters are all optional
    start={
        "text": "start text",
        "title": 'start',
        "color": "good"
    },
    success={
        "text": "success text",
        "title": 'success',
        "color": "good"
    },
    error={
        "title": 'error',
        "color": "danger",
        "stacktrace": True # Set True if you need stacktrace in a notification
    },
)
def test1():
    print('test1')


# Dynamic message formatting example
@deco_slack(
    success={
        "text_formatter": lambda result: f"Process completed with result: {result}",
        "title": "Success",
        "color": "good"
    },
    error={
        "text_formatter": lambda e: f"Error occurred: {str(e)}",
        "title": "Error",
        "color": "danger",
        "stacktrace": True
    }
)
def process_data(data):
    result = data * 2
    return result

Advanced Features

Dynamic Message Formatting

You can customize notification messages based on function results or errors using text_formatter and title_formatter:

@deco_slack(
    success={
        "text_formatter": lambda result: f"Process completed with result: {result}",
        "title_formatter": lambda result: f"Success: {result}",
        "color": "good"
    },
    error={
        "text_formatter": lambda e: f"Error details: {str(e)}",
        "color": "danger"
    }
)
def your_function():
    # Your code here
    pass

The formatters receive:

  • success: The function's return value
  • error: The exception object

This allows you to create more informative and context-aware notifications.

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

deco_slack-0.0.3.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

deco_slack-0.0.3-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file deco_slack-0.0.3.tar.gz.

File metadata

  • Download URL: deco_slack-0.0.3.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-1020-azure

File hashes

Hashes for deco_slack-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4b42d6cfe8d1a56f035a0b537603167127f70e6587e0662b82a9cb7f8f65de93
MD5 dc638e37a8b016789e65b0dd4edbec06
BLAKE2b-256 8dcec0ea2885bfa01c798b4d55c9c6dd70aba1a7455e0748ad11cf1b6bc7f494

See more details on using hashes here.

File details

Details for the file deco_slack-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: deco_slack-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-1020-azure

File hashes

Hashes for deco_slack-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 484f572530eaed1372910c2077464ca6c637c7cd7bc83096a31e5a2c7a850d37
MD5 e0c0ea47a45167a79b633af07f2906c2
BLAKE2b-256 3aa425b9a2c1f14bc7dc06bca276f9149d9dede753f80e4700a86e419ac5907e

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