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 = Sentinel('NOTHING'), metadata: Dict[str, str] | None = Sentinel('NOTHING'), tags: Dict[str, str] | None = Sentinel('NOTHING'), overwrite: bool = False, bsm: BotoSesManager | None = None, acl: str = Sentinel('NOTHING'), cache_control: str = Sentinel('NOTHING'), content_disposition: str = Sentinel('NOTHING'), content_encoding: str = Sentinel('NOTHING'), content_language: str = Sentinel('NOTHING'), content_md5: str = Sentinel('NOTHING'), content_type: str = Sentinel('NOTHING'), copy_source_if_match: str = Sentinel('NOTHING'), copy_source_if_modified_since: datetime = Sentinel('NOTHING'), copy_source_if_none_match: str = Sentinel('NOTHING'), copy_source_if_unmodified_since: datetime = Sentinel('NOTHING'), expires_datetime: datetime = Sentinel('NOTHING'), grant_full_control: str = Sentinel('NOTHING'), grant_read: str = Sentinel('NOTHING'), grant_read_acp: str = Sentinel('NOTHING'), grant_write_acp: str = Sentinel('NOTHING'), server_side_encryption: str = Sentinel('NOTHING'), storage_class: str = Sentinel('NOTHING'), website_redirect_location: str = Sentinel('NOTHING'), sse_customer_algorithm: str = Sentinel('NOTHING'), sse_customer_key: str = Sentinel('NOTHING'), sse_kms_key_id: str = Sentinel('NOTHING'), sse_kms_encryption_context: str = Sentinel('NOTHING'), bucket_key_enabled: bool = Sentinel('NOTHING'), copy_source_sse_customer_algorithm: str = Sentinel('NOTHING'), copy_source_sse_customer_key: str = Sentinel('NOTHING'), request_payer: str = Sentinel('NOTHING'), object_lock_mode: str = Sentinel('NOTHING'), object_lock_retain_until_datetime: datetime = Sentinel('NOTHING'), object_lock_legal_hold_status: str = Sentinel('NOTHING'), expected_bucket_owner: str = Sentinel('NOTHING'), expected_source_bucket_owner: str = Sentinel('NOTHING')) 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
overwrite
is True, then it won’t allow you to do that. You should setoverwrite
to False if you want to put a new version.
- Returns:
number of object are copied, 0 or 1.
New in version 1.0.1.
Changed in version 1.3.1: add
metadata
andtags
argumentChanged in version 2.0.1: add
version_id
argument
- copy_dir(dst: S3Path, metadata: Dict[str, str] | None = Sentinel('NOTHING'), tags: Dict[str, str] | None = Sentinel('NOTHING'), overwrite: bool = False, bsm: BotoSesManager | None = None, acl: str = Sentinel('NOTHING'), cache_control: str = Sentinel('NOTHING'), content_disposition: str = Sentinel('NOTHING'), content_encoding: str = Sentinel('NOTHING'), content_language: str = Sentinel('NOTHING'), content_md5: str = Sentinel('NOTHING'), content_type: str = Sentinel('NOTHING'), copy_source_if_match: str = Sentinel('NOTHING'), copy_source_if_modified_since: datetime = Sentinel('NOTHING'), copy_source_if_none_match: str = Sentinel('NOTHING'), copy_source_if_unmodified_since: datetime = Sentinel('NOTHING'), expires_datetime: datetime = Sentinel('NOTHING'), grant_full_control: str = Sentinel('NOTHING'), grant_read: str = Sentinel('NOTHING'), grant_read_acp: str = Sentinel('NOTHING'), grant_write_acp: str = Sentinel('NOTHING'), server_side_encryption: str = Sentinel('NOTHING'), storage_class: str = Sentinel('NOTHING'), website_redirect_location: str = Sentinel('NOTHING'), sse_customer_algorithm: str = Sentinel('NOTHING'), sse_customer_key: str = Sentinel('NOTHING'), sse_kms_key_id: str = Sentinel('NOTHING'), sse_kms_encryption_context: str = Sentinel('NOTHING'), bucket_key_enabled: bool = Sentinel('NOTHING'), copy_source_sse_customer_algorithm: str = Sentinel('NOTHING'), copy_source_sse_customer_key: str = Sentinel('NOTHING'), request_payer: str = Sentinel('NOTHING'), object_lock_mode: str = Sentinel('NOTHING'), object_lock_retain_until_datetime: datetime = Sentinel('NOTHING'), object_lock_legal_hold_status: str = Sentinel('NOTHING'), expected_bucket_owner: str = Sentinel('NOTHING'), expected_source_bucket_owner: str = Sentinel('NOTHING'))[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
New in version 1.0.1.
- TODO: add an argument
copy_all_history
to copy all object and all history if the source bucket is versioning enabled.
- copy_to(dst: S3Path, version_id: str = Sentinel('NOTHING'), metadata: Dict[str, str] | None = Sentinel('NOTHING'), tags: Dict[str, str] | None = Sentinel('NOTHING'), overwrite: bool = False, bsm: BotoSesManager | None = None, acl: str = Sentinel('NOTHING'), cache_control: str = Sentinel('NOTHING'), content_disposition: str = Sentinel('NOTHING'), content_encoding: str = Sentinel('NOTHING'), content_language: str = Sentinel('NOTHING'), content_md5: str = Sentinel('NOTHING'), content_type: str = Sentinel('NOTHING'), copy_source_if_match: str = Sentinel('NOTHING'), copy_source_if_modified_since: datetime = Sentinel('NOTHING'), copy_source_if_none_match: str = Sentinel('NOTHING'), copy_source_if_unmodified_since: datetime = Sentinel('NOTHING'), expires_datetime: datetime = Sentinel('NOTHING'), grant_full_control: str = Sentinel('NOTHING'), grant_read: str = Sentinel('NOTHING'), grant_read_acp: str = Sentinel('NOTHING'), grant_write_acp: str = Sentinel('NOTHING'), server_side_encryption: str = Sentinel('NOTHING'), storage_class: str = Sentinel('NOTHING'), website_redirect_location: str = Sentinel('NOTHING'), sse_customer_algorithm: str = Sentinel('NOTHING'), sse_customer_key: str = Sentinel('NOTHING'), sse_kms_key_id: str = Sentinel('NOTHING'), sse_kms_encryption_context: str = Sentinel('NOTHING'), bucket_key_enabled: bool = Sentinel('NOTHING'), copy_source_sse_customer_algorithm: str = Sentinel('NOTHING'), copy_source_sse_customer_key: str = Sentinel('NOTHING'), request_payer: str = Sentinel('NOTHING'), object_lock_mode: str = Sentinel('NOTHING'), object_lock_retain_until_datetime: datetime = Sentinel('NOTHING'), object_lock_legal_hold_status: str = Sentinel('NOTHING'), expected_bucket_owner: str = Sentinel('NOTHING'), expected_source_bucket_owner: str = Sentinel('NOTHING')) 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
overwrite
is True, then it won’t allow you to do that. You should setoverwrite
to False if you want to put a new version.
New in version 1.0.1.
Changed in version 1.3.1: add
metadata
andtags
argumentChanged in version 2.0.1: add
version_id
argument
- move_to(dst: S3Path, metadata: Dict[str, str] | None = Sentinel('NOTHING'), tags: Dict[str, str] | None = Sentinel('NOTHING'), overwrite: bool = False, bsm: BotoSesManager | None = None, acl: str = Sentinel('NOTHING'), cache_control: str = Sentinel('NOTHING'), content_disposition: str = Sentinel('NOTHING'), content_encoding: str = Sentinel('NOTHING'), content_language: str = Sentinel('NOTHING'), content_md5: str = Sentinel('NOTHING'), content_type: str = Sentinel('NOTHING'), copy_source_if_match: str = Sentinel('NOTHING'), copy_source_if_modified_since: datetime = Sentinel('NOTHING'), copy_source_if_none_match: str = Sentinel('NOTHING'), copy_source_if_unmodified_since: datetime = Sentinel('NOTHING'), expires_datetime: datetime = Sentinel('NOTHING'), grant_full_control: str = Sentinel('NOTHING'), grant_read: str = Sentinel('NOTHING'), grant_read_acp: str = Sentinel('NOTHING'), grant_write_acp: str = Sentinel('NOTHING'), server_side_encryption: str = Sentinel('NOTHING'), storage_class: str = Sentinel('NOTHING'), website_redirect_location: str = Sentinel('NOTHING'), sse_customer_algorithm: str = Sentinel('NOTHING'), sse_customer_key: str = Sentinel('NOTHING'), sse_kms_key_id: str = Sentinel('NOTHING'), sse_kms_encryption_context: str = Sentinel('NOTHING'), bucket_key_enabled: bool = Sentinel('NOTHING'), copy_source_sse_customer_algorithm: str = Sentinel('NOTHING'), copy_source_sse_customer_key: str = Sentinel('NOTHING'), request_payer: str = Sentinel('NOTHING'), object_lock_mode: str = Sentinel('NOTHING'), object_lock_retain_until_datetime: datetime = Sentinel('NOTHING'), object_lock_legal_hold_status: str = Sentinel('NOTHING'), expected_bucket_owner: str = Sentinel('NOTHING'), expected_source_bucket_owner: str = Sentinel('NOTHING')) 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
overwrite
is True, then it won’t allow you to do that. You should setoverwrite
to False if you want to put a new version.
New in version 1.0.1.
Changed in version 1.3.1: add
metadata
andtags
argument