Skip to main content

py-tjbrhk-toolkit

License: MIT

中文 | English

文档:

项目介绍

py-tjbrhk-toolkit 是天津博瑞皓科博瑞云音箱 API 的 Python 客户端库,提供同步和异步客户端,用于向云音箱发送通知语音播报请求。

当前实现 notify.php 通知接口。客户端使用 httpx 发送表单 POST 请求,并使用 Pydantic 模型解析接口响应。

软件架构

py_tjbrhk_toolkit/
├── pyproject.toml
├── README.md
├── LICENSE
├── src/
│   └── py_tjbrhk_toolkit/
│       ├── __init__.py
│       ├── py.typed
│       └── speaker/
│           ├── __init__.py
│           ├── client.py       # 同步与异步通知客户端
│           ├── exception.py    # 配置错误与网络错误
│           └── response.py     # 通知接口响应模型
└── tests/
    └── speaker/
        ├── .env.example
        ├── conftest.py
        └── test_notify.py

主要类与方法

类 说明
Client 同步云音箱客户端,提供 notify() 方法
AsyncClient 异步云音箱客户端,提供 notify() 方法
NotifyResponse 通知接口响应模型,提供 ok 属性判断业务结果
ConfigError 客户端配置无效时抛出
NetworkError HTTP 请求失败时抛出

支持的接口

接口 客户端方法 HTTP 请求 说明
notify.php Client.notify() 同步 POST 发送通知语音播报
notify.php AsyncClient.notify() 异步 POST 异步发送通知语音播报

通知消息最长为 128 个 UTF-8 字节。接口表单支持 id、token、version、message、seq、vol、speed 和 trace_no 字段。

安装方式

推荐使用 uv:

# 添加为项目依赖
uv add py-tjbrhk-toolkit

# 或使用 pip 安装
pip install py-tjbrhk-toolkit

从源码安装并配置测试环境:

uv sync --extra dev --extra test

使用说明

1. 同步发送通知

from py_tjbrhk_toolkit.speaker.client import Client

with Client(
    token="your_speaker_token",
    id="your_speaker_id",
) as client:
    response = client.notify(
        message="您好,欢迎光临",
        vol=80,
    )
    print(response.model_dump())
    print("发送成功:", response.ok)

2. 异步发送通知

import asyncio

from py_tjbrhk_toolkit.speaker.client import AsyncClient


async def main() -> None:
    async with AsyncClient(
        token="your_speaker_token",
        id="your_speaker_id",
    ) as client:
        response = await client.notify(
            message="收到一笔新的付款",
            vol=80,
        )
        print(response.model_dump())
        print("发送成功:", response.ok)


asyncio.run(main())

同步客户端可用 with 管理连接;异步客户端可用 async with 管理连接。也可以分别调用 Client.close() 和 AsyncClient.aclose() 手动关闭。

3. 通知参数

参数 类型 必填 说明
message str 是 播报内容,最长 128 个 UTF-8 字节
seq int | str 否 通讯去重顺序号
vol int | str 否 音量设置
speed int | str 否 语速设置
trace_no str 否 请求追踪字符串
id str 否 覆盖客户端配置的云音箱 ID
token str 否 覆盖客户端配置的 Token
version str 否 覆盖客户端配置的接口版本

消息中的数字默认按金额播报;如需按号码或编号播报,可按接口约定使用方括号,例如 "[123]"。音箱型号和接口版本对 speed 等参数的支持可能不同,请以官方接口文档为准。

测试

测试配置从 tests/speaker/.env 读取。先复制模板并填写有效的设备 ID 和 Token:

cp tests/speaker/.env.example tests/speaker/.env

在 .env 中设置:

BASE_URL=https://speaker.17laimai.cn
ID=your_speaker_id
TOKEN=your_speaker_token
VERSION=1
ALLOW_REAL_REQUESTS=true

运行同步和异步测试:

uv run --extra test pytest -v tests/speaker

**注意:**这些测试会向真实云音箱发送请求并触发语音播报。只有在 .env 中显式设置 ALLOW_REAL_REQUESTS=true 且配置有效凭据时才会运行;否则 pytest 会跳过测试。请勿在不适合播报的设备或环境中执行。

贡献指南

欢迎提交问题和贡献代码:

  1. Fork 本仓库
  2. 创建特性分支:git checkout -b feature/your-feature
  3. 提交修改:git commit -m "feat: add your feature"
  4. 推送分支并提交合并请求

提交前请运行 Ruff 检查,并确认测试符合预期。

作者信息

许可证

MIT License

Metadata

Release files for py-tjbrhk-toolkit 4.0.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 py-tjbrhk-toolkit 4.0.1
File Size Uploaded Provenance Actions
py_tjbrhk_toolkit-4.0.1.tar.gz 10.2 kB Without provenance Details for py_tjbrhk_toolkit-4.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-tjbrhk-toolkit 4.0.1
File Interpreter ABI Platform Actions
py_tjbrhk_toolkit-4.0.1-py3-none-any.whl Python 3 none any Details for py_tjbrhk_toolkit-4.0.1-py3-none-any.whl

Total release size: 17.9 kB

Release files / py_tjbrhk_toolkit-4.0.1.tar.gz

Download URL py_tjbrhk_toolkit-4.0.1.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e47e3fc0daf61ead12c969a1a8bebb59a31e748152b02c9880cb2616075b80db
BLAKE2b-256 checksum
How to use checksums
20db5111d8e68e04614b0cf3beec18cd8be21d5d868029166011bee9a9e003c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Release files / py_tjbrhk_toolkit-4.0.1-py3-none-any.whl

Download URL py_tjbrhk_toolkit-4.0.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab880d470abe63aa530c18ae2152102e593bf5d6674ca13da97bbb16bc2bb03f
BLAKE2b-256 checksum
How to use checksums
19a4cd97b448e2f3ecee7fefca4ad3b3835d1297d8f47515824b4d7a422ae14d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Security for py-tjbrhk-toolkit 4.0.1

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