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"
export COS_YAML_PATH="YOUR COS YAML 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,
)
Metadata
Release files for easy-cos 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easy_cos-0.5.2.tar.gz | 21.1 kB | Without provenance | Details for easy_cos-0.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easy_cos-0.5.2-py3-none-any.whl | Python 3 | none | any | Details for easy_cos-0.5.2-py3-none-any.whl |
Total release size: 43.2 kB
Release files / easy_cos-0.5.2.tar.gz
| Download URL | easy_cos-0.5.2.tar.gz |
|---|---|
| Size | 21.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27798328d2eed7c7e0039800d67056743dbbed682645a8998734f38e8b22cd84
|
|
BLAKE2b-256 checksum How to use checksums |
5302dd6de0c03059bff7c1bec36b89678f801f9c5cc73dd95872c1e0368fe789
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / easy_cos-0.5.2-py3-none-any.whl
| Download URL | easy_cos-0.5.2-py3-none-any.whl |
|---|---|
| Size | 22.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d09b26929792548ba7f0a6d8d4bfa0167f39d7d9e78d17f34af0180a56041b4
|
|
BLAKE2b-256 checksum How to use checksums |
bc6023e27440f05d18b7ed3c2a1130cf555b4c6ebd6cab8f8a8893705c7e0c96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Security for easy-cos 0.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.