copy¶
Copy file from s3 to s3.
- class s3pathlib.core.copy.CopyAPIMixin[source]¶
A mixin class that implements copy related methods.
- copy_file(dst: S3Path, version_id: str = OPT, metadata: Dict[str, str] | None = OPT, tags: Dict[str, str] | None = OPT, overwrite: bool = False, bsm: BotoSesManager | S3Client | None = None, acl: str = OPT, cache_control: str = OPT, content_disposition: str = OPT, content_encoding: str = OPT, content_language: str = OPT, content_md5: str = OPT, content_type: str = OPT, copy_source_if_match: str = OPT, copy_source_if_modified_since: datetime = OPT, copy_source_if_none_match: str = OPT, copy_source_if_unmodified_since: datetime = 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, copy_source_sse_customer_algorithm: str = OPT, copy_source_sse_customer_key: str = 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, expected_source_bucket_owner: str = OPT) dict[source]¶
Copy an S3 file to a different S3 location.
- Parameters:
dst – copy to s3 object, it has to be an object
overwrite – if False, none of the file will be uploaded / overwritten if any of target s3 location already taken. Note that if the target S3 location is a versioning enabled bucket, logically you should be able to put a new version to an existing file, but this if
overwriteis True, then it won’t allow you to do that. You should setoverwriteto False if you want to put a new version.
- Returns:
number of object are copied, 0 or 1.
Added in version 1.0.1.
Changed in version 1.3.1: add
metadataandtagsargumentChanged in version 2.0.1: add
version_idargument
- copy_dir(dst: S3Path, metadata: Dict[str, str] | None = OPT, tags: Dict[str, str] | None = OPT, overwrite: bool = False, bsm: BotoSesManager | S3Client | None = None, acl: str = OPT, cache_control: str = OPT, content_disposition: str = OPT, content_encoding: str = OPT, content_language: str = OPT, content_md5: str = OPT, content_type: str = OPT, copy_source_if_match: str = OPT, copy_source_if_modified_since: datetime = OPT, copy_source_if_none_match: str = OPT, copy_source_if_unmodified_since: datetime = 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, copy_source_sse_customer_algorithm: str = OPT, copy_source_sse_customer_key: str = 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, expected_source_bucket_owner: str = OPT)[source]¶
Copy an S3 directory to a different S3 directory, including all subdirectory and files.
- Parameters:
dst – copy to s3 directory, it has to be a directory
overwrite – if False, none of the file will be uploaded / overwritten if any of target s3 location already taken. Note that if the source dir is a versioning enabled bucket, it will always copy the latest version of the object.
- Returns:
number of objects are copied
Added in version 1.0.1.
- TODO: add an argument
copy_all_historyto copy all object and all history if the source bucket is versioning enabled.
- copy_to(dst: S3Path, version_id: str = OPT, metadata: Dict[str, str] | None = OPT, tags: Dict[str, str] | None = OPT, overwrite: bool = False, bsm: BotoSesManager | S3Client | None = None, acl: str = OPT, cache_control: str = OPT, content_disposition: str = OPT, content_encoding: str = OPT, content_language: str = OPT, content_md5: str = OPT, content_type: str = OPT, copy_source_if_match: str = OPT, copy_source_if_modified_since: datetime = OPT, copy_source_if_none_match: str = OPT, copy_source_if_unmodified_since: datetime = 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, copy_source_sse_customer_algorithm: str = OPT, copy_source_sse_customer_key: str = 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, expected_source_bucket_owner: str = OPT) int[source]¶
Copy s3 object or s3 directory from one place to another place.
- Parameters:
dst – copy to s3 path
overwrite – if False, none of the file will be uploaded / overwritten if any of target s3 location already taken. Note that if the target S3 location is a versioning enabled bucket, logically you should be able to put a new version to an existing file, but this if
overwriteis True, then it won’t allow you to do that. You should setoverwriteto False if you want to put a new version.
Added in version 1.0.1.
Changed in version 1.3.1: add
metadataandtagsargumentChanged in version 2.0.1: add
version_idargument
- move_to(dst: S3Path, metadata: Dict[str, str] | None = OPT, tags: Dict[str, str] | None = OPT, overwrite: bool = False, bsm: BotoSesManager | S3Client | None = None, acl: str = OPT, cache_control: str = OPT, content_disposition: str = OPT, content_encoding: str = OPT, content_language: str = OPT, content_md5: str = OPT, content_type: str = OPT, copy_source_if_match: str = OPT, copy_source_if_modified_since: datetime = OPT, copy_source_if_none_match: str = OPT, copy_source_if_unmodified_since: datetime = 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, copy_source_sse_customer_algorithm: str = OPT, copy_source_sse_customer_key: str = 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, expected_source_bucket_owner: str = OPT) int[source]¶
Move s3 object or s3 directory from one place to another place. It is firstly
S3Path.copy_to()thenS3Path.delete_if_exists()- Parameters:
dst – copy to s3 path
overwrite – if False, none of the file will be uploaded / overwritten if any of target s3 location already taken. Note that if the target S3 location is a versioning enabled bucket, logically you should be able to put a new version to an existing file, but this if
overwriteis True, then it won’t allow you to do that. You should setoverwriteto False if you want to put a new version.
Added in version 1.0.1.
Changed in version 1.3.1: add
metadataandtagsargument