Skip to main content

twist-academic

在实验或脚本结束时,通过飞书群机器人 webhook 发一条通知。无第三方运行时依赖。

安装

pip install twist-academic

配置

在项目根目录创建 .env(安装后 import twist_academic 会自动加载当前工作目录下的 .env):

TWIST_LARK_WEBHOOK=https://open.feishu.cn/open-apis/bot/v2/hook/your-token
# 若机器人在飞书后台开启了签名校验:
# TWIST_LARK_SECRET=your_sign_secret

用法

from twist_academic import notify

@notify
def train():
    ...

@notify(title="bert 微调")
def run_experiment():
    ...

# 直接发一条纯文本
notify("脚本已跑完,记得看结果。")

@notify 会在函数正常结束或抛异常后各发一条消息(含耗时、主机名;失败时带 traceback)。

集群 / 并行时避免刷屏

在 SLURM array、本地多进程等场景下,每个子任务若都 @notify,会产生大量重复消息。库会在以下情况自动不发送(notify / maybe_notify / @notify 均生效):

条件 说明
SLURM_ARRAY_TASK_ID 已设置 SLURM array 的每个 task 默认静音;可用 SBATCH --mail-type=END,FAIL 收邮件
NO_NOTIFY=1(或 true / yes / on) 任意环境显式关闭通知,便于子进程或调试
# 子进程 / 单次调试不发飞书
export NO_NOTIFY=1
python worker.py
from twist_academic import maybe_notify, notifications_suppressed

if not notifications_suppressed():
    notify("仅主进程汇总后发一条")

maybe_notify("与 notify(msg) 相同,受同一套静音规则约束")

测试

uv sync --dev
make test

# 向真实 webhook 发一条(需配置 TWIST_LARK_WEBHOOK)
pytest tests/test_notification.py -m integration

在 pyproject.toml 中已注册 integration marker。

开发

pre-commit run --all-files
uv build

Metadata

Release files for twist-academic 0.3.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 twist-academic 0.3.0
File Size Uploaded Provenance Actions
twist_academic-0.3.0.tar.gz 19.5 kB Without provenance Details for twist_academic-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twist-academic 0.3.0
File Interpreter ABI Platform Actions
twist_academic-0.3.0-py3-none-any.whl Python 3 none any Details for twist_academic-0.3.0-py3-none-any.whl

Total release size: 26.6 kB

Release files / twist_academic-0.3.0.tar.gz

Download URL twist_academic-0.3.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2300ee424489e6f9ae4829ef8264cec50704916d7e2f7f80bb84fe51c6d6ae6d
BLAKE2b-256 checksum
How to use checksums
53b47ac62a300845ab8e55ac94c718b23b4c92d020ba009d2234f5027c6af5d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","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 / twist_academic-0.3.0-py3-none-any.whl

Download URL twist_academic-0.3.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e768b0a3729c5707e28893ca5e6acb77b3ce547265ffe892a060c2bbb82021d
BLAKE2b-256 checksum
How to use checksums
04e0352fc44496acca299dfc997f30bb8d98a27f834d9e4e38ff29e8d4b832f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","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 twist-academic 0.3.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.

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