Provides S3 path manipulation, similar to PurePath in pathlib
Project description
Description
Provides S3 path manipulation, similar to PurePath in pathlib. S3Path is only meant for path manipulation and does not implement any methods which interact with S3 itself. Avoiding S3 interaction means that a user can use their own boto3 session and are not forced to use the default one.
For S3Path implementations that do path manipulation and interaction, see s3path instead.
Installation
This is a pure python package, so it can be installed with pip install s3-path-wrangler
or any other dependency manager.
Usage
This library provides a single (meant to be) immutable class - S3Path
.
Class features:
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")
Development
This library uses the poetry package manager, which has to be installed before installing
other dependencies. Afterwards, run poetry install
to create a virtualenv and install all dependencies.
Black is used (and enforced via workflows) to format all code. Poetry will install it
automatically, but running it is up to the user. To format the entire project, run black .
.
To run tests, either activate the virtualenv via poetry shell
and run pytest ./tests
,
or simply run poetry run pytest ./tests
.
Contributing
This project uses the Apache 2.0 license and is maintained by the data science team @ Barbora. All contribution are welcome in the form of PRs or raised issues.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for s3_path_wrangler-0.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2070edc5db4d251af2d7b411ea1bdfc88fbc2c027d8cefc3dade4061e9d34f9b |
|
MD5 | 15c2960af729f29497ee26c75f75abe2 |
|
BLAKE2b-256 | 0bdc3a5a01b5045a666edd4e6ac5413be5431d55eeed6e9d93e2f740ca2c7e68 |