Skip to main content

阿里云OSS命令行工具ossutil的Python包装器,提供更加友好的Python接口

Project description

fundrive-ossutil

阿里云OSS命令行工具ossutil的Python包装器,提供更加友好的Python接口。本项目将ossutil的安装和使用包装成一个Python包,当用户安装Python包的时候,会按照ossutil的安装流程,自动下载ossutil的安装包并安装。

功能特性

  • 🚀 简单易用的Python API
  • 📁 支持文件上传、下载、删除等基本操作
  • 📋 支持对象列表查询
  • 🔧 自动安装和配置ossutil命令行工具
  • 📝 完整的日志记录和错误处理
  • 🔒 支持多种认证方式
  • 🌐 兼容所有阿里云OSS区域

快速开始

安装

pip install fundrive-ossutil

🎉 自动安装特性: 当您执行 pip install fundrive-ossutil 时,安装程序会自动检测并安装 ossutil 命令行工具!

安装过程中您会看到类似以下的输出:

============================================================
fundrive-ossutil: 正在检查ossutil安装状态...
fundrive-ossutil: 开始自动安装ossutil命令行工具...
fundrive-ossutil: ✅ ossutil安装成功!
fundrive-ossutil: 🎉 您现在可以使用fundrive-ossutil包了
============================================================

如果自动安装失败,您也可以稍后手动安装:

from fundrives.ossutil import install_ossutil
install_ossutil()

基本配置

  1. 使用配置文件(推荐)

创建配置文件 ~/.ossutilconfig

[Credentials]
language=CH
endpoint=https://oss-cn-hangzhou.aliyuncs.com
accessKeyID=your_access_key_id
accessKeySecret=your_access_key_secret
  1. 使用环境变量
export OSS_ENDPOINT="https://oss-cn-hangzhou.aliyuncs.com"
export OSS_ACCESS_KEY_ID="your_access_key_id"
export OSS_ACCESS_KEY_SECRET="your_access_key_secret"

基本使用

from fundrives.ossutil import OSSUtil

# 初始化(使用配置文件)
oss = OSSUtil()

# 或者直接传入参数
oss = OSSUtil(
    endpoint="https://oss-cn-hangzhou.aliyuncs.com",
    access_key_id="your_access_key_id",
    access_key_secret="your_access_key_secret"
)

# 上传文件
success = oss.upload_file("./local_file.txt", "remote/path/file.txt", "my-bucket")
if success:
    print("上传成功")

# 下载文件
success = oss.download_file("remote/path/file.txt", "./downloaded_file.txt", "my-bucket")
if success:
    print("下载成功")

# 列出对象
objects = oss.list_objects(prefix="images/", bucket="my-bucket")
for obj in objects:
    print(obj)

# 删除对象
success = oss.delete_object("remote/path/file.txt", "my-bucket")
if success:
    print("删除成功")

使用说明

基本用法

文件操作

from fundrives.ossutil import OSSUtil

oss = OSSUtil()

# 上传单个文件
oss.upload_file("local.txt", "remote/file.txt", "bucket-name")

# 批量上传
files = [
    ("local1.txt", "remote/file1.txt"),
    ("local2.txt", "remote/file2.txt")
]
for local, remote in files:
    oss.upload_file(local, remote, "bucket-name")

# 下载文件
oss.download_file("remote/file.txt", "local_copy.txt", "bucket-name")

对象管理

# 列出所有对象
all_objects = oss.list_objects(bucket="bucket-name")

# 按前缀过滤
image_objects = oss.list_objects(prefix="images/", bucket="bucket-name")

# 删除对象
oss.delete_object("remote/unwanted_file.txt", "bucket-name")

高级功能

自动安装ossutil

from fundrives.ossutil import install_ossutil

# 自动检测并安装ossutil命令行工具
install_ossutil()

错误处理

from fundrives.ossutil import OSSUtil

oss = OSSUtil()

try:
    success = oss.upload_file("nonexistent.txt", "remote/file.txt", "bucket")
    if not success:
        print("上传失败,请检查日志")
except Exception as e:
    print(f"发生异常: {e}")

API文档

详细的API文档请参考:docs/API.md

开发指南

环境搭建

  1. 克隆项目
git clone https://github.com/farfarfun/fundrive-ossutil.git
cd fundrive-ossutil
  1. 安装开发依赖
pip install -e .
pip install pytest pytest-cov black flake8 mypy
  1. 运行测试
pytest --cov=src/fundrives/ossutil

代码规范

  • 遵循PEP8规范
  • 使用中文注释
  • 函数和类必须有文档字符串
  • 使用 funutil.getLogger 进行日志记录

详细的开发规范请参考:docs/DEVELOPMENT_GUIDE.md

测试

# 运行所有测试
pytest

# 生成覆盖率报告
pytest --cov=src/fundrives/ossutil --cov-report=html

# 运行特定测试
pytest tests/test_ossutil.py

变更日志

详细的版本变更记录请参考:docs/CHANGELOG.md

许可证

本项目采用 MIT 许可证。详情请参阅 LICENSE 文件。

贡献指南

我们欢迎所有形式的贡献!请遵循以下步骤:

  1. Fork 本项目
  2. 创建您的功能分支 (git checkout -b feature/AmazingFeature)
  3. 提交您的更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启一个 Pull Request

贡献要求

  • 代码必须通过所有测试
  • 新功能需要添加相应的测试
  • 遵循项目的代码规范
  • 更新相关文档

联系方式

相关项目

fundrive-ossutil 是 farfarfun 生态系统的一部分:

参考资料

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

fundrive_ossutil-0.1.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file fundrive_ossutil-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fundrive_ossutil-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78bfa3bc1190f020d21b4f9623faa1b39ca997d5a61513d614a726313b4f6a48
MD5 775b9673efc5e2d47b0a585a6e6d4afd
BLAKE2b-256 bca97f627b78c90eb721439c9ce4debe27702608c2621c4856643d5deb0d4e6b

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