Reference
async_s3
S3 Bucket helper utils. Async list objects by folders
The file is mandatory for build system to find the package.
S3BucketObjects
Source code in src/async_s3/s3_bucket_objects.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
__init__(bucket, *, parallelism=DEFAULT_PARALLELISM)
Initialize the S3BucketObjects object.
bucket: The name of the S3 bucket. parallelism: The maximum number of concurrent requests to AWS S3.
Source code in src/async_s3/s3_bucket_objects.py
32 33 34 35 36 37 38 39 | |
iter(prefix='/', *, max_level=None, max_folders=None, delimiter='/')
async
Generator that yields objects in the bucket with the given prefix.
Yield objects by partial chunks (list of AWS S3 object dicts) as they are collected from AWS asynchronously.
max_level: The maximum folders depth to traverse in separate requests. If None, traverse all levels. max_folders: The maximum number of folders to load in separate requests. If None, requests all folders. Otherwise, the folders are grouped by prefixes before loading in separate requests. Try to group in the given number of folders if possible. delimiter: The delimiter for "folders".
Source code in src/async_s3/s3_bucket_objects.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
list(prefix='/', *, max_level=None, max_folders=None, delimiter='/')
async
List all objects in the bucket with the given prefix.
max_level: The maximum folders depth to traverse in separate requests.
If None, traverse all levels.
max_folders: The maximum number of folders to load in separate requests.
If None, requests all folders.
Otherwise, the folders are grouped by prefixes before loading in separate requests.
Try to group to the given max_folders if possible.
delimiter: The delimiter for "folders".
Source code in src/async_s3/s3_bucket_objects.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
group_by_prefix
find_longest_common_prefix(words)
Finds the longest common prefix among a list of words.
Source code in src/async_s3/group_by_prefix.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
group_by_prefix(words, desired_group_count)
Groups words by prefixes to create a desired number of word groups.
Try to create the desired number of groups if possible.
Source code in src/async_s3/group_by_prefix.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
main
async-s3.
ListingConfig
dataclass
Configuration for S3 object listing operations.
Source code in src/async_s3/main.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
bucket
property
Extract bucket name from S3 URL.
key
property
Extract key/prefix from S3 URL.
S3ListCommand
Base class for S3 listing commands.
Source code in src/async_s3/main.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
validate_and_execute()
Validate S3 URL and execute listing.
Source code in src/async_s3/main.py
89 90 91 92 93 | |
as3()
Async S3.
Source code in src/async_s3/main.py
62 63 64 65 | |
du(s3_url, max_level, max_folders, repeat, parallelism, delimiter)
Show count and size for objects in an S3 bucket.
Example: as3 du s3://bucket/key
Source code in src/async_s3/main.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
error(message)
Print an error message and exit.
Source code in src/async_s3/main.py
44 45 46 47 | |
human_readable_size(size, decimal_places=2)
Convert bytes to a human-readable format.
Source code in src/async_s3/main.py
193 194 195 196 197 198 199 200 | |
list_objects(config)
List objects in an S3 bucket.
Source code in src/async_s3/main.py
203 204 205 | |
list_objects_async(config)
async
List objects in an S3 bucket.
Source code in src/async_s3/main.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
list_objects_options(func)
Add common options to commands using list_objects.
Source code in src/async_s3/main.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
list_objects_with_progress(s3_list, config)
async
List objects in an S3 bucket with a progress bar.
Returns:
| Type | Description |
|---|---|
tuple[Iterable[dict[str, Any]], float]
|
(The objects, the elapsed time) |
Source code in src/async_s3/main.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
ls(s3_url, max_level, max_folders, repeat, parallelism, delimiter)
List objects in an S3 bucket.
Example: as3 ls s3://bucket/key
Source code in src/async_s3/main.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
print_attempt_info(attempt, duration)
Print the elapsed time for an attempt.
Source code in src/async_s3/main.py
301 302 303 304 305 306 307 | |
print_average_time(total_time, repeat)
Print the average elapsed time.
Source code in src/async_s3/main.py
310 311 312 313 314 315 316 | |
print_start_info(config)
Print the command parameters.
Source code in src/async_s3/main.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
print_summary(objects)
Print a summary of the objects.
Source code in src/async_s3/main.py
50 51 52 53 54 55 56 57 58 59 | |
split_s3_url(s3_url)
Split an S3 URL into bucket and key.
Source code in src/async_s3/main.py
248 249 250 251 | |
validate_delimiter(ctx, param, value)
Validate the Delimiter option.
Source code in src/async_s3/main.py
143 144 145 146 147 | |
s3_bucket_objects
S3BucketObjects
Source code in src/async_s3/s3_bucket_objects.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
__init__(bucket, *, parallelism=DEFAULT_PARALLELISM)
Initialize the S3BucketObjects object.
bucket: The name of the S3 bucket. parallelism: The maximum number of concurrent requests to AWS S3.
Source code in src/async_s3/s3_bucket_objects.py
32 33 34 35 36 37 38 39 | |
iter(prefix='/', *, max_level=None, max_folders=None, delimiter='/')
async
Generator that yields objects in the bucket with the given prefix.
Yield objects by partial chunks (list of AWS S3 object dicts) as they are collected from AWS asynchronously.
max_level: The maximum folders depth to traverse in separate requests. If None, traverse all levels. max_folders: The maximum number of folders to load in separate requests. If None, requests all folders. Otherwise, the folders are grouped by prefixes before loading in separate requests. Try to group in the given number of folders if possible. delimiter: The delimiter for "folders".
Source code in src/async_s3/s3_bucket_objects.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
list(prefix='/', *, max_level=None, max_folders=None, delimiter='/')
async
List all objects in the bucket with the given prefix.
max_level: The maximum folders depth to traverse in separate requests.
If None, traverse all levels.
max_folders: The maximum number of folders to load in separate requests.
If None, requests all folders.
Otherwise, the folders are grouped by prefixes before loading in separate requests.
Try to group to the given max_folders if possible.
delimiter: The delimiter for "folders".
Source code in src/async_s3/s3_bucket_objects.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
create_session()
cached
Create a session object.
Source code in src/async_s3/s3_bucket_objects.py
16 17 18 19 | |
get_s3_client()
Get S3 client.
Source code in src/async_s3/s3_bucket_objects.py
22 23 24 25 26 27 28 | |