Skip to main content

A simple wrapper for cos

Project description

easy_cos

让数据流动变得简单!Make data flow!

pip install cos-python-sdk-v5

pip install easy_cos==0.4.2 --index-url https://pypi.tuna.tsinghua.edu.cn/simple
# pip install easy_cos==0.4.3 --index-url https://pypi.org/simple  #清华等其他镜像源可能同步慢

这个库的开发是包含了大部分常用的 cos 脚本操作,避免许多重复代码。以及让很多新入职的同事能够快速用起来我们的数据。、


快捷命令行指令

# 在 ~/.bashrc 中添加:
export COS_SECRET_ID="YOUR_COS_SECRET_ID"
export COS_SECRET_KEY="YOUR_COS_SECRET_KEY"
export COS_REGION="ap-guangzhou"
export COSCLI_PATH="YOUR COSCLI PATH"

# 之后则可以使用快捷命令行指令:
cos_list        bucket_name/prefix                                  # 列出 bucket_name/prefix 下的所有文件
cos_download    bucket_name/prefix/file.txt local/path/file.txt     # 下载 bucket_name/prefix/file.txt 到 local/path/file.txt
cos_download_r  bucket_name/dir local/path                          # 下载 bucket_name/prefix 到 local/path
cos_upload      local/path bucket_name/prefix/file.txt              # 上传 local/path 到 bucket_name/prefix/file.txt
cos_upload_r    local/dir bucket_name/prefix                        # 上传 local/path 到 bucket_name/prefix
cos_delete      bucket_name/prefix/file.txt                         # 删除 bucket_name/prefix/file.txt



Python API 示例

import os
COS_CONFIG = {
    'secret_id': f'{os.environ["COS_SECRET_ID"]}',
    'secret_key': f'{os.environ["COS_SECRET_KEY"]}',
    'region': f'{os.environ["COS_REGION"]}',
    'coscli_path': f'{os.environ["COSCLI_PATH"]}',
}

场景一(list all files under a cos dir):

from easy_cos import list_all_files_under_cos_dir

list_all_files_under_cos_dir(
    cos_dir="bucket_name/prefix",
    config=COS_CONFIG,
    verbose=True,
    return_path_only=True,
)

场景二(check if a cos path exists):

from easy_cos import check_cos_path_exist

check_cos_path_exist(
    cos_path="bucket_name/prefix/file.txt",
    config=COS_CONFIG,
)

场景三(delete a cos file):

from easy_cos import delete_cos_file

delete_cos_file(
    cos_path="bucket_name/prefix/file.txt",
    config=COS_CONFIG,
)

场景四(delete a cos dir):

from easy_cos import delete_cos_dir

delete_cos_dir(
    cos_dibucket_name/prefix",
    config=COS_CONFIG,
)

场景五(download a cos file):

from easy_cos import download_cos_file

download_cos_file(
    cos_path="bucket_name/prefix/file.txt",
    local_file_path="local/path/file.txt",
    config=COS_CONFIG,
)

场景六(download a cos dir):

from easy_cos import download_cos_dir

download_cos_dir(
    cos_dir="bucket_name/prefix",
    local_dir="local/path",
    config=COS_CONFIG,
)

场景七(save an image to cos):

from easy_cos import save_img2cos

save_img2cos(
    img=Image.open("image.jpg"),
    cos_save_path="bucket_name/prefix/image.jpg",
    config=COS_CONFIG,
)

场景八(upload a file to cos):

from easy_cos import upload_file2cos

upload_file2cos(
    local_file_path="local/path/file.txt",
    cos_save_path="bucket_name/prefix/file.txt",
    config=COS_CONFIG,
)

场景九(upload a dir to cos):

from easy_cos import upload_dir2cos

upload_dir2cos(
    local_upload_dir="local/path",
    cos_dir="bucket_name/prefix",
    config=COS_CONFIG,
)

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

easy_cos-0.4.4.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

easy_cos-0.4.4-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file easy_cos-0.4.4.tar.gz.

File metadata

  • Download URL: easy_cos-0.4.4.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for easy_cos-0.4.4.tar.gz
Algorithm Hash digest
SHA256 06eb6287ba3d8fdea22e2b0d24f154e0bf0526eef68bbc4b49b11507882451a5
MD5 893efa89b0653660570f5baf10363dff
BLAKE2b-256 ba9da4c3ac1354bac6abc44c7b70b733378f47d3e346b9d2616015a65cdabad7

See more details on using hashes here.

File details

Details for the file easy_cos-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: easy_cos-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for easy_cos-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2ae9601e0f225839032da5e5e01af6f61604bbacf3de7e50746c0a1c73f1d98a
MD5 09320d16bb4470f384a8e4b3cc816a10
BLAKE2b-256 745998b88969e0eada669f0cd49b0c7f948884d5b81a5e86f4c36d7bfa675367

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