s3_client
¶
Classes:
-
S3Client
–
S3Client
¶
S3Client()
Methods:
-
download
–Download a file from S3 to a local directory.
-
exists
–Check if a file exists in S3 at the given URI.
-
generate_presigned_uri
–Generate a presigned URL from a given S3 URI with a default expiration of 7 days.
-
traverse
–Traverse through an S3 "directory" and return entries under it.
-
upload
–Upload a local file to S3.
-
walk
–Generator that walks all objects under the given S3 URI.
Source code in src/unibox/utils/s3_client.py
21 22 23 24 |
|
download
¶
Download a file from S3 to a local directory. :param s3_uri: S3 URI (e.g. s3://bucket/key) :param target_dir: Local directory path :return: Local file path
Source code in src/unibox/utils/s3_client.py
26 27 28 29 30 31 32 33 34 35 36 |
|
exists
¶
Check if a file exists in S3 at the given URI. :param s3_uri: S3 URI :return: True if object exists, False otherwise.
Source code in src/unibox/utils/s3_client.py
46 47 48 49 50 51 52 53 54 55 56 |
|
generate_presigned_uri
¶
Generate a presigned URL from a given S3 URI with a default expiration of 7 days.
:param s3_uri: S3 URI (e.g., 's3://bucket-name/object-key') :param expiration: Time in seconds for the presigned URL to remain valid (default 7 days). :return: Presigned URL as a string. If error, returns None.
Source code in src/unibox/utils/s3_client.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
traverse
¶
traverse(
s3_uri: str,
include_extensions=None,
exclude_extensions=None,
relative_unix=False,
debug_print=True,
)
Traverse through an S3 "directory" and return entries under it.
:param include_extensions: list of file extensions to include (e.g. ['.jpg', '.png']). :param exclude_extensions: list of file extensions to exclude (e.g. ['.txt', '.json']). :param relative_unix: return relative paths or full s3:// URIs. :param debug_print: whether to show a tqdm progress bar. :return: list of keys or URIs.
Source code in src/unibox/utils/s3_client.py
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 |
|
upload
¶
Upload a local file to S3. :param file_path: Local file path :param s3_uri: S3 URI (e.g. s3://bucket/key)
Source code in src/unibox/utils/s3_client.py
38 39 40 41 42 43 44 |
|
walk
¶
walk(s3_uri: str)
Generator that walks all objects under the given S3 URI. Yields metadata dictionaries for each object.
Source code in src/unibox/utils/s3_client.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|