Skip to main content

prefect-dingtalk-notification

Python Prefect

一个用于 Prefect 的钉钉自定义机器人通知 Block

安装

uv add prefect-dingtalk-notification

使用

添加自定义机器人

添加自定义机器人

注: 选择 自定义 (通过Webhook接入自定义服务) 机器人

使用 DingTalkCustomRobotGroupWebhookNotification

直接发送通知

import asyncio
import json

from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification


async def main() -> None:
    notification = DingTalkCustomRobotGroupWebhookNotification(
        access_token="<access-token>",
        secret="<secret>",  # 可选, 基于你的机器人设置
    )
    await notification.notify(
        body=json.dumps(
            {
                "msgtype": "text",
                "text": {"content": "Prefect notification test"},
            },
            ensure_ascii=False,
        ),
    )


if __name__ == "__main__":
    asyncio.run(main())

保存为 Block 使用

from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification

notification_block = DingTalkCustomRobotGroupWebhookNotification(
    access_token="<access-token>",
    secret="<secret>",
)
block_document_id = notification_block.save("dingtalk-demo")

加载 Block

from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification

notification_block = DingTalkCustomRobotGroupWebhookNotification.load(
    "dingtalk-production"
)

在 Automation 中发送通知

Prefect Automation 的 SendNotification action 接受 Block document ID。下面的示例会在收到指定事件时调用本项目的 Block:

from prefect.automations import Automation, EventTrigger, SendNotification
from prefect.events import emit_event
from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification

notification = DingTalkCustomRobotGroupWebhookNotification(
    access_token="<access-token>",
    secret="<secret>",
)
block_id = notification.save("dingtalk-demo")
event_name = "example.build.finished"

automation = Automation(
    name="notify-dingtalk-on-build",
    trigger=EventTrigger(
        expect={event_name},
        match={"environment": "ci"},
    ),
    actions=[
        SendNotification(
            block_document_id=block_id,
            subject="Build notification",
            body=('{"msgtype":"text","text":{"content":"Prefect CI build finished"}}'),
        )
    ],
).create()

emit_event(
    event=event_name,
    resource={
        "prefect.resource.id": "example.build.123",
        "environment": "ci",
    },
)

Metadata

Release files for prefect-dingtalk-notification 0.1.0

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

Source distribution (sdist)

Source distribution for prefect-dingtalk-notification 0.1.0
File Size Uploaded
prefect_dingtalk_notification-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prefect-dingtalk-notification 0.1.0
File Interpreter ABI Platform
prefect_dingtalk_notification-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / prefect_dingtalk_notification-0.1.0.tar.gz

Download URL prefect_dingtalk_notification-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c97a1277075e7e8f151965d5665aefdb954db1629e13b31958e3fc12a3364bc0
BLAKE2b-256 checksum
How to use checksums
7cfe8f600159a8ac2ea544b48d9cf95136adba6e6d79ad2a4dcf13af868b3981
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / prefect_dingtalk_notification-0.1.0-py3-none-any.whl

Download URL prefect_dingtalk_notification-0.1.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ceaa7f31aa5e8440868ae32bcd65764831cc7128ad58dd46634a568e87b48c52
BLAKE2b-256 checksum
How to use checksums
71ea3532071ba45b4da102e4021afaacefaa8fb62a434f17baf7c9990a10b834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

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