Python SDK for material upload
Project description
Gravity Material Upload
Python SDK,用于批量上传图片和视频素材。
功能特性
- 🔍 智能文件扫描 — 支持扫描目录、指定文件、通配符匹配,自动过滤有效的图片/视频文件
- 📤 分片上传 — 基于 TOS 对象存储的分片上传,支持大文件传输
- 📊 进度显示 — 双层进度条实时展示文件级和字节级上传进度
- 🖼️ 自动解析 — 自动获取图片/视频的宽高、时长、MD5 等元信息
支持的文件格式
| 类型 | 后缀 |
|---|---|
| 图片 | .png .jpg .jpeg .gif |
| 视频 | .mp4 .3gp .avi .mov |
快速开始
1. 安装依赖
pip install gravity-material-upload
2. 使用示例
from gravity_material_upload import MaterialClient
# 1. 创建客户端
client = MaterialClient(
# app_key: 请在引力后台-设置-引力开发者中查看
# URL: https://web.gravity-engine.com/#/manage/develop
app_key="your_app_key",
)
# 2. 一键上传素材(扫描 + 上传)
client.upload_material(
source_paths=["./video1.mp4", "./image1.png"], # 目标路径,支持目录、文件列表、通配符
recursive=True, # 是否递归搜索子目录,在source_paths传入目录时生效
allowed_extensions=[".png", ".mp4"], # 可选:自定义文件后缀白名单
max_workers=5, # 可选:最大并发上传数
upload_config={ # 必填:自定义上传配置参数
"album_id": 123,
"remark": "your_remark",
},
)
MaterialClient 参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
app_key |
str |
必填。请在 引力后台-设置-引力开发者 中查看 |
upload_material() 参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
source_paths |
str | List[str] |
"." |
目标路径。用法示例: 1. ["./file1.mp4", "./file2.png"]: 仅上传这两个文件2. "./": 上传当前目录下所有匹配的文件3. "./data/*.mp4": 使用通配符匹配文件 |
recursive |
bool |
True |
是否递归搜索子目录 |
allowed_extensions |
Tuple[str, ...] |
None |
自定义文件后缀白名单,仅保留在默认支持列表中的后缀 |
max_workers |
int |
5 |
最大并发上传线程数 |
upload_config |
Object |
必填 | 自定义上传配置参数,合并到接口根层级 |
环境要求
- Python >= 3.7
许可证
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
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 gravity_material_upload-1.0.2.tar.gz.
File metadata
- Download URL: gravity_material_upload-1.0.2.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
076bdbb903ed6d714d59fac479c8ab37a52a58fc89c9781fc4c4b16d56737761
|
|
| MD5 |
4a2d2b06fe0306de48dcc22a0e3fb498
|
|
| BLAKE2b-256 |
d88eab9de45f04a02c9c964e36f397162c0d9bae5a7d05c00bc1649d52507a5d
|
File details
Details for the file gravity_material_upload-1.0.2-py3-none-any.whl.
File metadata
- Download URL: gravity_material_upload-1.0.2-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba60032d4fb005c4390cafea9f13bf689c9f5ec8ff86ef99349dc07c97550153
|
|
| MD5 |
f156d2644ce87b8d8cfa83b66ea12975
|
|
| BLAKE2b-256 |
d1ba2f8330080d2875084eaf70ff416e8c14dfaa6a33b5ac296ba3a0aec89091
|