这是python实现,用于与s3交互,语法更为丰富

libs3的Python项目详细描述


伦敦银行3

这个repo的目的是为python开发人员提供一个易于使用的s3接口,核心python库如os、shutil易于使用,对任何python程序员来说都更加熟悉。在

repo的目的是模拟这个功能,这样您的代码就可以像在linux或windows文件系统中一样与s3交互,只需修改一行或两行

安装

pip install libs3

文件

已经公开了一个功能列表,这些功能目前正在运行,稍后将添加更多功能(欢迎贡献)

操作系统

FunctionAvailaibleComments
^{}yesAs 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
^{}nowill be added in later releases
^{}nowill be added in later releases
^{}nowill be added in later releases
^{}nowill be added in later releases
^{}nowill be added in later releases
^{}nowill be added in later releases
^{}nowill be added in later releases

在操作系统路径

^{tb2}$

舒蒂尔

FunctionAvailaibleComments
^{}yescopy file(local/s3) to file(local/s3)
^{}yescopy file(local/s3) to file/folder(local/s3)
^{}nowill be added in later releases
^{}yes
^{}yescopy file(local/s3) to file/folder(local/s3)
^{}nowill 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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java既然Lucene 4.1中不存在TermEnum,如何从IndexReader中获取字段?   java在LinkedHashSet上的迭代比在ArrayList上的迭代要快   java无法在Android Studio中获得所有@override函数,如onStart、onResume   java的DateTimeFormatter比SimpleDateFormat更严格吗?以毫秒为单位分析日期   JavaSpring*servlet。Websphere服务器启动时未加载xml   java Fancytree selenium单击事件   java日期格式不一样   java无法在Android Studio上运行我的MQTT应用程序   c#计算两个集合的F检验   java JDialog不会显示在“设计”选项卡中   java如何在每个服务生页面上重新加载页面   java如何初始化包含一些对象的数组?   使用Datanucleus的java Amazon S3数据存储   Python的map函数是否有Java等价物?