Skip to main content

Gravity Material Upload

Python SDK,用于批量上传图片和视频素材。

文档:https://help.gravity-engine.com/docs/material-upload

功能特性

  • 🔍 智能文件扫描 — 支持扫描目录、指定文件、通配符匹配,自动过滤有效的图片/视频文件
  • 📤 分片上传 — 基于 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",
    },
    file_renames={                            # 可选:文件重命名映射  key可以是全名,也可是不含后缀的纯名,value必须是无后缀纯名,全名时仅对应文件更改名,纯名时同名文件都会匹配,比如 key为test时,test.png和test.mp4会重命名为 test_rename.png  , test_rename.mp4 
        "video1.mp4": "video_rename",
    },
)

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 必填 自定义上传配置参数,合并到接口根层级
file_renames dict None 文件重命名映射 key可以是全名,也可是不含后缀的纯名,value必须是无后缀纯名,全名时仅对应文件更改名,纯名时同名文件都会匹配,比如 key为test时,test.png和test.mp4会重命名为 test_rename.png , test_rename.mp4

环境要求

  • Python >= 3.7

许可证

Apache-2.0

Metadata

Release files for gravity-material-upload 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gravity-material-upload 1.0.4
File Size Uploaded Provenance
gravity_material_upload-1.0.4.tar.gz 19.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gravity-material-upload 1.0.4
File Interpreter ABI Platform
gravity_material_upload-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 39.5 kB

Release files / gravity_material_upload-1.0.4.tar.gz

Download URL gravity_material_upload-1.0.4.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e95c99dfb434063ade70365b989d14751a974e1e8edb439deceb936d6183cc0a
BLAKE2b-256 checksum
How to use checksums
5d629cfbf33c2f3d5bd2ea1a1c1e5c405ddbd344be2d3978ec834de3c05524c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gravity_material_upload-1.0.4-py3-none-any.whl

Download URL gravity_material_upload-1.0.4-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77dd862901a664cecdc5860220a986ca1989021b23f98c661218fd326804d718
BLAKE2b-256 checksum
How to use checksums
e0c78a07ab1e73bb24064dea42e7b9a174a1865ed11b6608de31c7e51ee35ae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for gravity-material-upload 1.0.4

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