awswrangler.s3.does_object_exist

awswrangler.s3.does_object_exist(path: str, s3_additional_kwargs: Optional[Dict[str, Any]] = None, boto3_session: Optional[boto3.session.Session] = None, version_id: Optional[str] = None) bool

Check if object exists on S3.

Parameters
  • path (str) – S3 path (e.g. s3://bucket/key).

  • s3_additional_kwargs (Optional[Dict[str, Any]]) – Forwarded to botocore requests. e.g. s3_additional_kwargs={‘RequestPayer’: ‘requester’}

  • boto3_session (boto3.Session(), optional) – Boto3 Session. The default boto3 session will be used if boto3_session receive None.

  • version_id (str, optional) – Specific version of the object that should exist.

Returns

True if exists, False otherwise.

Return type

bool

Examples

Using the default boto3 session

>>> import awswrangler as wr
>>> wr.s3.does_object_exist('s3://bucket/key_real')
True
>>> wr.s3.does_object_exist('s3://bucket/key_unreal')
False

Using a custom boto3 session

>>> import boto3
>>> import awswrangler as wr
>>> wr.s3.does_object_exist('s3://bucket/key_real', boto3_session=boto3.Session())
True
>>> wr.s3.does_object_exist('s3://bucket/key_unreal', boto3_session=boto3.Session())
False