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 = OPT, 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 = OPT, tags: Dict[str, str] | None = OPT, acl: str = OPT, cache_control: str = OPT, content_disposition: str = OPT, content_encoding: str = OPT, content_language: str = OPT, content_length: int = OPT, content_md5: str = OPT, content_type: str = OPT, checksum_algorithm: str = OPT, checksum_crc32: str = OPT, checksum_crc32c: str = OPT, checksum_sha1: str = OPT, checksum_sha256: str = OPT, expires_datetime: datetime = OPT, grant_full_control: str = OPT, grant_read: str = OPT, grant_read_acp: str = OPT, grant_write_acp: str = OPT, server_side_encryption: str = OPT, storage_class: str = OPT, website_redirect_location: str = OPT, sse_customer_algorithm: str = OPT, sse_customer_key: str = OPT, sse_kms_key_id: str = OPT, sse_kms_encryption_context: str = OPT, bucket_key_enabled: bool = OPT, request_payer: str = OPT, object_lock_mode: str = OPT, object_lock_retain_until_datetime: datetime = OPT, object_lock_legal_hold_status: str = OPT, expected_bucket_owner: str = OPT, if_match: str = OPT, if_modified_since: datetime = OPT, if_none_match: str = OPT, if_unmodified_since: datetime = OPT, range: str = OPT, response_cache_control: str = OPT, response_content_disposition: str = OPT, response_content_encoding: str = OPT, response_content_language: str = OPT, response_content_type: str = OPT, response_expires: str = OPT, part_number: int = OPT, checksum_mode: str = OPT, transport_params: dict | None = None, bsm: BotoSesManager | S3Client | 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:
Returns:

a file-like object that has read() and write() 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.

Added in version 1.0.1.

Changed in version 1.2.1: add metadata and tags parameters

Changed in version 2.0.1: add version_id parameter

Changed in version 2.1.1: add full list of get_object, put_object, create_multipart_upload arguments