Files
37duAutomation/libs/dingtalk/dingtalk_sdk/__init__.py
T
puddy eeeaed1e14 feat(sdk): desktopauto 0.5.3 银行卡/证件 OCR 增强、dingtalk 1.1.0、aitable 0.1.3
- desktopauto:cardocr 引擎/流水线/校验与 ocr 调整,sdk.json/pyproject/版本三处一致
- dingtalk:AI 表格读写与错误封装扩充
- aitable:client/cli/自测与打包配置更新
2026-11-18 18:56:09 +08:00

116 lines
4.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""dingtalk_sdk · 钉钉能力 SDK(纯运行库,只能被调用,无独立执行入口)。
覆盖项目内既有全部钉钉能力,调用方后续逐步迁移;新代码可直接用本 SDK:
============================ ====================================================
能力 入口
============================ ====================================================
群机器人(Webhook)推送 :class:`robot.Robot` / ``robot.push``(加签、Markdown、
状态色、分批、块格式、prod/dev 多环境)
企业内部应用鉴权 :class:`auth.AccessToken`(v1 新版 / oapi 旧版两套 token)
媒体库上传(发图片) :func:`media.upload_media` / :func:`media.markdown_image`
单聊 / 群聊推送(dws CLI) :class:`dws.Dws` / ``dws.push``(文本/文件、@、限流、记录)
AI 表格(notable)读写 :class:`aitable.AiTable` 与值归一工具
月报 / 周报数据采集 :func:`report.collect` / ``python -m dingtalk_sdk.report``
============================ ====================================================
典型用法::
from dingtalk_sdk import Robot, dws, media
Robot(env="dev").send("同步完成", "共 12 条", status="success")
media_id = media.upload_media(r"D:\\out\\qr.png")
Robot(env="prod").send("登录码", media.markdown_image(media_id))
dws.push([{"msg_type": "text", "name": "张三", "user_id": "37036361",
"content": "已处理完成"}])
dws.push([{"group": "人资通知群", "content": "今日报表已生成"}])
契约(《SDK 挂载机制设计》§6.5):不读命令行参数、不 ``sys.exit``、不启后台线程、
不 ``print``(用 ``log`` 回调)、不持有全局可变业务状态、异常消息脱敏。
"""
from __future__ import annotations
__version__ = "0.1.3"
from . import aitable, auth, config, dws, errors, http, media, robot
from .aitable import (AiTable, attachment_items, coerce_for_fields, flatten, ms_to_str,
norm, parse_expires, resolve_base, safe_filename, sniff_kind,
to_base_id, to_ms)
from .auth import AccessToken, invalidate as invalidate_token, token
from .config import RobotAccount, Settings, get_settings, load_env_files
from .dws import Dws, push as push_dws
from .errors import (ApiError, AttachmentExpiredError, AuthError, CancelledError,
ConfigError, DingTalkError, DwsError, NetworkError)
from .media import markdown_image, upload_media
from .robot import (DingTalkRobot, Robot, build_sign, build_url, compose_batch_messages,
push as push_robot, split_by_chars)
def __getattr__(name: str):
"""``report`` 延迟导入:它是唯一带 ``python -m`` 入口的模块,
提前 import 会让 ``python -m dingtalk_sdk.report`` 触发 runpy 重复导入告警。"""
if name in ("report", "collect_report", "parse_period"):
import importlib
mod = importlib.import_module(".report", __name__)
if name == "report":
return mod
return getattr(mod, "collect" if name == "collect_report" else "parse_period")
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
__all__ = [
"AccessToken",
"AiTable",
"ApiError",
"AttachmentExpiredError",
"AuthError",
"CancelledError",
"ConfigError",
"DingTalkError",
"DingTalkRobot",
"Dws",
"DwsError",
"NetworkError",
"Robot",
"RobotAccount",
"Settings",
"aitable",
"attachment_items",
"auth",
"build_sign",
"build_url",
"coerce_for_fields",
"collect_report",
"compose_batch_messages",
"config",
"dws",
"errors",
"flatten",
"get_settings",
"http",
"invalidate_token",
"load_env_files",
"markdown_image",
"media",
"ms_to_str",
"norm",
"parse_expires",
"parse_period",
"push_dws",
"push_robot",
"report",
"resolve_base",
"robot",
"safe_filename",
"sniff_kind",
"split_by_chars",
"to_base_id",
"to_ms",
"token",
"upload_media",
"__version__",
]