一个简单可扩展的异步消息通知库
Project description
一个简单可扩展的异步消息通知库
安装
pip install use-notify
使用
from use_notify import useNotify, useNotifyChannel
notify = useNotify()
notify.add(
# 添加多个通知渠道
useNotifyChannel.Bark({"token": "xxxxxx"}),
useNotifyChannel.Ding({
"token": "xxxxx",
"at_all": True
})
)
notify.publish(title="消息标题", content="消息正文")
装饰器使用(推荐)
使用 @notify 装饰器可以自动为函数执行发送通知:
from use_notify import useNotify, useNotifyChannel, notify, set_default_notify_instance
# 创建并设置全局默认通知实例
default_notify = useNotify()
default_notify.add(
useNotifyChannel.Bark({"token": "your_bark_token"}),
useNotifyChannel.Ding({"token": "your_ding_token"})
)
set_default_notify_instance(default_notify)
# 现在可以直接使用装饰器,无需传递 notify_instance
@notify()
def data_processing():
# 数据处理逻辑
return "数据处理完成"
@notify(title="重要任务")
def important_task():
# 重要任务逻辑
return "重要任务完成"
@notify(notify_on_error=True, notify_on_success=False)
def risky_operation():
# 只在出错时通知
if some_condition:
raise Exception("操作失败")
return "操作成功"
# 异步函数支持
@notify()
async def async_task():
await some_async_operation()
return "异步任务完成"
装饰器特性:
- ✅ 自动发送成功/失败通知
- ✅ 支持同步和异步函数
- ✅ 可配置通知条件和自定义消息
- ✅ 全局默认实例,简化使用
- ✅ 执行上下文信息收集
📖 详细文档: 装饰器完整使用指南
支持的消息通知渠道列表
- Wechat(企微)
- Ding(钉钉)
- Bark
- Chanify
- Pushdeer
- Pushover
- FeiShu(飞书)
- Ntfy
自己开发消息通知
from use_notify import useNotifyChannel
class Custom(useNotifyChannel.BaseChannel):
"""自定义消息通知"""
def send(self, *args, **kwargs):
...
async def send_async(self, *args, **kwargs):
...
更多示例
文档
- 装饰器完整使用指南 - 详细的装饰器功能说明和最佳实践
特性
- 🚀 简单易用: 几行代码即可集成多种通知渠道
- 🔄 异步支持: 完整的异步/同步双模式支持
- 🎯 装饰器模式: 使用
@notify装饰器自动化通知 - 🔧 高度可扩展: 轻松添加自定义通知渠道
- 📱 多渠道支持: 支持微信、钉钉、Bark、邮件等多种通知方式
- ⚙️ 灵活配置: 支持条件通知、自定义模板、全局默认实例等高级功能
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
use_notify-0.3.45.tar.gz
(13.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file use_notify-0.3.45.tar.gz.
File metadata
- Download URL: use_notify-0.3.45.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.18 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
739e56f9186f77412a96ad66bf28140e9b057ff5acbf1c8776f7bca4737dcc39
|
|
| MD5 |
09c8c6ec2d36128e5601b926c1d07147
|
|
| BLAKE2b-256 |
8c31856849b3910ed2792e00e2fd860046c4583d252859425b7c7de9a10c56c9
|
File details
Details for the file use_notify-0.3.45-py3-none-any.whl.
File metadata
- Download URL: use_notify-0.3.45-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.18 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bb44929434429f7aa92f5dd1448129fd93d6a499441aa909f421e4f8f403be2
|
|
| MD5 |
a02a8bbf3788c80ac094f3eabe2f23f0
|
|
| BLAKE2b-256 |
b521f98cd3afa1635b353aced306bed4735e50f29f2d42dc426f20c2e327e97d
|