ob-metaflow-stubs 2.11.4.1__py2.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.
- metaflow-stubs/__init__.pyi +2753 -0
- metaflow-stubs/cards.pyi +266 -0
- metaflow-stubs/cli.pyi +137 -0
- metaflow-stubs/client/__init__.pyi +993 -0
- metaflow-stubs/client/core.pyi +1425 -0
- metaflow-stubs/client/filecache.pyi +87 -0
- metaflow-stubs/events.pyi +107 -0
- metaflow-stubs/exception.pyi +98 -0
- metaflow-stubs/flowspec.pyi +297 -0
- metaflow-stubs/generated_for.txt +1 -0
- metaflow-stubs/includefile.pyi +524 -0
- metaflow-stubs/metadata/metadata.pyi +377 -0
- metaflow-stubs/metadata/util.pyi +18 -0
- metaflow-stubs/metaflow_config.pyi +263 -0
- metaflow-stubs/metaflow_current.pyi +327 -0
- metaflow-stubs/mflog/mflog.pyi +22 -0
- metaflow-stubs/multicore_utils.pyi +62 -0
- metaflow-stubs/parameters.pyi +114 -0
- metaflow-stubs/plugins/__init__.pyi +209 -0
- metaflow-stubs/plugins/airflow/__init__.pyi +9 -0
- metaflow-stubs/plugins/airflow/airflow.pyi +179 -0
- metaflow-stubs/plugins/airflow/airflow_cli.pyi +90 -0
- metaflow-stubs/plugins/airflow/airflow_decorator.pyi +50 -0
- metaflow-stubs/plugins/airflow/airflow_utils.pyi +137 -0
- metaflow-stubs/plugins/airflow/exception.pyi +27 -0
- metaflow-stubs/plugins/airflow/sensors/__init__.pyi +26 -0
- metaflow-stubs/plugins/airflow/sensors/base_sensor.pyi +60 -0
- metaflow-stubs/plugins/airflow/sensors/external_task_sensor.pyi +54 -0
- metaflow-stubs/plugins/airflow/sensors/s3_sensor.pyi +50 -0
- metaflow-stubs/plugins/argo/__init__.pyi +9 -0
- metaflow-stubs/plugins/argo/argo_client.pyi +77 -0
- metaflow-stubs/plugins/argo/argo_events.pyi +79 -0
- metaflow-stubs/plugins/argo/argo_workflows.pyi +604 -0
- metaflow-stubs/plugins/argo/argo_workflows_cli.pyi +180 -0
- metaflow-stubs/plugins/argo/argo_workflows_decorator.pyi +169 -0
- metaflow-stubs/plugins/aws/__init__.pyi +9 -0
- metaflow-stubs/plugins/aws/aws_client.pyi +22 -0
- metaflow-stubs/plugins/aws/aws_utils.pyi +93 -0
- metaflow-stubs/plugins/aws/batch/__init__.pyi +9 -0
- metaflow-stubs/plugins/aws/batch/batch.pyi +120 -0
- metaflow-stubs/plugins/aws/batch/batch_cli.pyi +42 -0
- metaflow-stubs/plugins/aws/batch/batch_client.pyi +159 -0
- metaflow-stubs/plugins/aws/batch/batch_decorator.pyi +145 -0
- metaflow-stubs/plugins/aws/secrets_manager/__init__.pyi +9 -0
- metaflow-stubs/plugins/aws/secrets_manager/aws_secrets_manager_secrets_provider.pyi +73 -0
- metaflow-stubs/plugins/aws/step_functions/__init__.pyi +9 -0
- metaflow-stubs/plugins/aws/step_functions/dynamo_db_client.pyi +22 -0
- metaflow-stubs/plugins/aws/step_functions/event_bridge_client.pyi +27 -0
- metaflow-stubs/plugins/aws/step_functions/production_token.pyi +18 -0
- metaflow-stubs/plugins/aws/step_functions/schedule_decorator.pyi +17 -0
- metaflow-stubs/plugins/aws/step_functions/step_functions.pyi +220 -0
- metaflow-stubs/plugins/aws/step_functions/step_functions_cli.pyi +139 -0
- metaflow-stubs/plugins/aws/step_functions/step_functions_client.pyi +36 -0
- metaflow-stubs/plugins/aws/step_functions/step_functions_decorator.pyi +49 -0
- metaflow-stubs/plugins/azure/__init__.pyi +9 -0
- metaflow-stubs/plugins/azure/azure_credential.pyi +28 -0
- metaflow-stubs/plugins/azure/azure_exceptions.pyi +28 -0
- metaflow-stubs/plugins/azure/azure_utils.pyi +76 -0
- metaflow-stubs/plugins/azure/blob_service_client_factory.pyi +52 -0
- metaflow-stubs/plugins/azure/includefile_support.pyi +63 -0
- metaflow-stubs/plugins/cards/__init__.pyi +9 -0
- metaflow-stubs/plugins/cards/card_cli.pyi +557 -0
- metaflow-stubs/plugins/cards/card_client.pyi +178 -0
- metaflow-stubs/plugins/cards/card_creator.pyi +26 -0
- metaflow-stubs/plugins/cards/card_datastore.pyi +111 -0
- metaflow-stubs/plugins/cards/card_decorator.pyi +133 -0
- metaflow-stubs/plugins/cards/card_modules/__init__.pyi +67 -0
- metaflow-stubs/plugins/cards/card_modules/basic.pyi +263 -0
- metaflow-stubs/plugins/cards/card_modules/card.pyi +62 -0
- metaflow-stubs/plugins/cards/card_modules/chevron/__init__.pyi +78 -0
- metaflow-stubs/plugins/cards/card_modules/chevron/main.pyi +77 -0
- metaflow-stubs/plugins/cards/card_modules/chevron/metadata.pyi +11 -0
- metaflow-stubs/plugins/cards/card_modules/chevron/renderer.pyi +114 -0
- metaflow-stubs/plugins/cards/card_modules/chevron/tokenizer.pyi +75 -0
- metaflow-stubs/plugins/cards/card_modules/components.pyi +251 -0
- metaflow-stubs/plugins/cards/card_modules/convert_to_native_type.pyi +45 -0
- metaflow-stubs/plugins/cards/card_modules/renderer_tools.pyi +24 -0
- metaflow-stubs/plugins/cards/card_modules/test_cards.pyi +155 -0
- metaflow-stubs/plugins/cards/card_resolver.pyi +60 -0
- metaflow-stubs/plugins/cards/component_serializer.pyi +227 -0
- metaflow-stubs/plugins/cards/exception.pyi +71 -0
- metaflow-stubs/plugins/catch_decorator.pyi +58 -0
- metaflow-stubs/plugins/datatools/__init__.pyi +339 -0
- metaflow-stubs/plugins/datatools/local.pyi +82 -0
- metaflow-stubs/plugins/datatools/s3/__init__.pyi +589 -0
- metaflow-stubs/plugins/datatools/s3/s3.pyi +875 -0
- metaflow-stubs/plugins/datatools/s3/s3tail.pyi +34 -0
- metaflow-stubs/plugins/datatools/s3/s3util.pyi +45 -0
- metaflow-stubs/plugins/debug_logger.pyi +25 -0
- metaflow-stubs/plugins/debug_monitor.pyi +25 -0
- metaflow-stubs/plugins/environment_decorator.pyi +17 -0
- metaflow-stubs/plugins/events_decorator.pyi +34 -0
- metaflow-stubs/plugins/frameworks/__init__.pyi +9 -0
- metaflow-stubs/plugins/frameworks/pytorch.pyi +42 -0
- metaflow-stubs/plugins/gcp/__init__.pyi +9 -0
- metaflow-stubs/plugins/gcp/gs_exceptions.pyi +22 -0
- metaflow-stubs/plugins/gcp/gs_storage_client_factory.pyi +26 -0
- metaflow-stubs/plugins/gcp/gs_utils.pyi +38 -0
- metaflow-stubs/plugins/gcp/includefile_support.pyi +63 -0
- metaflow-stubs/plugins/kubernetes/__init__.pyi +9 -0
- metaflow-stubs/plugins/kubernetes/kubernetes.pyi +127 -0
- metaflow-stubs/plugins/kubernetes/kubernetes_cli.pyi +73 -0
- metaflow-stubs/plugins/kubernetes/kubernetes_client.pyi +62 -0
- metaflow-stubs/plugins/kubernetes/kubernetes_decorator.pyi +165 -0
- metaflow-stubs/plugins/kubernetes/kubernetes_job.pyi +100 -0
- metaflow-stubs/plugins/package_cli.pyi +9 -0
- metaflow-stubs/plugins/parallel_decorator.pyi +34 -0
- metaflow-stubs/plugins/project_decorator.pyi +36 -0
- metaflow-stubs/plugins/pypi/__init__.pyi +18 -0
- metaflow-stubs/plugins/pypi/conda_decorator.pyi +59 -0
- metaflow-stubs/plugins/pypi/conda_environment.pyi +86 -0
- metaflow-stubs/plugins/pypi/pypi_decorator.pyi +22 -0
- metaflow-stubs/plugins/pypi/pypi_environment.pyi +50 -0
- metaflow-stubs/plugins/pypi/utils.pyi +28 -0
- metaflow-stubs/plugins/resources_decorator.pyi +15 -0
- metaflow-stubs/plugins/retry_decorator.pyi +28 -0
- metaflow-stubs/plugins/secrets/__init__.pyi +21 -0
- metaflow-stubs/plugins/secrets/inline_secrets_provider.pyi +30 -0
- metaflow-stubs/plugins/secrets/secrets_decorator.pyi +75 -0
- metaflow-stubs/plugins/storage_executor.pyi +33 -0
- metaflow-stubs/plugins/tag_cli.pyi +370 -0
- metaflow-stubs/plugins/test_unbounded_foreach_decorator.pyi +54 -0
- metaflow-stubs/plugins/timeout_decorator.pyi +39 -0
- metaflow-stubs/procpoll.pyi +51 -0
- metaflow-stubs/py.typed +0 -0
- metaflow-stubs/pylint_wrapper.pyi +31 -0
- metaflow-stubs/tagging_util.pyi +52 -0
- ob_metaflow_stubs-2.11.4.1.dist-info/METADATA +22 -0
- ob_metaflow_stubs-2.11.4.1.dist-info/RECORD +131 -0
- ob_metaflow_stubs-2.11.4.1.dist-info/WHEEL +6 -0
- ob_metaflow_stubs-2.11.4.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,875 @@
|
|
1
|
+
##################################################################################
|
2
|
+
# Auto-generated Metaflow stub file #
|
3
|
+
# MF version: 2.11.4.1 #
|
4
|
+
# Generated on 2024-02-28T05:30:43.910901 #
|
5
|
+
##################################################################################
|
6
|
+
|
7
|
+
from __future__ import annotations
|
8
|
+
|
9
|
+
import typing
|
10
|
+
if typing.TYPE_CHECKING:
|
11
|
+
import metaflow.plugins.datatools.s3.s3
|
12
|
+
import metaflow.exception
|
13
|
+
import metaflow.metaflow_current
|
14
|
+
import io
|
15
|
+
import metaflow.datastore.inputs
|
16
|
+
import typing
|
17
|
+
|
18
|
+
TYPE_CHECKING: bool
|
19
|
+
|
20
|
+
class FlowSpec(object, metaclass=type):
|
21
|
+
def __init__(self, use_cli = True):
|
22
|
+
"""
|
23
|
+
Construct a FlowSpec
|
24
|
+
|
25
|
+
Parameters
|
26
|
+
----------
|
27
|
+
use_cli : bool, default True
|
28
|
+
Set to True if the flow is invoked from __main__ or the command line
|
29
|
+
"""
|
30
|
+
...
|
31
|
+
@property
|
32
|
+
def script_name(self) -> str:
|
33
|
+
"""
|
34
|
+
[Legacy function - do not use. Use `current` instead]
|
35
|
+
|
36
|
+
Returns the name of the script containing the flow
|
37
|
+
|
38
|
+
Returns
|
39
|
+
-------
|
40
|
+
str
|
41
|
+
A string containing the name of the script
|
42
|
+
"""
|
43
|
+
...
|
44
|
+
def __iter__(self):
|
45
|
+
"""
|
46
|
+
[Legacy function - do not use]
|
47
|
+
|
48
|
+
Iterate over all steps in the Flow
|
49
|
+
|
50
|
+
Returns
|
51
|
+
-------
|
52
|
+
Iterator[graph.DAGNode]
|
53
|
+
Iterator over the steps in the flow
|
54
|
+
"""
|
55
|
+
...
|
56
|
+
def __getattr__(self, name: str):
|
57
|
+
...
|
58
|
+
def cmd(self, cmdline, input = {}, output = []):
|
59
|
+
"""
|
60
|
+
[Legacy function - do not use]
|
61
|
+
"""
|
62
|
+
...
|
63
|
+
@property
|
64
|
+
def index(self) -> typing.Optional[int]:
|
65
|
+
"""
|
66
|
+
The index of this foreach branch.
|
67
|
+
|
68
|
+
In a foreach step, multiple instances of this step (tasks) will be executed,
|
69
|
+
one for each element in the foreach. This property returns the zero based index
|
70
|
+
of the current task. If this is not a foreach step, this returns None.
|
71
|
+
|
72
|
+
If you need to know the indices of the parent tasks in a nested foreach, use
|
73
|
+
`FlowSpec.foreach_stack`.
|
74
|
+
|
75
|
+
Returns
|
76
|
+
-------
|
77
|
+
int, optional
|
78
|
+
Index of the task in a foreach step.
|
79
|
+
"""
|
80
|
+
...
|
81
|
+
@property
|
82
|
+
def input(self) -> typing.Optional[typing.Any]:
|
83
|
+
"""
|
84
|
+
The value of the foreach artifact in this foreach branch.
|
85
|
+
|
86
|
+
In a foreach step, multiple instances of this step (tasks) will be executed,
|
87
|
+
one for each element in the foreach. This property returns the element passed
|
88
|
+
to the current task. If this is not a foreach step, this returns None.
|
89
|
+
|
90
|
+
If you need to know the values of the parent tasks in a nested foreach, use
|
91
|
+
`FlowSpec.foreach_stack`.
|
92
|
+
|
93
|
+
Returns
|
94
|
+
-------
|
95
|
+
object, optional
|
96
|
+
Input passed to the foreach task.
|
97
|
+
"""
|
98
|
+
...
|
99
|
+
def foreach_stack(self) -> typing.Optional[typing.List[typing.Tuple[int, int, typing.Any]]]:
|
100
|
+
"""
|
101
|
+
Returns the current stack of foreach indexes and values for the current step.
|
102
|
+
|
103
|
+
Use this information to understand what data is being processed in the current
|
104
|
+
foreach branch. For example, considering the following code:
|
105
|
+
```
|
106
|
+
@step
|
107
|
+
def root(self):
|
108
|
+
self.split_1 = ['a', 'b', 'c']
|
109
|
+
self.next(self.nest_1, foreach='split_1')
|
110
|
+
|
111
|
+
@step
|
112
|
+
def nest_1(self):
|
113
|
+
self.split_2 = ['d', 'e', 'f', 'g']
|
114
|
+
self.next(self.nest_2, foreach='split_2'):
|
115
|
+
|
116
|
+
@step
|
117
|
+
def nest_2(self):
|
118
|
+
foo = self.foreach_stack()
|
119
|
+
```
|
120
|
+
|
121
|
+
`foo` will take the following values in the various tasks for nest_2:
|
122
|
+
```
|
123
|
+
[(0, 3, 'a'), (0, 4, 'd')]
|
124
|
+
[(0, 3, 'a'), (1, 4, 'e')]
|
125
|
+
...
|
126
|
+
[(0, 3, 'a'), (3, 4, 'g')]
|
127
|
+
[(1, 3, 'b'), (0, 4, 'd')]
|
128
|
+
...
|
129
|
+
```
|
130
|
+
where each tuple corresponds to:
|
131
|
+
|
132
|
+
- The index of the task for that level of the loop.
|
133
|
+
- The number of splits for that level of the loop.
|
134
|
+
- The value for that level of the loop.
|
135
|
+
|
136
|
+
Note that the last tuple returned in a task corresponds to:
|
137
|
+
|
138
|
+
- 1st element: value returned by `self.index`.
|
139
|
+
- 3rd element: value returned by `self.input`.
|
140
|
+
|
141
|
+
Returns
|
142
|
+
-------
|
143
|
+
List[Tuple[int, int, Any]]
|
144
|
+
An array describing the current stack of foreach steps.
|
145
|
+
"""
|
146
|
+
...
|
147
|
+
def merge_artifacts(self, inputs: metaflow.datastore.inputs.Inputs, exclude: typing.Optional[typing.List[str]] = None, include: typing.Optional[typing.List[str]] = None):
|
148
|
+
"""
|
149
|
+
Helper function for merging artifacts in a join step.
|
150
|
+
|
151
|
+
This function takes all the artifacts coming from the branches of a
|
152
|
+
join point and assigns them to self in the calling step. Only artifacts
|
153
|
+
not set in the current step are considered. If, for a given artifact, different
|
154
|
+
values are present on the incoming edges, an error will be thrown and the artifacts
|
155
|
+
that conflict will be reported.
|
156
|
+
|
157
|
+
As a few examples, in the simple graph: A splitting into B and C and joining in D:
|
158
|
+
```
|
159
|
+
A:
|
160
|
+
self.x = 5
|
161
|
+
self.y = 6
|
162
|
+
B:
|
163
|
+
self.b_var = 1
|
164
|
+
self.x = from_b
|
165
|
+
C:
|
166
|
+
self.x = from_c
|
167
|
+
|
168
|
+
D:
|
169
|
+
merge_artifacts(inputs)
|
170
|
+
```
|
171
|
+
In D, the following artifacts are set:
|
172
|
+
- `y` (value: 6), `b_var` (value: 1)
|
173
|
+
- if `from_b` and `from_c` are the same, `x` will be accessible and have value `from_b`
|
174
|
+
- if `from_b` and `from_c` are different, an error will be thrown. To prevent this error,
|
175
|
+
you need to manually set `self.x` in D to a merged value (for example the max) prior to
|
176
|
+
calling `merge_artifacts`.
|
177
|
+
|
178
|
+
Parameters
|
179
|
+
----------
|
180
|
+
inputs : Inputs
|
181
|
+
Incoming steps to the join point.
|
182
|
+
exclude : List[str], optional, default None
|
183
|
+
If specified, do not consider merging artifacts with a name in `exclude`.
|
184
|
+
Cannot specify if `include` is also specified.
|
185
|
+
include : List[str], optional, default None
|
186
|
+
If specified, only merge artifacts specified. Cannot specify if `exclude` is
|
187
|
+
also specified.
|
188
|
+
|
189
|
+
Raises
|
190
|
+
------
|
191
|
+
MetaflowException
|
192
|
+
This exception is thrown if this is not called in a join step.
|
193
|
+
UnhandledInMergeArtifactsException
|
194
|
+
This exception is thrown in case of unresolved conflicts.
|
195
|
+
MissingInMergeArtifactsException
|
196
|
+
This exception is thrown in case an artifact specified in `include` cannot
|
197
|
+
be found.
|
198
|
+
"""
|
199
|
+
...
|
200
|
+
def next(self, *dsts: typing.Callable[..., None], **kwargs):
|
201
|
+
"""
|
202
|
+
Indicates the next step to execute after this step has completed.
|
203
|
+
|
204
|
+
This statement should appear as the last statement of each step, except
|
205
|
+
the end step.
|
206
|
+
|
207
|
+
There are several valid formats to specify the next step:
|
208
|
+
|
209
|
+
- Straight-line connection: `self.next(self.next_step)` where `next_step` is a method in
|
210
|
+
the current class decorated with the `@step` decorator.
|
211
|
+
|
212
|
+
- Static fan-out connection: `self.next(self.step1, self.step2, ...)` where `stepX` are
|
213
|
+
methods in the current class decorated with the `@step` decorator.
|
214
|
+
|
215
|
+
- Foreach branch:
|
216
|
+
```
|
217
|
+
self.next(self.foreach_step, foreach='foreach_iterator')
|
218
|
+
```
|
219
|
+
In this situation, `foreach_step` is a method in the current class decorated with the
|
220
|
+
`@step` decorator and `foreach_iterator` is a variable name in the current class that
|
221
|
+
evaluates to an iterator. A task will be launched for each value in the iterator and
|
222
|
+
each task will execute the code specified by the step `foreach_step`.
|
223
|
+
|
224
|
+
Parameters
|
225
|
+
----------
|
226
|
+
dsts : Callable[..., None]
|
227
|
+
One or more methods annotated with `@step`.
|
228
|
+
|
229
|
+
Raises
|
230
|
+
------
|
231
|
+
InvalidNextException
|
232
|
+
Raised if the format of the arguments does not match one of the ones given above.
|
233
|
+
"""
|
234
|
+
...
|
235
|
+
def __str__(self):
|
236
|
+
...
|
237
|
+
def __getstate__(self):
|
238
|
+
...
|
239
|
+
...
|
240
|
+
|
241
|
+
current: metaflow.metaflow_current.Current
|
242
|
+
|
243
|
+
DATATOOLS_S3ROOT: None
|
244
|
+
|
245
|
+
S3_RETRY_COUNT: int
|
246
|
+
|
247
|
+
S3_TRANSIENT_RETRY_COUNT: int
|
248
|
+
|
249
|
+
S3_SERVER_SIDE_ENCRYPTION: None
|
250
|
+
|
251
|
+
TEMPDIR: str
|
252
|
+
|
253
|
+
class MetaflowException(Exception, metaclass=type):
|
254
|
+
def __init__(self, msg = "", lineno = None):
|
255
|
+
...
|
256
|
+
def __str__(self):
|
257
|
+
...
|
258
|
+
...
|
259
|
+
|
260
|
+
def get_s3_client(s3_role_arn = None, s3_session_vars = None, s3_client_params = None):
|
261
|
+
...
|
262
|
+
|
263
|
+
def read_in_chunks(dst, src, src_sz, max_chunk_size):
|
264
|
+
...
|
265
|
+
|
266
|
+
def get_timestamp(dt):
|
267
|
+
"""
|
268
|
+
Python2 compatible way to compute the timestamp (seconds since 1/1/1970)
|
269
|
+
"""
|
270
|
+
...
|
271
|
+
|
272
|
+
TRANSIENT_RETRY_START_LINE: str
|
273
|
+
|
274
|
+
TRANSIENT_RETRY_LINE_CONTENT: str
|
275
|
+
|
276
|
+
def check_s3_deps(func):
|
277
|
+
"""
|
278
|
+
The decorated function checks S3 dependencies (as needed for AWS S3 storage backend).
|
279
|
+
This includes boto3.
|
280
|
+
"""
|
281
|
+
...
|
282
|
+
|
283
|
+
TEST_INJECT_RETRYABLE_FAILURES: int
|
284
|
+
|
285
|
+
def ensure_unicode(x):
|
286
|
+
...
|
287
|
+
|
288
|
+
class S3GetObject(tuple, metaclass=type):
|
289
|
+
@staticmethod
|
290
|
+
def __new__(_cls, key: str, offset: int, length: int):
|
291
|
+
"""
|
292
|
+
Create new instance of S3GetObject(key, offset, length)
|
293
|
+
"""
|
294
|
+
...
|
295
|
+
def __repr__(self):
|
296
|
+
"""
|
297
|
+
Return a nicely formatted representation string
|
298
|
+
"""
|
299
|
+
...
|
300
|
+
def __getnewargs__(self):
|
301
|
+
"""
|
302
|
+
Return self as a plain tuple. Used by copy and pickle.
|
303
|
+
"""
|
304
|
+
...
|
305
|
+
def __init__(self, key: str, offset: int, length: int):
|
306
|
+
...
|
307
|
+
...
|
308
|
+
|
309
|
+
class S3PutObject(tuple, metaclass=type):
|
310
|
+
@staticmethod
|
311
|
+
def __new__(_cls, key: str, value: typing.Union[io.RawIOBase, io.BufferedIOBase, str, bytes, None] = None, path: typing.Optional[str] = None, content_type: typing.Optional[str] = None, encryption: typing.Optional[str] = None, metadata: typing.Optional[typing.Dict[str, str]] = None):
|
312
|
+
"""
|
313
|
+
Create new instance of S3PutObject(key, value, path, content_type, encryption, metadata)
|
314
|
+
"""
|
315
|
+
...
|
316
|
+
def __repr__(self):
|
317
|
+
"""
|
318
|
+
Return a nicely formatted representation string
|
319
|
+
"""
|
320
|
+
...
|
321
|
+
def __getnewargs__(self):
|
322
|
+
"""
|
323
|
+
Return self as a plain tuple. Used by copy and pickle.
|
324
|
+
"""
|
325
|
+
...
|
326
|
+
def __init__(self, key: str, value: typing.Union[io.RawIOBase, io.BufferedIOBase, str, bytes, None], path: typing.Optional[str], content_type: typing.Optional[str], encryption: typing.Optional[str], metadata: typing.Optional[typing.Dict[str, str]]):
|
327
|
+
...
|
328
|
+
...
|
329
|
+
|
330
|
+
class RangeInfo(tuple, metaclass=type):
|
331
|
+
@staticmethod
|
332
|
+
def __new__(_cls, total_size: int, request_offset: int = 0, request_length: int = -1):
|
333
|
+
"""
|
334
|
+
Create new instance of RangeInfo(total_size, request_offset, request_length)
|
335
|
+
"""
|
336
|
+
...
|
337
|
+
def __repr__(self):
|
338
|
+
"""
|
339
|
+
Return a nicely formatted representation string
|
340
|
+
"""
|
341
|
+
...
|
342
|
+
def __getnewargs__(self):
|
343
|
+
"""
|
344
|
+
Return self as a plain tuple. Used by copy and pickle.
|
345
|
+
"""
|
346
|
+
...
|
347
|
+
def __init__(self, total_size: int, request_offset: int, request_length: int):
|
348
|
+
...
|
349
|
+
...
|
350
|
+
|
351
|
+
class MetaflowS3InvalidObject(metaflow.exception.MetaflowException, metaclass=type):
|
352
|
+
...
|
353
|
+
|
354
|
+
class MetaflowS3URLException(metaflow.exception.MetaflowException, metaclass=type):
|
355
|
+
...
|
356
|
+
|
357
|
+
class MetaflowS3Exception(metaflow.exception.MetaflowException, metaclass=type):
|
358
|
+
...
|
359
|
+
|
360
|
+
class MetaflowS3NotFound(metaflow.exception.MetaflowException, metaclass=type):
|
361
|
+
...
|
362
|
+
|
363
|
+
class MetaflowS3AccessDenied(metaflow.exception.MetaflowException, metaclass=type):
|
364
|
+
...
|
365
|
+
|
366
|
+
class MetaflowS3InvalidRange(metaflow.exception.MetaflowException, metaclass=type):
|
367
|
+
...
|
368
|
+
|
369
|
+
class S3Object(object, metaclass=type):
|
370
|
+
def __init__(self, prefix: str, url: str, path: str, size: typing.Optional[int] = None, content_type: typing.Optional[str] = None, metadata: typing.Optional[typing.Dict[str, str]] = None, range_info: typing.Optional[RangeInfo] = None, last_modified: typing.Optional[int] = None, encryption: typing.Optional[str] = None):
|
371
|
+
...
|
372
|
+
@property
|
373
|
+
def exists(self) -> bool:
|
374
|
+
"""
|
375
|
+
Does this key correspond to an object in S3?
|
376
|
+
|
377
|
+
Returns
|
378
|
+
-------
|
379
|
+
bool
|
380
|
+
True if this object points at an existing object (file) in S3.
|
381
|
+
"""
|
382
|
+
...
|
383
|
+
@property
|
384
|
+
def downloaded(self) -> bool:
|
385
|
+
"""
|
386
|
+
Has this object been downloaded?
|
387
|
+
|
388
|
+
If True, the contents can be accessed through `path`, `blob`,
|
389
|
+
and `text` properties.
|
390
|
+
|
391
|
+
Returns
|
392
|
+
-------
|
393
|
+
bool
|
394
|
+
True if the contents of this object have been downloaded.
|
395
|
+
"""
|
396
|
+
...
|
397
|
+
@property
|
398
|
+
def url(self) -> str:
|
399
|
+
"""
|
400
|
+
S3 location of the object
|
401
|
+
|
402
|
+
Returns
|
403
|
+
-------
|
404
|
+
str
|
405
|
+
The S3 location of this object.
|
406
|
+
"""
|
407
|
+
...
|
408
|
+
@property
|
409
|
+
def prefix(self) -> str:
|
410
|
+
"""
|
411
|
+
Prefix requested that matches this object.
|
412
|
+
|
413
|
+
Returns
|
414
|
+
-------
|
415
|
+
str
|
416
|
+
Requested prefix
|
417
|
+
"""
|
418
|
+
...
|
419
|
+
@property
|
420
|
+
def key(self) -> str:
|
421
|
+
"""
|
422
|
+
Key corresponds to the key given to the get call that produced
|
423
|
+
this object.
|
424
|
+
|
425
|
+
This may be a full S3 URL or a suffix based on what
|
426
|
+
was requested.
|
427
|
+
|
428
|
+
Returns
|
429
|
+
-------
|
430
|
+
str
|
431
|
+
Key requested.
|
432
|
+
"""
|
433
|
+
...
|
434
|
+
@property
|
435
|
+
def path(self) -> typing.Optional[str]:
|
436
|
+
"""
|
437
|
+
Path to a local temporary file corresponding to the object downloaded.
|
438
|
+
|
439
|
+
This file gets deleted automatically when a S3 scope exits.
|
440
|
+
Returns None if this S3Object has not been downloaded.
|
441
|
+
|
442
|
+
Returns
|
443
|
+
-------
|
444
|
+
str
|
445
|
+
Local path, if the object has been downloaded.
|
446
|
+
"""
|
447
|
+
...
|
448
|
+
@property
|
449
|
+
def blob(self) -> typing.Optional[bytes]:
|
450
|
+
"""
|
451
|
+
Contents of the object as a byte string or None if the
|
452
|
+
object hasn't been downloaded.
|
453
|
+
|
454
|
+
Returns
|
455
|
+
-------
|
456
|
+
bytes
|
457
|
+
Contents of the object as bytes.
|
458
|
+
"""
|
459
|
+
...
|
460
|
+
@property
|
461
|
+
def text(self) -> typing.Optional[str]:
|
462
|
+
"""
|
463
|
+
Contents of the object as a string or None if the
|
464
|
+
object hasn't been downloaded.
|
465
|
+
|
466
|
+
The object is assumed to contain UTF-8 encoded data.
|
467
|
+
|
468
|
+
Returns
|
469
|
+
-------
|
470
|
+
str
|
471
|
+
Contents of the object as text.
|
472
|
+
"""
|
473
|
+
...
|
474
|
+
@property
|
475
|
+
def size(self) -> typing.Optional[int]:
|
476
|
+
"""
|
477
|
+
Size of the object in bytes.
|
478
|
+
|
479
|
+
Returns None if the key does not correspond to an object in S3.
|
480
|
+
|
481
|
+
Returns
|
482
|
+
-------
|
483
|
+
int
|
484
|
+
Size of the object in bytes, if the object exists.
|
485
|
+
"""
|
486
|
+
...
|
487
|
+
@property
|
488
|
+
def has_info(self) -> bool:
|
489
|
+
"""
|
490
|
+
Returns true if this `S3Object` contains the content-type MIME header or
|
491
|
+
user-defined metadata.
|
492
|
+
|
493
|
+
If False, this means that `content_type`, `metadata`, `range_info` and
|
494
|
+
`last_modified` will return None.
|
495
|
+
|
496
|
+
Returns
|
497
|
+
-------
|
498
|
+
bool
|
499
|
+
True if additional metadata is available.
|
500
|
+
"""
|
501
|
+
...
|
502
|
+
@property
|
503
|
+
def metadata(self) -> typing.Optional[typing.Dict[str, str]]:
|
504
|
+
"""
|
505
|
+
Returns a dictionary of user-defined metadata, or None if no metadata
|
506
|
+
is defined.
|
507
|
+
|
508
|
+
Returns
|
509
|
+
-------
|
510
|
+
Dict
|
511
|
+
User-defined metadata.
|
512
|
+
"""
|
513
|
+
...
|
514
|
+
@property
|
515
|
+
def content_type(self) -> typing.Optional[str]:
|
516
|
+
"""
|
517
|
+
Returns the content-type of the S3 object or None if it is not defined.
|
518
|
+
|
519
|
+
Returns
|
520
|
+
-------
|
521
|
+
str
|
522
|
+
Content type or None if the content type is undefined.
|
523
|
+
"""
|
524
|
+
...
|
525
|
+
@property
|
526
|
+
def encryption(self) -> typing.Optional[str]:
|
527
|
+
"""
|
528
|
+
Returns the encryption type of the S3 object or None if it is not defined.
|
529
|
+
|
530
|
+
Returns
|
531
|
+
-------
|
532
|
+
str
|
533
|
+
Server-side-encryption type or None if parameter is not set.
|
534
|
+
"""
|
535
|
+
...
|
536
|
+
@property
|
537
|
+
def range_info(self) -> typing.Optional[RangeInfo]:
|
538
|
+
"""
|
539
|
+
If the object corresponds to a partially downloaded object, returns
|
540
|
+
information of what was downloaded.
|
541
|
+
|
542
|
+
The returned object has the following fields:
|
543
|
+
- `total_size`: Size of the object in S3.
|
544
|
+
- `request_offset`: The starting offset.
|
545
|
+
- `request_length`: The number of bytes downloaded.
|
546
|
+
|
547
|
+
Returns
|
548
|
+
-------
|
549
|
+
namedtuple
|
550
|
+
An object containing information about the partial download. If
|
551
|
+
the `S3Object` doesn't correspond to a partially downloaded file,
|
552
|
+
returns None.
|
553
|
+
"""
|
554
|
+
...
|
555
|
+
@property
|
556
|
+
def last_modified(self) -> typing.Optional[int]:
|
557
|
+
"""
|
558
|
+
Returns the last modified unix timestamp of the object.
|
559
|
+
|
560
|
+
Returns
|
561
|
+
-------
|
562
|
+
int
|
563
|
+
Unix timestamp corresponding to the last modified time.
|
564
|
+
"""
|
565
|
+
...
|
566
|
+
def __str__(self):
|
567
|
+
...
|
568
|
+
def __repr__(self):
|
569
|
+
...
|
570
|
+
...
|
571
|
+
|
572
|
+
class S3Client(object, metaclass=type):
|
573
|
+
def __init__(self, s3_role_arn = None, s3_session_vars = None, s3_client_params = None):
|
574
|
+
...
|
575
|
+
@property
|
576
|
+
def client(self):
|
577
|
+
...
|
578
|
+
@property
|
579
|
+
def error(self):
|
580
|
+
...
|
581
|
+
def reset_client(self):
|
582
|
+
...
|
583
|
+
...
|
584
|
+
|
585
|
+
class S3(object, metaclass=type):
|
586
|
+
@classmethod
|
587
|
+
def get_root_from_config(cls, echo, create_on_absent = True):
|
588
|
+
...
|
589
|
+
def __enter__(self) -> S3:
|
590
|
+
...
|
591
|
+
def __exit__(self, *args):
|
592
|
+
...
|
593
|
+
def close(self):
|
594
|
+
"""
|
595
|
+
Delete all temporary files downloaded in this context.
|
596
|
+
"""
|
597
|
+
...
|
598
|
+
def list_paths(self, keys: typing.Optional[typing.Iterable[str]] = None) -> typing.List[S3Object]:
|
599
|
+
"""
|
600
|
+
List the next level of paths in S3.
|
601
|
+
|
602
|
+
If multiple keys are specified, listings are done in parallel. The returned
|
603
|
+
S3Objects have `.exists == False` if the path refers to a prefix, not an
|
604
|
+
existing S3 object.
|
605
|
+
|
606
|
+
For instance, if the directory hierarchy is
|
607
|
+
```
|
608
|
+
a/0.txt
|
609
|
+
a/b/1.txt
|
610
|
+
a/c/2.txt
|
611
|
+
a/d/e/3.txt
|
612
|
+
f/4.txt
|
613
|
+
```
|
614
|
+
The `list_paths(['a', 'f'])` call returns
|
615
|
+
```
|
616
|
+
a/0.txt (exists == True)
|
617
|
+
a/b/ (exists == False)
|
618
|
+
a/c/ (exists == False)
|
619
|
+
a/d/ (exists == False)
|
620
|
+
f/4.txt (exists == True)
|
621
|
+
```
|
622
|
+
|
623
|
+
Parameters
|
624
|
+
----------
|
625
|
+
keys : Iterable[str], optional, default None
|
626
|
+
List of paths.
|
627
|
+
|
628
|
+
Returns
|
629
|
+
-------
|
630
|
+
List[S3Object]
|
631
|
+
S3Objects under the given paths, including prefixes (directories) that
|
632
|
+
do not correspond to leaf objects.
|
633
|
+
"""
|
634
|
+
...
|
635
|
+
def list_recursive(self, keys: typing.Optional[typing.Iterable[str]] = None) -> typing.List[S3Object]:
|
636
|
+
"""
|
637
|
+
List all objects recursively under the given prefixes.
|
638
|
+
|
639
|
+
If multiple keys are specified, listings are done in parallel. All objects
|
640
|
+
returned have `.exists == True` as this call always returns leaf objects.
|
641
|
+
|
642
|
+
For instance, if the directory hierarchy is
|
643
|
+
```
|
644
|
+
a/0.txt
|
645
|
+
a/b/1.txt
|
646
|
+
a/c/2.txt
|
647
|
+
a/d/e/3.txt
|
648
|
+
f/4.txt
|
649
|
+
```
|
650
|
+
The `list_paths(['a', 'f'])` call returns
|
651
|
+
```
|
652
|
+
a/0.txt (exists == True)
|
653
|
+
a/b/1.txt (exists == True)
|
654
|
+
a/c/2.txt (exists == True)
|
655
|
+
a/d/e/3.txt (exists == True)
|
656
|
+
f/4.txt (exists == True)
|
657
|
+
```
|
658
|
+
|
659
|
+
Parameters
|
660
|
+
----------
|
661
|
+
keys : Iterable[str], optional, default None
|
662
|
+
List of paths.
|
663
|
+
|
664
|
+
Returns
|
665
|
+
-------
|
666
|
+
List[S3Object]
|
667
|
+
S3Objects under the given paths.
|
668
|
+
"""
|
669
|
+
...
|
670
|
+
def info(self, key: typing.Optional[str] = None, return_missing: bool = False) -> S3Object:
|
671
|
+
"""
|
672
|
+
Get metadata about a single object in S3.
|
673
|
+
|
674
|
+
This call makes a single `HEAD` request to S3 which can be
|
675
|
+
much faster than downloading all data with `get`.
|
676
|
+
|
677
|
+
Parameters
|
678
|
+
----------
|
679
|
+
key : str, optional, default None
|
680
|
+
Object to query. It can be an S3 url or a path suffix.
|
681
|
+
return_missing : bool, default False
|
682
|
+
If set to True, do not raise an exception for a missing key but
|
683
|
+
return it as an `S3Object` with `.exists == False`.
|
684
|
+
|
685
|
+
Returns
|
686
|
+
-------
|
687
|
+
S3Object
|
688
|
+
An S3Object corresponding to the object requested. The object
|
689
|
+
will have `.downloaded == False`.
|
690
|
+
"""
|
691
|
+
...
|
692
|
+
def info_many(self, keys: typing.Iterable[str], return_missing: bool = False) -> typing.List[S3Object]:
|
693
|
+
"""
|
694
|
+
Get metadata about many objects in S3 in parallel.
|
695
|
+
|
696
|
+
This call makes a single `HEAD` request to S3 which can be
|
697
|
+
much faster than downloading all data with `get`.
|
698
|
+
|
699
|
+
Parameters
|
700
|
+
----------
|
701
|
+
keys : Iterable[str]
|
702
|
+
Objects to query. Each key can be an S3 url or a path suffix.
|
703
|
+
return_missing : bool, default False
|
704
|
+
If set to True, do not raise an exception for a missing key but
|
705
|
+
return it as an `S3Object` with `.exists == False`.
|
706
|
+
|
707
|
+
Returns
|
708
|
+
-------
|
709
|
+
List[S3Object]
|
710
|
+
A list of S3Objects corresponding to the paths requested. The
|
711
|
+
objects will have `.downloaded == False`.
|
712
|
+
"""
|
713
|
+
...
|
714
|
+
def get(self, key: typing.Union[str, S3GetObject, None] = None, return_missing: bool = False, return_info: bool = True) -> S3Object:
|
715
|
+
"""
|
716
|
+
Get a single object from S3.
|
717
|
+
|
718
|
+
Parameters
|
719
|
+
----------
|
720
|
+
key : Union[str, S3GetObject], optional, default None
|
721
|
+
Object to download. It can be an S3 url, a path suffix, or
|
722
|
+
an S3GetObject that defines a range of data to download. If None, or
|
723
|
+
not provided, gets the S3 root.
|
724
|
+
return_missing : bool, default False
|
725
|
+
If set to True, do not raise an exception for a missing key but
|
726
|
+
return it as an `S3Object` with `.exists == False`.
|
727
|
+
return_info : bool, default True
|
728
|
+
If set to True, fetch the content-type and user metadata associated
|
729
|
+
with the object at no extra cost, included for symmetry with `get_many`
|
730
|
+
|
731
|
+
Returns
|
732
|
+
-------
|
733
|
+
S3Object
|
734
|
+
An S3Object corresponding to the object requested.
|
735
|
+
"""
|
736
|
+
...
|
737
|
+
def get_many(self, keys: typing.Iterable[typing.Union[str, S3GetObject]], return_missing: bool = False, return_info: bool = True) -> typing.List[S3Object]:
|
738
|
+
"""
|
739
|
+
Get many objects from S3 in parallel.
|
740
|
+
|
741
|
+
Parameters
|
742
|
+
----------
|
743
|
+
keys : Iterable[Union[str, S3GetObject]]
|
744
|
+
Objects to download. Each object can be an S3 url, a path suffix, or
|
745
|
+
an S3GetObject that defines a range of data to download.
|
746
|
+
return_missing : bool, default False
|
747
|
+
If set to True, do not raise an exception for a missing key but
|
748
|
+
return it as an `S3Object` with `.exists == False`.
|
749
|
+
return_info : bool, default True
|
750
|
+
If set to True, fetch the content-type and user metadata associated
|
751
|
+
with the object at no extra cost, included for symmetry with `get_many`.
|
752
|
+
|
753
|
+
Returns
|
754
|
+
-------
|
755
|
+
List[S3Object]
|
756
|
+
S3Objects corresponding to the objects requested.
|
757
|
+
"""
|
758
|
+
...
|
759
|
+
def get_recursive(self, keys: typing.Iterable[str], return_info: bool = False) -> typing.List[S3Object]:
|
760
|
+
"""
|
761
|
+
Get many objects from S3 recursively in parallel.
|
762
|
+
|
763
|
+
Parameters
|
764
|
+
----------
|
765
|
+
keys : Iterable[str]
|
766
|
+
Prefixes to download recursively. Each prefix can be an S3 url or a path suffix
|
767
|
+
which define the root prefix under which all objects are downloaded.
|
768
|
+
return_info : bool, default False
|
769
|
+
If set to True, fetch the content-type and user metadata associated
|
770
|
+
with the object.
|
771
|
+
|
772
|
+
Returns
|
773
|
+
-------
|
774
|
+
List[S3Object]
|
775
|
+
S3Objects stored under the given prefixes.
|
776
|
+
"""
|
777
|
+
...
|
778
|
+
def get_all(self, return_info: bool = False) -> typing.List[S3Object]:
|
779
|
+
"""
|
780
|
+
Get all objects under the prefix set in the `S3` constructor.
|
781
|
+
|
782
|
+
This method requires that the `S3` object is initialized either with `run` or
|
783
|
+
`s3root`.
|
784
|
+
|
785
|
+
Parameters
|
786
|
+
----------
|
787
|
+
return_info : bool, default False
|
788
|
+
If set to True, fetch the content-type and user metadata associated
|
789
|
+
with the object.
|
790
|
+
|
791
|
+
Returns
|
792
|
+
-------
|
793
|
+
Iterable[S3Object]
|
794
|
+
S3Objects stored under the main prefix.
|
795
|
+
"""
|
796
|
+
...
|
797
|
+
def put(self, key: typing.Union[str, S3PutObject], obj: typing.Union[io.RawIOBase, io.BufferedIOBase, str, bytes], overwrite: bool = True, content_type: typing.Optional[str] = None, metadata: typing.Optional[typing.Dict[str, str]] = None) -> str:
|
798
|
+
"""
|
799
|
+
Upload a single object to S3.
|
800
|
+
|
801
|
+
Parameters
|
802
|
+
----------
|
803
|
+
key : Union[str, S3PutObject]
|
804
|
+
Object path. It can be an S3 url or a path suffix.
|
805
|
+
obj : PutValue
|
806
|
+
An object to store in S3. Strings are converted to UTF-8 encoding.
|
807
|
+
overwrite : bool, default True
|
808
|
+
Overwrite the object if it exists. If set to False, the operation
|
809
|
+
succeeds without uploading anything if the key already exists.
|
810
|
+
content_type : str, optional, default None
|
811
|
+
Optional MIME type for the object.
|
812
|
+
metadata : Dict[str, str], optional, default None
|
813
|
+
A JSON-encodable dictionary of additional headers to be stored
|
814
|
+
as metadata with the object.
|
815
|
+
|
816
|
+
Returns
|
817
|
+
-------
|
818
|
+
str
|
819
|
+
URL of the object stored.
|
820
|
+
"""
|
821
|
+
...
|
822
|
+
def put_many(self, key_objs: typing.List[typing.Union[typing.Tuple[str, typing.Union[io.RawIOBase, io.BufferedIOBase, str, bytes]], S3PutObject]], overwrite: bool = True) -> typing.List[typing.Tuple[str, str]]:
|
823
|
+
"""
|
824
|
+
Upload many objects to S3.
|
825
|
+
|
826
|
+
Each object to be uploaded can be specified in two ways:
|
827
|
+
|
828
|
+
1. As a `(key, obj)` tuple where `key` is a string specifying
|
829
|
+
the path and `obj` is a string or a bytes object.
|
830
|
+
|
831
|
+
2. As a `S3PutObject` which contains additional metadata to be
|
832
|
+
stored with the object.
|
833
|
+
|
834
|
+
Parameters
|
835
|
+
----------
|
836
|
+
key_objs : List[Union[Tuple[str, PutValue], S3PutObject]]
|
837
|
+
List of key-object pairs to upload.
|
838
|
+
overwrite : bool, default True
|
839
|
+
Overwrite the object if it exists. If set to False, the operation
|
840
|
+
succeeds without uploading anything if the key already exists.
|
841
|
+
|
842
|
+
Returns
|
843
|
+
-------
|
844
|
+
List[Tuple[str, str]]
|
845
|
+
List of `(key, url)` pairs corresponding to the objects uploaded.
|
846
|
+
"""
|
847
|
+
...
|
848
|
+
def put_files(self, key_paths: typing.List[typing.Union[typing.Tuple[str, typing.Union[io.RawIOBase, io.BufferedIOBase, str, bytes]], S3PutObject]], overwrite: bool = True) -> typing.List[typing.Tuple[str, str]]:
|
849
|
+
"""
|
850
|
+
Upload many local files to S3.
|
851
|
+
|
852
|
+
Each file to be uploaded can be specified in two ways:
|
853
|
+
|
854
|
+
1. As a `(key, path)` tuple where `key` is a string specifying
|
855
|
+
the S3 path and `path` is the path to a local file.
|
856
|
+
|
857
|
+
2. As a `S3PutObject` which contains additional metadata to be
|
858
|
+
stored with the file.
|
859
|
+
|
860
|
+
Parameters
|
861
|
+
----------
|
862
|
+
key_paths : List[Union[Tuple[str, PutValue], S3PutObject]]
|
863
|
+
List of files to upload.
|
864
|
+
overwrite : bool, default True
|
865
|
+
Overwrite the object if it exists. If set to False, the operation
|
866
|
+
succeeds without uploading anything if the key already exists.
|
867
|
+
|
868
|
+
Returns
|
869
|
+
-------
|
870
|
+
List[Tuple[str, str]]
|
871
|
+
List of `(key, url)` pairs corresponding to the files uploaded.
|
872
|
+
"""
|
873
|
+
...
|
874
|
+
...
|
875
|
+
|