opener#
Smart open library integration.
- class s3pathlib.core.opener.OpenerAPIMixin[source]#
A mixin class that implements the file-object protocol.
- open(mode: str | None = 'r', version_id: str | None = Sentinel('NOTHING'), buffering: int | None = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None, closefd=True, opener=None, ignore_ext: bool = False, compression: str | None = None, multipart_upload: bool = True, metadata: Dict[str, str] | None = Sentinel('NOTHING'), tags: Dict[str, str] | None = Sentinel('NOTHING'), transport_params: dict | None = None, bsm: BotoSesManager | None = None)[source]#
Open S3Path as a file-liked object.
Example:
>>> import json >>> with S3Path("s3://bucket/data.json").open("w") as f: ... json.dump({"a": 1}, f) >>> with S3Path("s3://bucket/data.json").open("r") as f: ... data = json.load(f)
- Parameters:
mode – “r”, “w”, “rb”, “wb”.
version_id – optional version id you want to read from.
buffering – See smart_open.
encoding – See smart_open.
errors – See smart_open.
newline – See smart_open.
closefd – See smart_open.
opener – See smart_open.
ignore_ext – See smart_open.
compression – whether do you want to compress the content.
multipart_upload – do you want to use multi-parts upload, by default it is True.
metadata – also put the user defined metadata dictionary.
tags – also put the tag dictionary.
bsm – See bsm.
- Returns:
a file-like object that has
read()
andwrite()
method.
See smart_open for more info. Also see https://github.com/RaRe-Technologies/smart_open/blob/develop/howto.md#how-to-access-s3-anonymously for S3 related info.
New in version 1.0.1.
Changed in version 1.2.1: add
metadata
andtags
parametersChanged in version 2.0.1: add
version_id
parameter