Skip to main content

提供 S3 路径操作,类似于 pathlib 中的 PurePath

项目描述

格式化程序 构建状态 编解码器 PyPI 版本 PyPI - Python 版本

描述

提供 S3 路径操作,类似于 pathlib 中的 PurePath。S3Path用于路径操作,不实现任何与 S3 本身交互的方法。避免 S3 交互意味着用户可以使用自己的 boto3 会话,而不必强制使用默认会话。

对于执行路径操作交互的 S3Path 实现,请参阅 s3path

安装

这是一个纯 python 包,所以它可以与pip install s3-path-wrangler 任何其他依赖管理器一起安装。

用法

这个库提供了一个(意味着)不可变的类 - S3Path. 班级特色:

from s3_path_wrangler.paths import S3Path

# various options for creating path objects
full_path = S3Path("s3://your-bucket/some/path/file.json")
from_list = S3Path.from_parts(["your-bucket", "some", "path", "file.json"], is_absolute=True)
relative = S3Path("some/path/")
relative_from_list = S3Path.from_parts(["some", "path"]) # or is_absolute=False

# convenient attributes
assert full_path.parts == ["your-bucket", "some", "path", "file.json"]
assert full_path.is_absolute == True
assert full_path.bucket == "your-bucket"
assert full_path.key == "some/path/file.json"
assert full_path.name == "file.json"
assert full_path.parent == S3Path("s3://your-bucket/some/path")

# paths are comparable to strings (directories will not have trailing slashes)
assert S3Path.from_parts(["some", "path"]) == "some/path"

# paths can be manipulated via '/'
assert relative / "file.json" == S3Path("some/path/file.json")

发展

该库使用诗歌包管理器,必须在安装其他依赖项之前安装它。之后,运行poetry install以创建一个 virtualenv 并安装所有依赖项。

黑色用于(并通过工作流强制执行)格式化所有代码。Poetry 会自动安装它,但运行它取决于用户。要格式化整个项目,请运行black ..

要运行测试,要么通过激活 virtualenvpoetry shell并运行pytest ./tests,要么简单地运行poetry run pytest ./tests

贡献

该项目使用 Apache 2.0 许可证,由数据科学团队 @ Barbora 维护。欢迎以 PR 或提出问题的形式提供所有贡献。

项目详情


下载文件

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

源分布

s3-path-wrangler-0.5.0.tar.gz (9.0 kB 查看哈希

已上传 source

内置分布

s3_path_wrangler-0.5.0-py3-none-any.whl (9.3 kB 查看哈希

已上传 py3