这是python实现,用于与s3交互,语法更为丰富
libs3的Python项目详细描述
伦敦银行3
这个repo的目的是为python开发人员提供一个易于使用的s3接口,核心python库如os、shutil易于使用,对任何python程序员来说都更加熟悉。在
repo的目的是模拟这个功能,这样您的代码就可以像在linux或windows文件系统中一样与s3交互,只需修改一行或两行
安装
pip install libs3
文件
已经公开了一个功能列表,这些功能目前正在运行,稍后将添加更多功能(欢迎贡献)
操作系统
Function | Availaible | Comments |
---|---|---|
^{ | yes | As s3 has no notion of directories, in order to list directories along with files we have to traverse entire bucket and filter the results. For more quick results you can use os.listdir(x, filesonly=True) is much fast but will only returns files and not directory |
^{ | yes | |
^{ | yes | |
^{ | yes | |
^{ | no | will be added in later releases |
^{ | no | will be added in later releases |
^{ | no | will be added in later releases |
^{ | no | will be added in later releases |
^{ | no | will be added in later releases |
^{ | no | will be added in later releases |
^{ | no | will be added in later releases |
在操作系统路径
^{tb2}$舒蒂尔
Function | Availaible | Comments |
---|---|---|
^{ | yes | copy file(local/s3) to file(local/s3) |
^{ | yes | copy file(local/s3) to file/folder(local/s3) |
^{ | no | will be added in later releases |
^{ | yes | |
^{ | yes | copy file(local/s3) to file/folder(local/s3) |
^{ | no | will be added in later releases |
示例
操作系统-导入模块并使用s3凭据进行授权
^{pr2}$在授权访问接口之后,就像通常访问文件系统一样
print(os.listdir("/dir_1/dir_1"))
print(os.listdir("/dir_1/dir_1", filesonly=True)) # Much quicker
print(os.path.exists('/dir_1/file_2'))
print(os.path.isfile('/dir_1/file_2'))
print(os.path.isdir('/dir_1/file_2'))
print(os.path.basename('/dir_1/file_2'))
print(os.path.dirname('/dir_1/file_2'))
os.remove('/dir_2/file_ks')
shutil-导入模块并使用s3凭证进行授权
from libs3 import shutil
shutil.authorize(bucket, aws_access_key_id, aws_secret_access_key)
在授权访问接口之后,就像通常访问文件系统一样
# Copying file
shutil.copy("/dir_2/file_1", "/dir_2/file_1_cp") # Copy within s3
shutil.copy("/dir_2/file_1", "localfile", download=True) # Copy from s3 to local
shutil.copy("localfile", "/dir_2/filename", upload=True) # Copy from local to s3
shutil.copyfile("/dir_2/file_1", "/dir_2/file_ks") # Copy within s3
# Removing
shutil.rmtree('/dir_2/cold')
# Moving
shutil.move('/dir_2/file_1_cp', '/dir_2/file_1_moved')
shutil.move('file_1_cp', '/dir_2/file_1_moved', upload=True) # Moving file from local to s3
- 项目
标签: