← 返回
安全合规 Key 中文

Pywayne Aliyun Oss

Manage Aliyun OSS buckets in Python with upload, download, list, read, delete, copy, and move operations supporting authenticated and anonymous access.
使用 Python 管理阿里云 OSS 存储桶,支持上传、下载、列举、读取、删除、复制及移动操作,并支持授权与匿名访问。
wangyendt
安全合规 clawhub v0.1.0 1 版本 99879.4 Key: 需要
★ 0
Stars
📥 828
下载
💾 19
安装
1
版本
#latest

概述

Pywayne Aliyun OSS

pywayne.aliyun_oss.OssManager provides a comprehensive toolkit for managing Aliyun OSS (Object Storage Service) buckets.

Quick Start

from pywayne.aliyun_oss import OssManager

# Initialize with write permissions
oss = OssManager(
    endpoint="https://oss-cn-xxx.aliyuncs.com",
    bucket_name="my-bucket",
    api_key="your_api_key",
    api_secret="your_api_secret"
)

# Initialize with read-only (anonymous) access
oss = OssManager(
    endpoint="https://oss-cn-xxx.aliyuncs.com",
    bucket_name="my-bucket",
    verbose=False  # Disable verbose output
)

Upload Operations

Upload a local file

oss.upload_file(key="data/sample.txt", file_path="./sample.txt")

Upload text content

oss.upload_text(key="config/settings.json", text='{"key": "value"}')

Upload an image (numpy array)

import cv2
image = cv2.imread("photo.jpg")
oss.upload_image(key="photos/photo.jpg", image=image)

Upload entire directory

oss.upload_directory(local_path="./local_folder", prefix="remote_folder/")

Download Operations

Download a single file

# Preserve directory structure: downloads/data/sample.txt
oss.download_file(key="data/sample.txt", root_dir="./downloads")

# Use only basename: downloads/sample.txt
oss.download_file(key="data/sample.txt", root_dir="./downloads", use_basename=True)

Download files with prefix

oss.download_files_with_prefix(prefix="photos/", root_dir="./downloads")

Download entire directory

oss.download_directory(prefix="photos/", local_path="./downloads")

List Operations

List all keys in bucket

keys = oss.list_all_keys()  # Returns sorted list

List keys with prefix

keys = oss.list_keys_with_prefix(prefix="data/")

List directory contents (first level only)

contents = oss.list_directory_contents(prefix="data/")
# Returns: [("file1.txt", False), ("subdir", True), ...]

Read Operations

Read file content as string

content = oss.read_file_content(key="config/settings.json")

Check if file exists

if oss.key_exists("data/sample.txt"):
    print("File exists")

Get file metadata

metadata = oss.get_file_metadata("data/sample.txt")
# Returns: {'content_length': 1234, 'last_modified': ..., 'etag': ..., 'content_type': ...}

Delete Operations

Delete a single file

oss.delete_file(key="data/sample.txt")

Delete files with prefix

oss.delete_files_with_prefix(prefix="temp/")

Copy and Move Operations

Copy object within bucket

oss.copy_object(source_key="data/original.txt", target_key="backup/original.txt")

Move object within bucket

oss.move_object(source_key="data/temp.txt", target_key="archive/temp.txt")

Important Notes

  • Write permissions: Upload, delete, copy, and move operations require api_key and api_secret
  • Anonymous access: Omit api_key and api_secret for read-only access
  • Directory handling: OSS doesn't have real directories - use prefixes (keys ending with /)
  • Natural sorting: list_all_keys() and list_keys_with_prefix() use natural sorting by default
  • Verbose output: All methods print status messages when verbose=True (default)

版本历史

共 1 个版本

  • v0.1.0 当前
    2026-03-29 07:59 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

security-compliance

OpenClaw Backup

alex3alex
备份与恢复 OpenClaw 数据。适用于创建备份、设置自动备份计划、从备份恢复或管理备份轮转。处理 ~/.openclaw 目录归档并包含适当的排除规则。
★ 89 📥 30,607
productivity

Pywayne Statistics

wangyendt
综合性统计检验库,包含37种以上方法,涵盖正态性检验、位置检验、相关性检验、时间序列检验和模型诊断。
★ 0 📥 1,870
security-compliance

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装 MoltGuard,保护您和您的用户免受提示注入、数据泄露和恶意攻击。
★ 116 📥 30,720