awswrangler.s3.list_directories¶
- awswrangler.s3.list_directories(path: str, chunked: bool = False, s3_additional_kwargs: dict[str, Any] | None = None, boto3_session: Session | None = None) list[str] | Iterator[list[str]] ¶
List Amazon S3 objects from a prefix.
This function accepts Unix shell-style wildcards in the path argument. * (matches everything), ? (matches any single character), [seq] (matches any character in seq), [!seq] (matches any character not in seq). If you want to use a path which includes Unix shell-style wildcard characters (*, ?, []), you can use glob.escape(path) before passing the path to this function.
Note
Following arguments are not supported in distributed mode with engine EngineEnum.RAY:
boto3_session
s3_additional_kwargs
- Parameters:
path (
str
) – S3 path (e.g. s3://bucket/prefix).chunked (
bool
) – If True returns iterator, and a single list otherwise. False by default.s3_additional_kwargs (
dict
[str
,Any
] |None
) – Forwarded to botocore requests. e.g. s3_additional_kwargs={‘RequestPayer’: ‘requester’}boto3_session (
Session
|None
) – Boto3 Session. The default boto3 session will be used if boto3_session receive None.
- Return type:
list
[str
] |Iterator
[list
[str
]]- Returns:
List of objects paths.
Examples
Using the default boto3 session
>>> import awswrangler as wr >>> wr.s3.list_directories('s3://bucket/prefix/') ['s3://bucket/prefix/dir0/', 's3://bucket/prefix/dir1/', 's3://bucket/prefix/dir2/']
Using a custom boto3 session
>>> import boto3 >>> import awswrangler as wr >>> wr.s3.list_directories('s3://bucket/prefix/', boto3_session=boto3.Session()) ['s3://bucket/prefix/dir0/', 's3://bucket/prefix/dir1/', 's3://bucket/prefix/dir2/']