BDD 平台文件服务客户端
Project description
BDD File Client
BDD 平台文件服务客户端
安装方式
$ pip install bdd-file-client
快速开始
配置 BddFileClient
from bdd_file import BddFileClient, UploadMode
client = BddFileClient(
profile="dev", # 可选 dev、beta、prod,默认为 dev
default_user_id="114514", # 默认的用户 ID,可在调用时覆盖
)
profile用于指定后端环境,会自动映射到对应的服务地址default_user_id、default_biz、default_mode均为可选,若在调用时未显式提供则使用此处的默认值
上传文件
# 1. 通过文件路径上传(简单上传)
result = client.upload(
path="example.png",
mode=UploadMode.SIMPLE, # 默认 auto,可选 simple、chunked
biz="chat",
biz_params={"chat_id": "191810"},
)
print("上传成功,file_id =", result.file_id)
# 2. 通过文件流上传
with open("example.png", "rb") as f:
result = client.upload(
stream=f,
filename="example.png", # 当使用 stream 时,必须显式指定文件名
biz="chat",
biz_params={"chat_id": "191810"},
)
注意
path与stream只能二选一- 分片上传(UploadMode.CHUNKED)暂未实现,设置后会抛出
BddFileError
下载文件
# 保存到本地文件
client.download(
file_id=result.file_id,
path="downloaded.png",
)
# 或写入到自定义流
from io import BytesIO
buffer = BytesIO()
client.download(file_id=result.file_id, stream=buffer)
print(buffer.getvalue())
错误处理
所有业务及网络错误都会抛出 bdd_file.BddFileError,可按需捕获:
from bdd_file import BddFileClient, BddFileError
client = BddFileClient(default_user_id="114514")
try:
result = client.upload(path="not_exists.txt", biz="chat")
except BddFileError as e:
print("操作失败:", e)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bdd_file_client-0.1.2.tar.gz
(28.6 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 bdd_file_client-0.1.2.tar.gz.
File metadata
- Download URL: bdd_file_client-0.1.2.tar.gz
- Upload date:
- Size: 28.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e459aed402e201dc6c2c3ec6dce46e022723a4b4557459492e7471e66bf66f4
|
|
| MD5 |
9f12ea71dfca88fb4232cb647fe9bf13
|
|
| BLAKE2b-256 |
5abc326623b260fab79fad38dd476b22c617334d70336271f038e3ff799fe293
|
File details
Details for the file bdd_file_client-0.1.2-py3-none-any.whl.
File metadata
- Download URL: bdd_file_client-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6e524f7d31f4d05745ffe03f470cb2e33eb28b3c7c7c3e283281c395bc8fe37
|
|
| MD5 |
7fdb956a7fbf83976daf54e57f13a964
|
|
| BLAKE2b-256 |
4fabe9a3395989d7cfc516a451d81e14b487737983f376097ec0713d69568d94
|