Data connection
S3Connector
Bases: ILogger
S3Connector - S3 Connection Manager
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
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 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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
__init__(env, bucket_name)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s3_bucket |
required |
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
22 23 24 25 26 27 28 29 30 |
|
check_key_exists(s3_key_to_check)
check_key_exists - Checks if an S3 key exists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s3_key_to_check |
str
|
required |
Returns:
Type | Description |
---|---|
bool
|
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
create_bucket()
Creates a bucket with the initialized bucket name.
Returns:
Type | Description |
---|---|
bool
|
The new bucket response |
Raises:
Type | Description |
---|---|
ClientError
|
If the creation failed for any reason. |
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
create_presigned_download_url(bucket_name, object_name, expiration=3600)
Generate a presigned URL S3 Get request to download a file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket_name |
str
|
string |
required |
object_name |
str
|
string |
required |
expiration |
Time in seconds for the presigned URL to remain valid |
3600
|
Returns:
Type | Description |
---|---|
URL encoded with the credentials in the query, to be fetched using any HTTP client. |
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
328 329 330 331 332 333 334 335 336 337 338 |
|
create_presigned_upload_url(object_name, fields=None, conditions=None, expiration=3600)
Generate a presigned URL S3 POST request to upload a file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket_name |
string |
required | |
object_name |
str
|
string |
required |
fields |
Dictionary of prefilled form fields |
None
|
|
conditions |
List of conditions to include in the policy |
None
|
|
expiration |
Time in seconds for the presigned URL to remain valid |
3600
|
Returns:
Type | Description |
---|---|
Dictionary with the following keys: url: URL to post to fields: Dictionary of form fields and values to submit with the POST request |
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
delete_bucket()
Deletes a bucket with the initialized bucket name.
Returns:
Type | Description |
---|---|
True if succeeded. |
Raises:
Type | Description |
---|---|
ClientError
|
If the creation failed for any reason. |
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
delete_key(s3_key_to_delete)
delete_key - Deletes a Key from an S3 Bucket :param s3_key_to_delete: :return: True/False if the operation succeeded/failed
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
download_file_by_path(s3_file_path, local_download_dir)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s3_file_path |
str
|
str - path ot s3 file e.g./ "s3://x/y.zip" |
required |
local_download_dir |
str
|
path to download |
required |
Returns:
Type | Description |
---|---|
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
download_key(target_path, key_to_download)
download_file - Downloads a key from S3 using boto3 to the provided filename Please Notice* - This method is for working with files, not objects :param key_to_download: The key (filename) to download from the S3 bucket :param target_path: Filename of the file to download the content of the key to :return: True/False if the operation succeeded/failed
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
download_keys_by_prefix(s3_bucket_path_prefix, local_download_dir, s3_file_path_prefix='')
download_keys_by_prefix - Download all of the keys who match the provided in-bucket path prefix and file prefix :param s3_bucket_path_prefix: The S3 "folder" to download from :param local_download_dir: The local directory to download the files to :param s3_file_path_prefix: The specific prefix of the files we want to download
Returns:
Type | Description |
---|---|
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
empty_folder_content_by_path_prefix(s3_bucket_path_prefix)
empty_folder_content_by_path_prefix - Deletes all of the files in the specified bucket path :param s3_bucket_path_prefix: The "folder" to empty :returns: Errors list
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
get_object_by_etag(bucket_relative_file_name, etag)
get_object_by_etag - Gets S3 object by it's ETag heder if it. exists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket_relative_file_name |
str
|
The name of the file in the bucket (relative) |
required |
etag |
str
|
The ETag of the object in S3 |
required |
Returns:
Type | Description |
---|---|
object
|
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
list_bucket_objects(prefix=None)
Gets a list of dictionaries, representing files in the S3 bucket that is passed in the constructor (self.bucket).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix |
str
|
A prefix filter for the files names. |
None
|
Returns:
Type | Description |
---|---|
List[dict]
|
the objects, dict as received from botocore. |
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
upload_buffer(new_key_name, buffer_to_write)
Uploads a buffer into a file in S3 with the provided key name. :bucket: The name of the bucket :new_key_name: The name of the file to create in s3 :buffer_to_write: A buffer that contains the file contents.
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
278 279 280 281 282 283 284 285 286 |
|
upload_file(filename_to_upload, key)
upload_file - Uploads a file to S3 via boto3 interface Please Notice - This method is for working with files, not objects :param key: The key (filename) to create in the S3 bucket :param filename_to_upload: Filename of the file to upload :return True/False if the operation succeeded/failed
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
upload_file_from_stream(file, key)
upload_file - Uploads a file to S3 via boto3 interface Please Notice - This method is for working with files, not objects :param key: The key (filename) to create in the S3 bucket :param filen: File to upload :return True/False if the operation succeeded/failed
Source code in V3_1/src/super_gradients/common/data_connection/s3_connector.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|