关于amazon-web-services:Python-遍历中国区-s3-目录qbit

42次阅读

共计 534 个字符,预计需要花费 2 分钟才能阅读完成。

  • SDK 版本
Python 3.9
s3fs  2021.7.0
  • s3fs 文档:https://s3fs.readthedocs.io/
  • client_kwargs 参见:https://botocore.amazonaws.co…
  • 示例代码
# coding: utf-8
# author: qbit
# date: 2021-08-08
# summary: 遍历中国区 S3 目录

import s3fs

# 如果操作系统已配置命令行可拜访 s3
# 能够不必参数
fs = s3fs.S3FileSystem(
    key="aws_access_key_id",
    secret="aws_secret_access_key",
    client_kwargs={"region_name": "cn-northwest-1"}     # 中国宁夏区
)

print(fs.ls("qbit-cn-northwest-1"))
for parent, dirs, files in fs.walk("qbit-cn-northwest-1/data"):
    for file in files:
        pathfile = f"{parent}/{file}"
        print(f"{fs.size(pathfile)/1024:8.2f} KB {pathfile}")

本文出自 qbit snap

正文完
 0