Skip to main content

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.

Release files for deco_slack 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deco_slack 0.0.5
File Size Uploaded
deco_slack-0.0.5.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for deco_slack 0.0.5
File Interpreter ABI Platform
deco_slack-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / deco_slack-0.0.5.tar.gz

Download URL deco_slack-0.0.5.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
49d0c9fda4410e1e4dac04c1f4b2bd578b858289ec311f15656ca050e4b33af2
BLAKE2b-256 checksum
How to use checksums
d58df2eecdbc7cf15a1c629ff41938c98a69747117c47cc8bae9bc8e220f4bea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1018-azure

Release files / deco_slack-0.0.5-py3-none-any.whl

Download URL deco_slack-0.0.5-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a52218554329a00512d634b3585e8b9857d0950b14f8023d659fa5cb72ee088
BLAKE2b-256 checksum
How to use checksums
87fc0b65dd351709b4abaa5f26a267c67a4a7a60d52756790375fb302a9987e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1018-azure

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page