Skip to main content

未提供项目描述

项目描述

S3路径

最新版本 S3Path CI

S3Path 使用 boto3 S3 资源作为驱动程序为 AWS S3 服务提供 Python 方便的文件系统/路径类接口。

与 pathlib 类似,但适用于 S3 存储桶

AWS S3 是最流行的云存储解决方案之一。它是对象存储,旨在从任何地方存储和检索各种数量的数据。

目前,Python 开发人员使用 Boto3 作为默认 API 从 S3 连接/放置/获取/列出/删除文件。

S3Path 融合了 Boto3 的易用性和 pathlib api 的熟悉度。

安装:

来自 PyPI:

$ pip install s3path

从康达:

$ conda install -c conda-forge s3path

基本用途:

以下示例假定如下指定的 s3 存储桶设置:

$ aws s3 ls s3://pypi-proxy/

2018-04-24 22:59:59        186 requests/index.html
2018-04-24 22:59:57     485015 requests/requests-2.9.1.tar.gz
2018-04-24 22:35:01      89112 boto3/boto3-1.4.1.tar.gz
2018-04-24 22:35:02        180 boto3/index.html
2018-04-24 22:35:19    3308919 botocore/botocore-1.4.93.tar.gz
2018-04-24 22:35:36        188 botocore/index.html

导入主类:

>>> from s3path import S3Path

列出“子目录” - s3 键可以像文件系统一样在 s3path 中使用/进行拆分,我们:

>>> bucket_path = S3Path('/pypi-proxy/')
>>> [path for path in bucket_path.iterdir() if path.is_dir()]
[S3Path('/pypi-proxy/requests/'),
 S3Path('/pypi-proxy/boto3/'),
 S3Path('/pypi-proxy/botocore/')]

在这个“目录”树中列出 html 源文件:

>>> bucket_path = S3Path('/pypi-proxy/')
>>> list(bucket_path.glob('**/*.html'))
[S3Path('/pypi-proxy/requests/index.html'),
 S3Path('/pypi-proxy/boto3/index.html'),
 S3Path('/pypi-proxy/botocore/index.html')]

在“目录”树中导航:

>>> bucket_path = S3Path('/pypi-proxy/')
>>> boto3_package_path = bucket_path / 'boto3' / 'boto3-1.4.1.tar.gz'
>>> boto3_package_path
S3Path('/pypi-proxy/boto3/boto3-1.4.1.tar.gz')

查询路径属性:

>>> boto3_package_path = S3Path('/pypi-proxy/boto3/boto3-1.4.1.tar.gz')
>>> boto3_package_path.exists()
True
>>> boto3_package_path.is_dir()
False
>>> boto3_package_path.is_file()
True

打开“文件”(s3 键):

>>> botocore_index_path = S3Path('/pypi-proxy/botocore/index.html')
>>> with botocore_index_path.open() as f:
>>>     print(f.read())
"""
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Package Index</title>
</head>
<body>
    <a href="botocore-1.4.93.tar.gz">botocore-1.4.93.tar.gz</a><br>
</body>
</html>
"""

或简单阅读:

>>> botocore_index_path = S3Path('/pypi-proxy/botocore/index.html')
>>> botocore_index_path.read_text()
"""
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Package Index</title>
</head>
<body>
    <a href="botocore-1.4.93.tar.gz">botocore-1.4.93.tar.gz</a><br>
</body>
</html>
"""

要求:

  • 蟒蛇> = 3.4

  • 博托3

  • 智能开

更多文档:

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

s3path-0.3.4.tar.gz (14.5 kB 查看哈希

已上传 source

内置分布

s3path-0.3.4-py3-none-any.whl (14.4 kB 查看哈希

已上传 py3