MCPcopy Create free account
hub / github.com/pyathena-dev/PyAthena / exists

Method exists

pyathena/filesystem/s3.py:712–752  ·  view source on GitHub ↗

Check if an S3 path exists. Determines whether a bucket, object, or prefix exists in S3. Uses caching and efficient head operations to minimize API calls. Args: path: S3 path to check (e.g., "s3://bucket" or "s3://bucket/key"). **kwargs: Additional a

(self, path: str, **kwargs)

Source from the content-addressed store, hash-verified

710 return [f.name for f in files]
711
712 def exists(self, path: str, **kwargs) -> bool:
713 """Check if an S3 path exists.
714
715 Determines whether a bucket, object, or prefix exists in S3.
716 Uses caching and efficient head operations to minimize API calls.
717
718 Args:
719 path: S3 path to check (e.g., "s3://bucket" or "s3://bucket/key").
720 **kwargs: Additional arguments (unused).
721
722 Returns:
723 True if the path exists, False otherwise.
724
725 Example:
726 >>> fs = S3FileSystem()
727 >>> fs.exists("s3://my-bucket/file.txt")
728 >>> fs.exists("s3://my-bucket/")
729 """
730 path = self._strip_protocol(path)
731 if path in ["", "/"]:
732 # The root always exists.
733 return True
734 bucket, key, _ = self.parse_path(path)
735 if key:
736 try:
737 if self._ls_from_cache(path):
738 return True
739 info = self.info(path)
740 return bool(info)
741 except FileNotFoundError:
742 return False
743 elif self.dircache.get(bucket, False):
744 return True
745 else:
746 try:
747 if self._ls_from_cache(bucket):
748 return True
749 except FileNotFoundError:
750 pass
751 file = self._head_bucket(bucket)
752 return bool(file)
753
754 def rm_file(self, path: str, **kwargs) -> None:
755 bucket, key, version_id = self.parse_path(path)

Callers 15

mkdirMethod · 0.95
rmdirMethod · 0.95
touchMethod · 0.95
pipe_fileMethod · 0.95
__init__Method · 0.80
test_exists_bucketMethod · 0.80
test_exists_objectMethod · 0.80
test_rm_fileMethod · 0.80
test_rmMethod · 0.80
test_rm_recursiveMethod · 0.80
test_touchMethod · 0.80

Calls 5

parse_pathMethod · 0.95
_ls_from_cacheMethod · 0.95
infoMethod · 0.95
_head_bucketMethod · 0.95
getMethod · 0.45

Tested by 11

test_exists_bucketMethod · 0.64
test_exists_objectMethod · 0.64
test_rm_fileMethod · 0.64
test_rmMethod · 0.64
test_rm_recursiveMethod · 0.64
test_touchMethod · 0.64
test_moveMethod · 0.64
test_sync_wrappersMethod · 0.64