PyS3Uploader 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of PyS3Uploader might be problematic. Click here for more details.
- {pys3uploader-0.2.0.dist-info → pys3uploader-0.2.1.dist-info}/METADATA +3 -1
- pys3uploader-0.2.1.dist-info/RECORD +11 -0
- s3/__init__.py +1 -1
- s3/uploader.py +21 -10
- s3/utils.py +14 -0
- pys3uploader-0.2.0.dist-info/RECORD +0 -11
- {pys3uploader-0.2.0.dist-info → pys3uploader-0.2.1.dist-info}/LICENSE +0 -0
- {pys3uploader-0.2.0.dist-info → pys3uploader-0.2.1.dist-info}/WHEEL +0 -0
- {pys3uploader-0.2.0.dist-info → pys3uploader-0.2.1.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: PyS3Uploader
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Python module to upload objects to an S3 bucket.
|
|
5
5
|
Author-email: Vignesh Rao <svignesh1793@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -115,6 +115,8 @@ if __name__ == '__main__':
|
|
|
115
115
|
#### Optional kwargs
|
|
116
116
|
- **s3_prefix** - S3 object prefix for each file. Defaults to ``None``
|
|
117
117
|
- **exclude_path** - Path in ``upload_dir`` that has to be excluded in object keys. Defaults to `None`
|
|
118
|
+
- **skip_dot_files** - Boolean flag to skip dot files. Defaults to ``True``
|
|
119
|
+
- **overwrite** - Boolean flag to overwrite files present in S3. Defaults to ``False``
|
|
118
120
|
- **logger** - Bring your own custom pre-configured logger. Defaults to on-screen logging.
|
|
119
121
|
<br><br>
|
|
120
122
|
- **region_name** - AWS region name. Defaults to the env var `AWS_DEFAULT_REGION`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
s3/__init__.py,sha256=IqcPR9iWMw0GDBEmKvLzW7P-AhInTkwRklkvYgiT1Xc,66
|
|
2
|
+
s3/exceptions.py,sha256=hH3jlMOe8yjBatQK9EdndWZz4QESU74KSY_iDhQ37SY,2585
|
|
3
|
+
s3/logger.py,sha256=oH540oq8jY723jA4lDWlgfFPLbNgGXTkDwFpB7TLO_o,1196
|
|
4
|
+
s3/tree.py,sha256=DiQ2ekMMaj2m_P3-iKkEqSuJCJZ_UZxcAwHtAoPVa5c,1824
|
|
5
|
+
s3/uploader.py,sha256=v6TGdm8EcAldoIw3GOAwkuoUzi9b9IRj8b94hl1Pkyw,11454
|
|
6
|
+
s3/utils.py,sha256=dd1OeLbswLzFVyjYiXixkJlFsoGWRtRCOHha6wLG5zQ,2485
|
|
7
|
+
pys3uploader-0.2.1.dist-info/LICENSE,sha256=8k-hEraOzyum0GvmmK65YxNRTFXK7eIFHJ0OshJXeTk,1068
|
|
8
|
+
pys3uploader-0.2.1.dist-info/METADATA,sha256=NA7x6YqpWEKvn3XEYzVug7XTl1vPcwiphUzWtMvlzHE,7449
|
|
9
|
+
pys3uploader-0.2.1.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
|
10
|
+
pys3uploader-0.2.1.dist-info/top_level.txt,sha256=iQp4y1P58Q633gj8M08kHE4mqqT0hixuDWcniDk_RJ4,3
|
|
11
|
+
pys3uploader-0.2.1.dist-info/RECORD,,
|
s3/__init__.py
CHANGED
s3/uploader.py
CHANGED
|
@@ -11,7 +11,13 @@ from tqdm import tqdm
|
|
|
11
11
|
|
|
12
12
|
from s3.exceptions import BucketNotFound
|
|
13
13
|
from s3.logger import default_logger
|
|
14
|
-
from s3.utils import
|
|
14
|
+
from s3.utils import (
|
|
15
|
+
RETRY_CONFIG,
|
|
16
|
+
UploadResults,
|
|
17
|
+
convert_to_folder_structure,
|
|
18
|
+
getenv,
|
|
19
|
+
urljoin,
|
|
20
|
+
)
|
|
15
21
|
|
|
16
22
|
|
|
17
23
|
class Uploader:
|
|
@@ -21,19 +27,19 @@ class Uploader:
|
|
|
21
27
|
|
|
22
28
|
"""
|
|
23
29
|
|
|
24
|
-
RETRY_CONFIG: Config = Config(retries={"max_attempts": 10, "mode": "standard"})
|
|
25
|
-
|
|
26
30
|
def __init__(
|
|
27
31
|
self,
|
|
28
32
|
bucket_name: str,
|
|
29
33
|
upload_dir: str,
|
|
30
34
|
s3_prefix: str = None,
|
|
31
35
|
exclude_path: str = None,
|
|
36
|
+
skip_dot_files: bool = True,
|
|
32
37
|
overwrite: bool = False,
|
|
33
38
|
region_name: str = None,
|
|
34
39
|
profile_name: str = None,
|
|
35
40
|
aws_access_key_id: str = None,
|
|
36
41
|
aws_secret_access_key: str = None,
|
|
42
|
+
retry_config: Config = RETRY_CONFIG,
|
|
37
43
|
logger: logging.Logger = None,
|
|
38
44
|
):
|
|
39
45
|
"""Initiates all the necessary args and creates a boto3 session with retry logic.
|
|
@@ -43,6 +49,7 @@ class Uploader:
|
|
|
43
49
|
upload_dir: Full path of the directory to be uploaded.
|
|
44
50
|
s3_prefix: Particular bucket prefix within which the upload should happen.
|
|
45
51
|
exclude_path: Full directory path to exclude from S3 object prefix.
|
|
52
|
+
skip_dot_files: Boolean flag to skip dot files.
|
|
46
53
|
overwrite: Boolean flag to overwrite files in S3.
|
|
47
54
|
region_name: Name of the AWS region.
|
|
48
55
|
profile_name: AWS profile name.
|
|
@@ -51,18 +58,18 @@ class Uploader:
|
|
|
51
58
|
logger: Bring your own logger.
|
|
52
59
|
|
|
53
60
|
See Also:
|
|
61
|
+
s3_prefix:
|
|
62
|
+
If provided, ``s3_prefix`` will always be attached to each object.
|
|
63
|
+
|
|
64
|
+
If ``s3_prefix`` is set to: ``2025``, then the file path
|
|
65
|
+
``/home/ubuntu/Desktop/S3Upload/sub/photo.jpg`` will be uploaded as ``2025/S3Upload/sub/photo.jpg``
|
|
66
|
+
|
|
54
67
|
exclude_path:
|
|
55
68
|
When upload directory is "/home/ubuntu/Desktop/S3Upload", each file will naturally have the full prefix.
|
|
56
69
|
However, this behavior can be avoided by specifying the ``exclude_path`` parameter.
|
|
57
70
|
|
|
58
71
|
If exclude_path is set to: ``/home/ubuntu/Desktop``, then the file path
|
|
59
72
|
``/home/ubuntu/Desktop/S3Upload/sub-dir/photo.jpg`` will be uploaded as ``S3Upload/sub-dir/photo.jpg``
|
|
60
|
-
|
|
61
|
-
s3_prefix:
|
|
62
|
-
If provided, ``s3_prefix`` will always be attached to each object.
|
|
63
|
-
|
|
64
|
-
If ``s3_prefix`` is set to: ``2025``, then the file path
|
|
65
|
-
``/home/ubuntu/Desktop/S3Upload/sub/photo.jpg`` will be uploaded as ``2025/S3Upload/sub/photo.jpg``
|
|
66
73
|
"""
|
|
67
74
|
self.session = boto3.Session(
|
|
68
75
|
profile_name=profile_name or getenv("PROFILE_NAME"),
|
|
@@ -70,7 +77,7 @@ class Uploader:
|
|
|
70
77
|
aws_access_key_id=aws_access_key_id or getenv("AWS_ACCESS_KEY_ID"),
|
|
71
78
|
aws_secret_access_key=aws_secret_access_key or getenv("AWS_SECRET_ACCESS_KEY"),
|
|
72
79
|
)
|
|
73
|
-
self.s3 = self.session.resource(service_name="s3", config=
|
|
80
|
+
self.s3 = self.session.resource(service_name="s3", config=retry_config)
|
|
74
81
|
|
|
75
82
|
self.logger = logger or default_logger()
|
|
76
83
|
|
|
@@ -78,6 +85,7 @@ class Uploader:
|
|
|
78
85
|
self.upload_dir = upload_dir or getenv("UPLOAD_DIR", "UPLOAD_SOURCE")
|
|
79
86
|
self.s3_prefix = s3_prefix
|
|
80
87
|
self.exclude_path = exclude_path
|
|
88
|
+
self.skip_dot_files = skip_dot_files
|
|
81
89
|
self.overwrite = overwrite
|
|
82
90
|
|
|
83
91
|
self.results = UploadResults()
|
|
@@ -176,6 +184,9 @@ class Uploader:
|
|
|
176
184
|
files_to_upload = {}
|
|
177
185
|
for __path, __directory, __files in os.walk(self.upload_dir):
|
|
178
186
|
for file_ in __files:
|
|
187
|
+
if self.skip_dot_files and file_.startswith("."):
|
|
188
|
+
self.logger.info("Skipping dot file: %s", file_)
|
|
189
|
+
continue
|
|
179
190
|
file_path = os.path.join(__path, file_)
|
|
180
191
|
if self.exclude_path:
|
|
181
192
|
relative_path = file_path.replace(self.exclude_path, "")
|
s3/utils.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import Dict, Set
|
|
3
3
|
|
|
4
|
+
from botocore.config import Config
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
class UploadResults(dict):
|
|
6
8
|
"""Object to store results of S3 upload.
|
|
@@ -13,6 +15,18 @@ class UploadResults(dict):
|
|
|
13
15
|
failed: int = 0
|
|
14
16
|
|
|
15
17
|
|
|
18
|
+
RETRY_CONFIG: Config = Config(
|
|
19
|
+
retries={
|
|
20
|
+
"max_attempts": 10,
|
|
21
|
+
"mode": "adaptive", # Adaptive retry mode with jitter
|
|
22
|
+
"total_max_attempts": 20, # Max retries across all requests
|
|
23
|
+
},
|
|
24
|
+
# Adding custom timeouts here:
|
|
25
|
+
connect_timeout=5, # 5 seconds for establishing a connection
|
|
26
|
+
read_timeout=30, # 30 seconds to wait for a response from the server
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
16
30
|
def getenv(*args, default: str = None) -> str:
|
|
17
31
|
"""Returns the key-ed environment variable or the default value."""
|
|
18
32
|
for key in args:
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
s3/__init__.py,sha256=yLvvl4-uTLZwhdhCMQpWq5juX_zFuYAfKSf4aB0WjZw,66
|
|
2
|
-
s3/exceptions.py,sha256=hH3jlMOe8yjBatQK9EdndWZz4QESU74KSY_iDhQ37SY,2585
|
|
3
|
-
s3/logger.py,sha256=oH540oq8jY723jA4lDWlgfFPLbNgGXTkDwFpB7TLO_o,1196
|
|
4
|
-
s3/tree.py,sha256=DiQ2ekMMaj2m_P3-iKkEqSuJCJZ_UZxcAwHtAoPVa5c,1824
|
|
5
|
-
s3/uploader.py,sha256=IAlFrEjfBuexrfmBPGN9OZAfHjQuwcGRzWi2es0r_fU,11154
|
|
6
|
-
s3/utils.py,sha256=0kcG0aE2olHhC8thaUEwx2J8tOI2-2TGCk6E6U-PiKw,2058
|
|
7
|
-
pys3uploader-0.2.0.dist-info/LICENSE,sha256=8k-hEraOzyum0GvmmK65YxNRTFXK7eIFHJ0OshJXeTk,1068
|
|
8
|
-
pys3uploader-0.2.0.dist-info/METADATA,sha256=IXSmHXJJndlnd_6MHlpZrcVILPni8VUbVNJYQEjMIR8,7286
|
|
9
|
-
pys3uploader-0.2.0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
|
10
|
-
pys3uploader-0.2.0.dist-info/top_level.txt,sha256=iQp4y1P58Q633gj8M08kHE4mqqT0hixuDWcniDk_RJ4,3
|
|
11
|
-
pys3uploader-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|