Skip to main content

PyUploadX Python SDK

pyuploadx 是 PyUploadX 文件/目录上传服务的 Python 客户端 SDK,支持小文件 Proxy 上传、 大文件 Multipart 分片 + 断点续传、目录上传(Manifest + .uploadignore)与生命周期策略。 协议与状态机见 docs/docs_product-design.md §17/§12/§13;完整开发文档(方法参考/模型/异常/测试/发版)见 docs/docs_sdk-dev.md。

安装

pip install pyuploadx          # Python ≥ 3.11,第三方依赖仅 httpx

快速开始

from datetime import timedelta
from pyuploadx import UploadClient, FileLifecycle

client = UploadClient(
    base_url="http://localhost:8000",
    api_key="dev-key",
    state_dir="~/.pyuploadx/uploads",
)

result = client.upload_file(
    "./README.md",
    bucket="app-default",
    lifecycle=FileLifecycle.ttl(timedelta(days=30)),
)

job = client.upload_directory(
    "./album-assets",
    bucket="app-default",
    destination_prefix="artists/10001",
    conflict_policy="reject",
)

获取结果与状态

上传接口同步返回结果对象(FileInfo / DirectoryJobInfo),后续可通过查询接口随时获取服务端最新状态。

# 上传结果:文件元数据与状态(含临时预签名下载 URL,expires_in 秒;Local 后端为 None)
info = client.upload_file("./README.md", bucket="app-default")
print(info.id, info.status, info.size_bytes, info.etag)
print(info.download_url, info.expires_in)
url = client.get_download_url(info.id, expires_seconds=3600)    # 过期后重新获取

# 大文件 Multipart 会话:查询分片上传状态(status: initiated/uploading/completed)
session = client.create_upload(bucket="app-default", object_key="model.bin", total_size=1024, part_size=256)
probe = client.get_upload(session.id)
print(probe.status, probe.completed_file_id)

# 目录上传:任务统计与状态(completed/failed_files/uploaded_bytes)
job = client.upload_directory("./album-assets", bucket="app-default")
print(job.status, job.uploaded_files, job.failed_files, job.uploaded_bytes)

# 事后查询:文件最新状态、生命周期与下载
info = client.get_file(info.id)                 # FileInfo:status/expires_at/legal_hold/completed_at
lifecycle = client.get_lifecycle(info.id)       # 生效生命周期
client.update_lifecycle(info.id, {"mode": "ttl", "ttl_seconds": 3600})
client.download(info.id, "/tmp/README.md")      # URL 模式:预签名流式,Local 自动回退代理
client.download_from_url(url, "/tmp/README.md") # 直接下载 URL(预签名/永久链接)
client.delete(info.id)                          # 删除(幂等)

指定目录上传、返回 URL 与 URL 下载

import httpx

# 1) 指定目录上传:自动拼接 object_key = <directory>/<文件名>
info = client.upload_file(
    "./report.pdf",
    bucket="app-default",
    directory="reports/2026",          # => object_key: reports/2026/report.pdf
)
large = client.upload_large_file(
    "./model.bin",
    bucket="app-default",
    directory="models/backup",         # => object_key: models/backup/model.bin
)

# 2) 上传响应返回临时预签名下载 URL(expires_in 秒;Local 后端为 None)
print(info.download_url, info.expires_in)
url = client.get_download_url(info.id, expires_seconds=3600)   # 过期后重新获取

# 3) 使用 URL 下载(httpx 流式写盘,不占内存)
with httpx.stream("GET", url, follow_redirects=True) as resp:
    resp.raise_for_status()
    with open("/tmp/report.pdf", "wb") as f:
        for chunk in resp.iter_bytes():
            f.write(chunk)

发版

SDK 与服务端分开发布:SDK 包 pyuploadx 在本目录构建 (bash scripts/publish-pypi.sh),服务端包 pyuploadx-server 在仓库根构建 (bash scripts/publish-pypi-server.sh),详见 docs/docs_product-design.md §37。

Metadata

Release files for pyuploadx 0.6.0

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

Source distribution (sdist)

Source distribution for pyuploadx 0.6.0
File Size Uploaded
pyuploadx-0.6.0.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyuploadx 0.6.0
File Interpreter ABI Platform
pyuploadx-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.0 kB

Release files / pyuploadx-0.6.0.tar.gz

Download URL pyuploadx-0.6.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3d7c8c55ded7f21dd031a5b78944714dee50f67df5bb8831f406fe9a0df0b573
BLAKE2b-256 checksum
How to use checksums
ee6971b6c8462d4c05b2e69e5dbb1d126434b8608525805c7d5b47c8ee3031b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / pyuploadx-0.6.0-py3-none-any.whl

Download URL pyuploadx-0.6.0-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f1f36a47e1c70e1d1f615f3362f5513b84cccc2d415ef803655a848082def35
BLAKE2b-256 checksum
How to use checksums
c749a34ca13abeff491e0d658c7598d1c5554e326c4b3cef5ac4a17eab9857b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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