Skip to main content

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

许可证

Apache-2.0

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

gravity_material_upload-1.0.3.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gravity_material_upload-1.0.3-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file gravity_material_upload-1.0.3.tar.gz.

File metadata

  • Download URL: gravity_material_upload-1.0.3.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

Hashes for gravity_material_upload-1.0.3.tar.gz
Algorithm Hash digest
SHA256 7ef21a7f395cd33b8387345618be693806b73416e0df7aa7c0eabbc7acd872fe
MD5 10f7fa6ad76cd9eb9abe93656a7b9255
BLAKE2b-256 d493857bd30435a1f29a35adb8f886d350c6a74cd8418664582cc9c7c6788574

See more details on using hashes here.

File details

Details for the file gravity_material_upload-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gravity_material_upload-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f059f4d2908374dbf5a1e281bf02f7925f577a76a53882b02a216f88f20d48c1
MD5 5fe5990007d9fa7a1ed0eb43306e8461
BLAKE2b-256 6c5abbfb7e01c58a4ad273a7a20cb5b8e91d8d011596c8007140a265d1de49c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page