Python SDK for Quote0 e-ink device API
Project description
Quote0 Client Python SDK
用于通过 Dot. App API 控制 Quote0 电子墨水设备的 Python SDK。
功能特性
- 完整覆盖 Quote0 的全部 6 个 API 端点
- 基于 Pydantic v2 模型的类型安全
- 全面的错误处理
- 支持文本和图像内容
- 设备任务管理
- 易于使用的同步客户端
安装
# 使用 pip
pip install quote0-client
# 使用 uv
uv add quote0-client
快速开始
from quote0_client.client import Quote0Client
from quote0_client.models import TextContentRequest
# 初始化客户端
client = Quote0Client(api_key="your-api-key-from-dot-app")
# 获取设备列表
devices = client.get_devices()
print(f"找到 {len(devices)} 个设备")
# 发送文本内容
text_req = TextContentRequest(
title="你好",
message="Quote0 设备!"
)
response = client.send_text(devices[0].id, text_req)
if response.success:
print("文本发送成功!")
API 参考
| 方法 | 说明 | 参数 | 返回类型 |
|---|---|---|---|
get_devices() |
获取所有设备列表 | 无 | List[Device] |
get_device_status(device_id) |
获取设备状态 | device_id: 设备序列号 |
DeviceStatus |
switch_to_next(device_id) |
切换到下一个内容 | device_id: 设备序列号 |
APIResponse |
list_tasks(device_id, task_type) |
列出设备任务 | device_id: 设备序列号, task_type: 任务类型 |
List[Task] |
send_text(device_id, content) |
发送文本内容 | device_id: 设备序列号, content: TextContentRequest |
APIResponse |
send_image(device_id, content) |
发送图像内容 | device_id: 设备序列号, content: ImageContentRequest |
APIResponse |
数据模型
Device: 设备信息(series, model, edition, id)DeviceStatus: 设备状态(电池、WiFi、渲染信息等)TextContentRequest: 文本内容(title, message, signature)ImageContentRequest: 图像内容(base64编码图片, border, ditherType)APIResponse: 通用响应包装器(success, message, data)
错误处理
所有 SDK 方法都可能抛出以下异常:
Quote0Error- 基础异常类AuthenticationError- API 密钥无效或已过期(HTTP 401)NotFoundError- 设备未找到(HTTP 404)PermissionError- 权限不足(HTTP 403)ValidationError- 参数无效(HTTP 400)RateLimitError- 超过速率限制(10 次/秒)
from quote0_client.exceptions import AuthenticationError, NotFoundError
try:
devices = client.get_devices()
except AuthenticationError:
print("API 密钥无效!")
except NotFoundError:
print("设备未找到!")
except Quote0Error as e:
print(f"错误: {e}")
配置
获取 API 密钥
- 打开 Dot. App
- 进入"更多"标签页
- 点击"API Key"
- 创建并保存密钥
获取设备序列号
- 打开 Dot. App
- 进入设备详情
- 复制序列号(如 "ABCD1234ABCD")
自定义 API 端点
client = Quote0Client(
api_key="your-api-key",
base_url="https://your-custom-endpoint.com"
)
使用示例
上下文管理器模式
from quote0_client.client import Quote0Client
with Quote0Client(api_key="your-api-key") as client:
devices = client.get_devices()
print(f"找到 {len(devices)} 个设备")
# 退出上下文时客户端会自动关闭
发送图像
import base64
with open("image.png", "rb") as f:
image_data = base64.b64encode(f.read()).decode()
image_req = ImageContentRequest(
image=image_data,
border=0,
refreshNow=True
)
response = client.send_image("ABCD1234ABCD", image_req)
故障排除
- ModuleNotFoundError - 使用
pip install -e .安装包 - AuthenticationError - 检查 API 密钥是否有效且未过期
- NotFoundError - 确认设备 ID 正确且已在 Dot. App 中注册
- RateLimitError - API 限制为 10 次/秒,添加退避机制
- ValidationError - 检查设备 ID 格式和 base64 编码
启用调试日志:
import logging
logging.basicConfig(level=logging.DEBUG)
许可证
MIT License
贡献
欢迎贡献!请提交 pull request 或 issue。
相关链接
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
quote0_client-0.1.0.tar.gz
(62.2 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 quote0_client-0.1.0.tar.gz.
File metadata
- Download URL: quote0_client-0.1.0.tar.gz
- Upload date:
- Size: 62.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1256010982c8644bb949ab892291b9cde6d62d291daf0c1313024640027bf2e1
|
|
| MD5 |
14a44b62b7d17427e7a9e68ea92d945e
|
|
| BLAKE2b-256 |
ea5818ed4a43570b550aa5fb0d82768c4a33a5b3a3a5de2434472f9f20e66cbf
|
File details
Details for the file quote0_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: quote0_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7918b3e48ac7b9e4856fea3777c3675db2a68bfac6cd30e9e54d476524d4fc29
|
|
| MD5 |
fe7ea2bc7dcddceb5b4e7e67c195892a
|
|
| BLAKE2b-256 |
799e9b77aa67d5a68fb74f86289c58e673985998b4dc8b970388e7e4838ad4f9
|