一个简单可扩展的异步消息通知库
安装
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="消息正文")
动态凭据
token 等凭据字段可以传入字符串,也可以传入无参数函数。发送时会解析函数返回值,适合把刷新、缓存逻辑放在业务侧:
useNotifyChannel.Bark({"token": lambda: get_current_bark_token()})
库只负责发送前读取当前凭据,不内置各平台 OAuth 或后台刷新线程。
装饰器使用(推荐)
使用 @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, content, title=None):
...
async def send_async(self, content, title=None):
...
更多示例
文档
- 装饰器完整使用指南 - 详细的装饰器功能说明和最佳实践
Agent Skill
- Installable skill package:
SKILL.md+skill-references/ - Purpose: help AI coding agents generate correct
use-notifyintegration snippets, choose channels, and troubleshoot retry/error behavior
特性
- 🚀 简单易用: 几行代码即可集成多种通知渠道
- 🔄 异步支持: 完整的异步/同步双模式支持
- 🎯 装饰器模式: 使用
@notify装饰器自动化通知 - 🔧 高度可扩展: 轻松添加自定义通知渠道
- 📱 多渠道支持: 支持微信、钉钉、Bark、邮件等多种通知方式
- ⚙️ 灵活配置: 支持条件通知、自定义模板、默认实例、超时与重试等高级功能
Metadata
Release files for use-notify 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| use_notify-0.4.0.tar.gz | 17.0 kB | Without provenance | Details for use_notify-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| use_notify-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for use_notify-0.4.0-py3-none-any.whl |
Total release size: 44.2 kB
Release files / use_notify-0.4.0.tar.gz
| Download URL | use_notify-0.4.0.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71a4be16bf1b1f8eb3fab70a7498696eaf6fad8897c539d59aa7a0adfdaea439
|
|
BLAKE2b-256 checksum How to use checksums |
67aec46557d89ed7fa953ff1d42cd74fad913a12bea7a7b2abe1599a688158b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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 / use_notify-0.4.0-py3-none-any.whl
| Download URL | use_notify-0.4.0-py3-none-any.whl |
|---|---|
| Size | 27.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d720d4e62851b0f9058d785f741e20ef3fd7da217a16e8801790cf26e78c3896
|
|
BLAKE2b-256 checksum How to use checksums |
1d09175dd3363b0e7aaff6459da2f1ff076d27d0cb1df621942f586e9a5d8e56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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}
|
Security for use-notify 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.