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="",  # leave blank
            body='{"msgtype":"text","text":{"content":"Prefect notification test"}}',
        )
    ],
).create()

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

Metadata

Release files for prefect-dingtalk-notification 0.1.1

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.1
File Size Uploaded
prefect_dingtalk_notification-0.1.1.tar.gz 4.8 kB Details

Built distribution (wheel)

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

Total release size: 11.4 kB

Release files / prefect_dingtalk_notification-0.1.1.tar.gz

Download URL prefect_dingtalk_notification-0.1.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c4d8e54d1549e90d72804c98bed70fc72b053aa71807e6c77255029f2995a482
BLAKE2b-256 checksum
How to use checksums
21a6a4bafe6935403831a97a61649621267f095706402ebe940354bf6c634670
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.1-py3-none-any.whl

Download URL prefect_dingtalk_notification-0.1.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a3e66cc8d35e66c8fd5f995ad90fb1e0d8555b2b8b0d178e9ad63743b9443bd
BLAKE2b-256 checksum
How to use checksums
9abc0af77f04a238ef8d7351006c5fa1754a4b60b244c0a602403167cb49e022
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

This release

0.1.1 This release

2 release files

0.1.0

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