modal 1.0.5.dev2__py3-none-any.whl → 1.0.5.dev3__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.
- modal/_clustered_functions.pyi +13 -3
- modal/_runtime/container_io_manager.pyi +222 -40
- modal/_runtime/execution_context.pyi +60 -6
- modal/_tunnel.pyi +380 -12
- modal/app.pyi +658 -48
- modal/client.pyi +224 -28
- modal/cloud_bucket_mount.pyi +192 -4
- modal/cls.pyi +442 -35
- modal/container_process.pyi +103 -14
- modal/dict.pyi +453 -51
- modal/environments.pyi +41 -9
- modal/file_io.pyi +236 -45
- modal/functions.pyi +543 -56
- modal/image.pyi +1256 -74
- modal/io_streams.pyi +342 -39
- modal/mount.pyi +261 -31
- modal/network_file_system.pyi +307 -26
- modal/object.pyi +48 -9
- modal/parallel_map.pyi +144 -14
- modal/partial_function.pyi +255 -14
- modal/proxy.pyi +28 -3
- modal/queue.pyi +447 -30
- modal/runner.pyi +160 -22
- modal/sandbox.pyi +310 -50
- modal/secret.pyi +164 -15
- modal/snapshot.pyi +25 -4
- modal/token_flow.pyi +28 -8
- modal/volume.pyi +649 -59
- {modal-1.0.5.dev2.dist-info → modal-1.0.5.dev3.dist-info}/METADATA +1 -1
- {modal-1.0.5.dev2.dist-info → modal-1.0.5.dev3.dist-info}/RECORD +35 -35
- modal_version/__init__.py +1 -1
- {modal-1.0.5.dev2.dist-info → modal-1.0.5.dev3.dist-info}/WHEEL +0 -0
- {modal-1.0.5.dev2.dist-info → modal-1.0.5.dev3.dist-info}/entry_points.txt +0 -0
- {modal-1.0.5.dev2.dist-info → modal-1.0.5.dev3.dist-info}/licenses/LICENSE +0 -0
- {modal-1.0.5.dev2.dist-info → modal-1.0.5.dev3.dist-info}/top_level.txt +0 -0
modal/functions.pyi
CHANGED
@@ -35,6 +35,12 @@ class Function(
|
|
35
35
|
typing.Generic[modal._functions.P, modal._functions.ReturnType, modal._functions.OriginalReturnType],
|
36
36
|
modal.object.Object,
|
37
37
|
):
|
38
|
+
"""Functions are the basic units of serverless execution on Modal.
|
39
|
+
|
40
|
+
Generally, you will not construct a `Function` directly. Instead, use the
|
41
|
+
`App.function()` decorator to register your Python functions with your App.
|
42
|
+
"""
|
43
|
+
|
38
44
|
_info: typing.Optional[modal._utils.function_utils.FunctionInfo]
|
39
45
|
_serve_mounts: frozenset[modal.mount.Mount]
|
40
46
|
_app: typing.Optional[modal.app.App]
|
@@ -53,7 +59,10 @@ class Function(
|
|
53
59
|
_method_handle_metadata: typing.Optional[dict[str, modal_proto.api_pb2.FunctionHandleMetadata]]
|
54
60
|
_metadata: typing.Optional[modal_proto.api_pb2.FunctionHandleMetadata]
|
55
61
|
|
56
|
-
def __init__(self, *args, **kwargs):
|
62
|
+
def __init__(self, *args, **kwargs):
|
63
|
+
"""mdmd:hidden"""
|
64
|
+
...
|
65
|
+
|
57
66
|
@staticmethod
|
58
67
|
def from_local(
|
59
68
|
info: modal._utils.function_utils.FunctionInfo,
|
@@ -101,14 +110,22 @@ class Function(
|
|
101
110
|
_experimental_proxy_ip: typing.Optional[str] = None,
|
102
111
|
_experimental_custom_scaling_factor: typing.Optional[float] = None,
|
103
112
|
_experimental_enable_gpu_snapshot: bool = False,
|
104
|
-
) -> Function:
|
113
|
+
) -> Function:
|
114
|
+
"""mdmd:hidden"""
|
115
|
+
...
|
116
|
+
|
105
117
|
def _bind_parameters(
|
106
118
|
self,
|
107
119
|
obj: modal.cls.Obj,
|
108
120
|
options: typing.Optional[modal.cls._ServiceOptions],
|
109
121
|
args: collections.abc.Sized,
|
110
122
|
kwargs: dict[str, typing.Any],
|
111
|
-
) -> Function:
|
123
|
+
) -> Function:
|
124
|
+
"""mdmd:hidden
|
125
|
+
|
126
|
+
Binds a class-function to a specific instance of (init params, options) or a new workspace
|
127
|
+
"""
|
128
|
+
...
|
112
129
|
|
113
130
|
class __update_autoscaler_spec(typing_extensions.Protocol[SUPERSELF]):
|
114
131
|
def __call__(
|
@@ -119,7 +136,33 @@ class Function(
|
|
119
136
|
max_containers: typing.Optional[int] = None,
|
120
137
|
buffer_containers: typing.Optional[int] = None,
|
121
138
|
scaledown_window: typing.Optional[int] = None,
|
122
|
-
) -> None:
|
139
|
+
) -> None:
|
140
|
+
"""Override the current autoscaler behavior for this Function.
|
141
|
+
|
142
|
+
Unspecified parameters will retain their current value, i.e. either the static value
|
143
|
+
from the function decorator, or an override value from a previous call to this method.
|
144
|
+
|
145
|
+
Subsequent deployments of the App containing this Function will reset the autoscaler back to
|
146
|
+
its static configuration.
|
147
|
+
|
148
|
+
Examples:
|
149
|
+
|
150
|
+
```python notest
|
151
|
+
f = modal.Function.from_name("my-app", "function")
|
152
|
+
|
153
|
+
# Always have at least 2 containers running, with an extra buffer when the Function is active
|
154
|
+
f.update_autoscaler(min_containers=2, buffer_containers=1)
|
155
|
+
|
156
|
+
# Limit this Function to avoid spinning up more than 5 containers
|
157
|
+
f.update_autoscaler(max_containers=5)
|
158
|
+
|
159
|
+
# Extend the scaledown window to increase the amount of time that idle containers stay alive
|
160
|
+
f.update_autoscaler(scaledown_window=300)
|
161
|
+
|
162
|
+
```
|
163
|
+
"""
|
164
|
+
...
|
165
|
+
|
123
166
|
async def aio(
|
124
167
|
self,
|
125
168
|
/,
|
@@ -128,13 +171,71 @@ class Function(
|
|
128
171
|
max_containers: typing.Optional[int] = None,
|
129
172
|
buffer_containers: typing.Optional[int] = None,
|
130
173
|
scaledown_window: typing.Optional[int] = None,
|
131
|
-
) -> None:
|
174
|
+
) -> None:
|
175
|
+
"""Override the current autoscaler behavior for this Function.
|
176
|
+
|
177
|
+
Unspecified parameters will retain their current value, i.e. either the static value
|
178
|
+
from the function decorator, or an override value from a previous call to this method.
|
179
|
+
|
180
|
+
Subsequent deployments of the App containing this Function will reset the autoscaler back to
|
181
|
+
its static configuration.
|
182
|
+
|
183
|
+
Examples:
|
184
|
+
|
185
|
+
```python notest
|
186
|
+
f = modal.Function.from_name("my-app", "function")
|
187
|
+
|
188
|
+
# Always have at least 2 containers running, with an extra buffer when the Function is active
|
189
|
+
f.update_autoscaler(min_containers=2, buffer_containers=1)
|
190
|
+
|
191
|
+
# Limit this Function to avoid spinning up more than 5 containers
|
192
|
+
f.update_autoscaler(max_containers=5)
|
193
|
+
|
194
|
+
# Extend the scaledown window to increase the amount of time that idle containers stay alive
|
195
|
+
f.update_autoscaler(scaledown_window=300)
|
196
|
+
|
197
|
+
```
|
198
|
+
"""
|
199
|
+
...
|
132
200
|
|
133
201
|
update_autoscaler: __update_autoscaler_spec[typing_extensions.Self]
|
134
202
|
|
135
203
|
class __keep_warm_spec(typing_extensions.Protocol[SUPERSELF]):
|
136
|
-
def __call__(self, /, warm_pool_size: int) -> None:
|
137
|
-
|
204
|
+
def __call__(self, /, warm_pool_size: int) -> None:
|
205
|
+
"""mdmd:hidden
|
206
|
+
Set the warm pool size for the Function.
|
207
|
+
|
208
|
+
DEPRECATED: Please adapt your code to use the more general `update_autoscaler` method instead:
|
209
|
+
|
210
|
+
```python notest
|
211
|
+
f = modal.Function.from_name("my-app", "function")
|
212
|
+
|
213
|
+
# Old pattern (deprecated)
|
214
|
+
f.keep_warm(2)
|
215
|
+
|
216
|
+
# New pattern
|
217
|
+
f.update_autoscaler(min_containers=2)
|
218
|
+
```
|
219
|
+
"""
|
220
|
+
...
|
221
|
+
|
222
|
+
async def aio(self, /, warm_pool_size: int) -> None:
|
223
|
+
"""mdmd:hidden
|
224
|
+
Set the warm pool size for the Function.
|
225
|
+
|
226
|
+
DEPRECATED: Please adapt your code to use the more general `update_autoscaler` method instead:
|
227
|
+
|
228
|
+
```python notest
|
229
|
+
f = modal.Function.from_name("my-app", "function")
|
230
|
+
|
231
|
+
# Old pattern (deprecated)
|
232
|
+
f.keep_warm(2)
|
233
|
+
|
234
|
+
# New pattern
|
235
|
+
f.update_autoscaler(min_containers=2)
|
236
|
+
```
|
237
|
+
"""
|
238
|
+
...
|
138
239
|
|
139
240
|
keep_warm: __keep_warm_spec[typing_extensions.Self]
|
140
241
|
|
@@ -143,7 +244,18 @@ class Function(
|
|
143
244
|
@classmethod
|
144
245
|
def from_name(
|
145
246
|
cls: type[Function], app_name: str, name: str, *, namespace=1, environment_name: typing.Optional[str] = None
|
146
|
-
) -> Function:
|
247
|
+
) -> Function:
|
248
|
+
"""Reference a Function from a deployed App by its name.
|
249
|
+
|
250
|
+
In contrast to `modal.Function.lookup`, this is a lazy method
|
251
|
+
that defers hydrating the local object with metadata from
|
252
|
+
Modal servers until the first time it is actually used.
|
253
|
+
|
254
|
+
```python
|
255
|
+
f = modal.Function.from_name("other-app", "function")
|
256
|
+
```
|
257
|
+
"""
|
258
|
+
...
|
147
259
|
|
148
260
|
class __lookup_spec(typing_extensions.Protocol):
|
149
261
|
def __call__(
|
@@ -154,7 +266,21 @@ class Function(
|
|
154
266
|
namespace=1,
|
155
267
|
client: typing.Optional[modal.client.Client] = None,
|
156
268
|
environment_name: typing.Optional[str] = None,
|
157
|
-
) -> Function:
|
269
|
+
) -> Function:
|
270
|
+
"""mdmd:hidden
|
271
|
+
Lookup a Function from a deployed App by its name.
|
272
|
+
|
273
|
+
DEPRECATED: This method is deprecated in favor of `modal.Function.from_name`.
|
274
|
+
|
275
|
+
In contrast to `modal.Function.from_name`, this is an eager method
|
276
|
+
that will hydrate the local object with metadata from Modal servers.
|
277
|
+
|
278
|
+
```python notest
|
279
|
+
f = modal.Function.lookup("other-app", "function")
|
280
|
+
```
|
281
|
+
"""
|
282
|
+
...
|
283
|
+
|
158
284
|
async def aio(
|
159
285
|
self,
|
160
286
|
/,
|
@@ -163,37 +289,81 @@ class Function(
|
|
163
289
|
namespace=1,
|
164
290
|
client: typing.Optional[modal.client.Client] = None,
|
165
291
|
environment_name: typing.Optional[str] = None,
|
166
|
-
) -> Function:
|
292
|
+
) -> Function:
|
293
|
+
"""mdmd:hidden
|
294
|
+
Lookup a Function from a deployed App by its name.
|
295
|
+
|
296
|
+
DEPRECATED: This method is deprecated in favor of `modal.Function.from_name`.
|
297
|
+
|
298
|
+
In contrast to `modal.Function.from_name`, this is an eager method
|
299
|
+
that will hydrate the local object with metadata from Modal servers.
|
300
|
+
|
301
|
+
```python notest
|
302
|
+
f = modal.Function.lookup("other-app", "function")
|
303
|
+
```
|
304
|
+
"""
|
305
|
+
...
|
167
306
|
|
168
307
|
lookup: __lookup_spec
|
169
308
|
|
170
309
|
@property
|
171
|
-
def tag(self) -> str:
|
310
|
+
def tag(self) -> str:
|
311
|
+
"""mdmd:hidden"""
|
312
|
+
...
|
313
|
+
|
172
314
|
@property
|
173
|
-
def app(self) -> modal.app.App:
|
315
|
+
def app(self) -> modal.app.App:
|
316
|
+
"""mdmd:hidden"""
|
317
|
+
...
|
318
|
+
|
174
319
|
@property
|
175
|
-
def stub(self) -> modal.app.App:
|
320
|
+
def stub(self) -> modal.app.App:
|
321
|
+
"""mdmd:hidden"""
|
322
|
+
...
|
323
|
+
|
176
324
|
@property
|
177
|
-
def info(self) -> modal._utils.function_utils.FunctionInfo:
|
325
|
+
def info(self) -> modal._utils.function_utils.FunctionInfo:
|
326
|
+
"""mdmd:hidden"""
|
327
|
+
...
|
328
|
+
|
178
329
|
@property
|
179
|
-
def spec(self) -> modal._functions._FunctionSpec:
|
330
|
+
def spec(self) -> modal._functions._FunctionSpec:
|
331
|
+
"""mdmd:hidden"""
|
332
|
+
...
|
333
|
+
|
180
334
|
def _is_web_endpoint(self) -> bool: ...
|
181
|
-
def get_build_def(self) -> str:
|
335
|
+
def get_build_def(self) -> str:
|
336
|
+
"""mdmd:hidden"""
|
337
|
+
...
|
338
|
+
|
182
339
|
def _initialize_from_empty(self): ...
|
183
340
|
def _hydrate_metadata(self, metadata: typing.Optional[google.protobuf.message.Message]): ...
|
184
341
|
def _get_metadata(self): ...
|
185
342
|
def _check_no_web_url(self, fn_name: str): ...
|
186
343
|
@property
|
187
|
-
def web_url(self) -> typing.Optional[str]:
|
344
|
+
def web_url(self) -> typing.Optional[str]:
|
345
|
+
"""mdmd:hidden
|
346
|
+
Deprecated. Use the `Function.get_web_url()` method instead.
|
347
|
+
|
348
|
+
URL of a Function running as a web endpoint.
|
349
|
+
"""
|
350
|
+
...
|
188
351
|
|
189
352
|
class __get_web_url_spec(typing_extensions.Protocol[SUPERSELF]):
|
190
|
-
def __call__(self, /) -> typing.Optional[str]:
|
191
|
-
|
353
|
+
def __call__(self, /) -> typing.Optional[str]:
|
354
|
+
"""URL of a Function running as a web endpoint."""
|
355
|
+
...
|
356
|
+
|
357
|
+
async def aio(self, /) -> typing.Optional[str]:
|
358
|
+
"""URL of a Function running as a web endpoint."""
|
359
|
+
...
|
192
360
|
|
193
361
|
get_web_url: __get_web_url_spec[typing_extensions.Self]
|
194
362
|
|
195
363
|
@property
|
196
|
-
def is_generator(self) -> bool:
|
364
|
+
def is_generator(self) -> bool:
|
365
|
+
"""mdmd:hidden"""
|
366
|
+
...
|
197
367
|
|
198
368
|
class ___map_spec(typing_extensions.Protocol[SUPERSELF]):
|
199
369
|
def __call__(
|
@@ -203,7 +373,18 @@ class Function(
|
|
203
373
|
order_outputs: bool,
|
204
374
|
return_exceptions: bool,
|
205
375
|
wrap_returned_exceptions: bool,
|
206
|
-
) -> typing.Generator[typing.Any, None, None]:
|
376
|
+
) -> typing.Generator[typing.Any, None, None]:
|
377
|
+
"""mdmd:hidden
|
378
|
+
|
379
|
+
Synchronicity-wrapped map implementation. To be safe against invocations of user code in
|
380
|
+
the synchronicity thread it doesn't accept an [async]iterator, and instead takes a
|
381
|
+
_SynchronizedQueue instance that is fed by higher level functions like .map()
|
382
|
+
|
383
|
+
_SynchronizedQueue is used instead of asyncio.Queue so that the main thread can put
|
384
|
+
items in the queue safely.
|
385
|
+
"""
|
386
|
+
...
|
387
|
+
|
207
388
|
def aio(
|
208
389
|
self,
|
209
390
|
/,
|
@@ -211,7 +392,17 @@ class Function(
|
|
211
392
|
order_outputs: bool,
|
212
393
|
return_exceptions: bool,
|
213
394
|
wrap_returned_exceptions: bool,
|
214
|
-
) -> collections.abc.AsyncGenerator[typing.Any, None]:
|
395
|
+
) -> collections.abc.AsyncGenerator[typing.Any, None]:
|
396
|
+
"""mdmd:hidden
|
397
|
+
|
398
|
+
Synchronicity-wrapped map implementation. To be safe against invocations of user code in
|
399
|
+
the synchronicity thread it doesn't accept an [async]iterator, and instead takes a
|
400
|
+
_SynchronizedQueue instance that is fed by higher level functions like .map()
|
401
|
+
|
402
|
+
_SynchronizedQueue is used instead of asyncio.Queue so that the main thread can put
|
403
|
+
items in the queue safely.
|
404
|
+
"""
|
405
|
+
...
|
215
406
|
|
216
407
|
_map: ___map_spec[typing_extensions.Self]
|
217
408
|
|
@@ -238,14 +429,24 @@ class Function(
|
|
238
429
|
_call_generator: ___call_generator_spec[typing_extensions.Self]
|
239
430
|
|
240
431
|
class __remote_spec(typing_extensions.Protocol[ReturnType_INNER, P_INNER, SUPERSELF]):
|
241
|
-
def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> ReturnType_INNER:
|
242
|
-
|
432
|
+
def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> ReturnType_INNER:
|
433
|
+
"""Calls the function remotely, executing it with the given arguments and returning the execution's result."""
|
434
|
+
...
|
435
|
+
|
436
|
+
async def aio(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> ReturnType_INNER:
|
437
|
+
"""Calls the function remotely, executing it with the given arguments and returning the execution's result."""
|
438
|
+
...
|
243
439
|
|
244
440
|
remote: __remote_spec[modal._functions.ReturnType, modal._functions.P, typing_extensions.Self]
|
245
441
|
|
246
442
|
class __remote_gen_spec(typing_extensions.Protocol[SUPERSELF]):
|
247
|
-
def __call__(self, /, *args, **kwargs) -> typing.Generator[typing.Any, None, None]:
|
248
|
-
|
443
|
+
def __call__(self, /, *args, **kwargs) -> typing.Generator[typing.Any, None, None]:
|
444
|
+
"""Calls the generator remotely, executing it with the given arguments and returning the execution's result."""
|
445
|
+
...
|
446
|
+
|
447
|
+
def aio(self, /, *args, **kwargs) -> collections.abc.AsyncGenerator[typing.Any, None]:
|
448
|
+
"""Calls the generator remotely, executing it with the given arguments and returning the execution's result."""
|
449
|
+
...
|
249
450
|
|
250
451
|
remote_gen: __remote_gen_spec[typing_extensions.Self]
|
251
452
|
|
@@ -254,11 +455,37 @@ class Function(
|
|
254
455
|
def _get_obj(self) -> typing.Optional[modal.cls.Obj]: ...
|
255
456
|
def local(
|
256
457
|
self, *args: modal._functions.P.args, **kwargs: modal._functions.P.kwargs
|
257
|
-
) -> modal._functions.OriginalReturnType:
|
458
|
+
) -> modal._functions.OriginalReturnType:
|
459
|
+
"""Calls the function locally, executing it with the given arguments and returning the execution's result.
|
460
|
+
|
461
|
+
The function will execute in the same environment as the caller, just like calling the underlying function
|
462
|
+
directly in Python. In particular, only secrets available in the caller environment will be available
|
463
|
+
through environment variables.
|
464
|
+
"""
|
465
|
+
...
|
258
466
|
|
259
467
|
class ___experimental_spawn_spec(typing_extensions.Protocol[ReturnType_INNER, P_INNER, SUPERSELF]):
|
260
|
-
def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
|
261
|
-
|
468
|
+
def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
|
469
|
+
"""[Experimental] Calls the function with the given arguments, without waiting for the results.
|
470
|
+
|
471
|
+
This experimental version of the spawn method allows up to 1 million inputs to be spawned.
|
472
|
+
|
473
|
+
Returns a `modal.FunctionCall` object, that can later be polled or
|
474
|
+
waited for using `.get(timeout=...)`.
|
475
|
+
Conceptually similar to `multiprocessing.pool.apply_async`, or a Future/Promise in other contexts.
|
476
|
+
"""
|
477
|
+
...
|
478
|
+
|
479
|
+
async def aio(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
|
480
|
+
"""[Experimental] Calls the function with the given arguments, without waiting for the results.
|
481
|
+
|
482
|
+
This experimental version of the spawn method allows up to 1 million inputs to be spawned.
|
483
|
+
|
484
|
+
Returns a `modal.FunctionCall` object, that can later be polled or
|
485
|
+
waited for using `.get(timeout=...)`.
|
486
|
+
Conceptually similar to `multiprocessing.pool.apply_async`, or a Future/Promise in other contexts.
|
487
|
+
"""
|
488
|
+
...
|
262
489
|
|
263
490
|
_experimental_spawn: ___experimental_spawn_spec[
|
264
491
|
modal._functions.ReturnType, modal._functions.P, typing_extensions.Self
|
@@ -271,22 +498,49 @@ class Function(
|
|
271
498
|
_spawn_map_inner: ___spawn_map_inner_spec[modal._functions.P, typing_extensions.Self]
|
272
499
|
|
273
500
|
class __spawn_spec(typing_extensions.Protocol[ReturnType_INNER, P_INNER, SUPERSELF]):
|
274
|
-
def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
|
275
|
-
|
501
|
+
def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
|
502
|
+
"""Calls the function with the given arguments, without waiting for the results.
|
503
|
+
|
504
|
+
Returns a [`modal.FunctionCall`](/docs/reference/modal.FunctionCall) object, that can later be polled or
|
505
|
+
waited for using [`.get(timeout=...)`](/docs/reference/modal.FunctionCall#get).
|
506
|
+
Conceptually similar to `multiprocessing.pool.apply_async`, or a Future/Promise in other contexts.
|
507
|
+
"""
|
508
|
+
...
|
509
|
+
|
510
|
+
async def aio(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
|
511
|
+
"""Calls the function with the given arguments, without waiting for the results.
|
512
|
+
|
513
|
+
Returns a [`modal.FunctionCall`](/docs/reference/modal.FunctionCall) object, that can later be polled or
|
514
|
+
waited for using [`.get(timeout=...)`](/docs/reference/modal.FunctionCall#get).
|
515
|
+
Conceptually similar to `multiprocessing.pool.apply_async`, or a Future/Promise in other contexts.
|
516
|
+
"""
|
517
|
+
...
|
276
518
|
|
277
519
|
spawn: __spawn_spec[modal._functions.ReturnType, modal._functions.P, typing_extensions.Self]
|
278
520
|
|
279
|
-
def get_raw_f(self) -> collections.abc.Callable[..., typing.Any]:
|
521
|
+
def get_raw_f(self) -> collections.abc.Callable[..., typing.Any]:
|
522
|
+
"""Return the inner Python object wrapped by this Modal Function."""
|
523
|
+
...
|
280
524
|
|
281
525
|
class __get_current_stats_spec(typing_extensions.Protocol[SUPERSELF]):
|
282
|
-
def __call__(self, /) -> modal._functions.FunctionStats:
|
283
|
-
|
526
|
+
def __call__(self, /) -> modal._functions.FunctionStats:
|
527
|
+
"""Return a `FunctionStats` object describing the current function's queue and runner counts."""
|
528
|
+
...
|
529
|
+
|
530
|
+
async def aio(self, /) -> modal._functions.FunctionStats:
|
531
|
+
"""Return a `FunctionStats` object describing the current function's queue and runner counts."""
|
532
|
+
...
|
284
533
|
|
285
534
|
get_current_stats: __get_current_stats_spec[typing_extensions.Self]
|
286
535
|
|
287
536
|
class ___get_schema_spec(typing_extensions.Protocol[SUPERSELF]):
|
288
|
-
def __call__(self, /) -> modal_proto.api_pb2.FunctionSchema:
|
289
|
-
|
537
|
+
def __call__(self, /) -> modal_proto.api_pb2.FunctionSchema:
|
538
|
+
"""Returns recorded schema for function, internal use only for now"""
|
539
|
+
...
|
540
|
+
|
541
|
+
async def aio(self, /) -> modal_proto.api_pb2.FunctionSchema:
|
542
|
+
"""Returns recorded schema for function, internal use only for now"""
|
543
|
+
...
|
290
544
|
|
291
545
|
_get_schema: ___get_schema_spec[typing_extensions.Self]
|
292
546
|
|
@@ -299,7 +553,45 @@ class Function(
|
|
299
553
|
order_outputs: bool = True,
|
300
554
|
return_exceptions: bool = False,
|
301
555
|
wrap_returned_exceptions: bool = True,
|
302
|
-
) -> modal._utils.async_utils.AsyncOrSyncIterable:
|
556
|
+
) -> modal._utils.async_utils.AsyncOrSyncIterable:
|
557
|
+
"""Parallel map over a set of inputs.
|
558
|
+
|
559
|
+
Takes one iterator argument per argument in the function being mapped over.
|
560
|
+
|
561
|
+
Example:
|
562
|
+
```python
|
563
|
+
@app.function()
|
564
|
+
def my_func(a):
|
565
|
+
return a ** 2
|
566
|
+
|
567
|
+
|
568
|
+
@app.local_entrypoint()
|
569
|
+
def main():
|
570
|
+
assert list(my_func.map([1, 2, 3, 4])) == [1, 4, 9, 16]
|
571
|
+
```
|
572
|
+
|
573
|
+
If applied to a `app.function`, `map()` returns one result per input and the output order
|
574
|
+
is guaranteed to be the same as the input order. Set `order_outputs=False` to return results
|
575
|
+
in the order that they are completed instead.
|
576
|
+
|
577
|
+
`return_exceptions` can be used to treat exceptions as successful results:
|
578
|
+
|
579
|
+
```python
|
580
|
+
@app.function()
|
581
|
+
def my_func(a):
|
582
|
+
if a == 2:
|
583
|
+
raise Exception("ohno")
|
584
|
+
return a ** 2
|
585
|
+
|
586
|
+
|
587
|
+
@app.local_entrypoint()
|
588
|
+
def main():
|
589
|
+
# [0, 1, UserCodeException(Exception('ohno'))]
|
590
|
+
print(list(my_func.map(range(3), return_exceptions=True)))
|
591
|
+
```
|
592
|
+
"""
|
593
|
+
...
|
594
|
+
|
303
595
|
def aio(
|
304
596
|
self,
|
305
597
|
/,
|
@@ -322,7 +614,25 @@ class Function(
|
|
322
614
|
order_outputs: bool = True,
|
323
615
|
return_exceptions: bool = False,
|
324
616
|
wrap_returned_exceptions: bool = True,
|
325
|
-
) -> modal._utils.async_utils.AsyncOrSyncIterable:
|
617
|
+
) -> modal._utils.async_utils.AsyncOrSyncIterable:
|
618
|
+
"""Like `map`, but spreads arguments over multiple function arguments.
|
619
|
+
|
620
|
+
Assumes every input is a sequence (e.g. a tuple).
|
621
|
+
|
622
|
+
Example:
|
623
|
+
```python
|
624
|
+
@app.function()
|
625
|
+
def my_func(a, b):
|
626
|
+
return a + b
|
627
|
+
|
628
|
+
|
629
|
+
@app.local_entrypoint()
|
630
|
+
def main():
|
631
|
+
assert list(my_func.starmap([(1, 2), (3, 4)])) == [3, 7]
|
632
|
+
```
|
633
|
+
"""
|
634
|
+
...
|
635
|
+
|
326
636
|
def aio(
|
327
637
|
self,
|
328
638
|
/,
|
@@ -339,63 +649,240 @@ class Function(
|
|
339
649
|
starmap: __starmap_spec[typing_extensions.Self]
|
340
650
|
|
341
651
|
class __for_each_spec(typing_extensions.Protocol[SUPERSELF]):
|
342
|
-
def __call__(self, /, *input_iterators, kwargs={}, ignore_exceptions: bool = False):
|
652
|
+
def __call__(self, /, *input_iterators, kwargs={}, ignore_exceptions: bool = False):
|
653
|
+
"""Execute function for all inputs, ignoring outputs. Waits for completion of the inputs.
|
654
|
+
|
655
|
+
Convenient alias for `.map()` in cases where the function just needs to be called.
|
656
|
+
as the caller doesn't have to consume the generator to process the inputs.
|
657
|
+
"""
|
658
|
+
...
|
659
|
+
|
343
660
|
async def aio(self, /, *input_iterators, kwargs={}, ignore_exceptions: bool = False) -> None: ...
|
344
661
|
|
345
662
|
for_each: __for_each_spec[typing_extensions.Self]
|
346
663
|
|
347
664
|
class __spawn_map_spec(typing_extensions.Protocol[SUPERSELF]):
|
348
|
-
def __call__(self, /, *input_iterators, kwargs={}) -> None:
|
349
|
-
|
665
|
+
def __call__(self, /, *input_iterators, kwargs={}) -> None:
|
666
|
+
"""Spawn parallel execution over a set of inputs, exiting as soon as the inputs are created (without waiting
|
667
|
+
for the map to complete).
|
668
|
+
|
669
|
+
Takes one iterator argument per argument in the function being mapped over.
|
670
|
+
|
671
|
+
Example:
|
672
|
+
```python
|
673
|
+
@app.function()
|
674
|
+
def my_func(a):
|
675
|
+
return a ** 2
|
676
|
+
|
677
|
+
|
678
|
+
@app.local_entrypoint()
|
679
|
+
def main():
|
680
|
+
my_func.spawn_map([1, 2, 3, 4])
|
681
|
+
```
|
682
|
+
|
683
|
+
Programmatic retrieval of results will be supported in a future update.
|
684
|
+
"""
|
685
|
+
...
|
686
|
+
|
687
|
+
async def aio(self, /, *input_iterators, kwargs={}) -> None:
|
688
|
+
"""This runs in an event loop on the main thread. It consumes inputs from the input iterators and creates async
|
689
|
+
function calls for each.
|
690
|
+
"""
|
691
|
+
...
|
350
692
|
|
351
693
|
spawn_map: __spawn_map_spec[typing_extensions.Self]
|
352
694
|
|
353
695
|
class FunctionCall(typing.Generic[modal._functions.ReturnType], modal.object.Object):
|
696
|
+
"""A reference to an executed function call.
|
697
|
+
|
698
|
+
Constructed using `.spawn(...)` on a Modal function with the same
|
699
|
+
arguments that a function normally takes. Acts as a reference to
|
700
|
+
an ongoing function call that can be passed around and used to
|
701
|
+
poll or fetch function results at some later time.
|
702
|
+
|
703
|
+
Conceptually similar to a Future/Promise/AsyncResult in other contexts and languages.
|
704
|
+
"""
|
705
|
+
|
354
706
|
_is_generator: bool
|
355
707
|
|
356
|
-
def __init__(self, *args, **kwargs):
|
708
|
+
def __init__(self, *args, **kwargs):
|
709
|
+
"""mdmd:hidden"""
|
710
|
+
...
|
711
|
+
|
357
712
|
def _invocation(self): ...
|
358
713
|
|
359
714
|
class __get_spec(typing_extensions.Protocol[ReturnType_INNER, SUPERSELF]):
|
360
|
-
def __call__(self, /, timeout: typing.Optional[float] = None) -> ReturnType_INNER:
|
361
|
-
|
715
|
+
def __call__(self, /, timeout: typing.Optional[float] = None) -> ReturnType_INNER:
|
716
|
+
"""Get the result of the function call.
|
717
|
+
|
718
|
+
This function waits indefinitely by default. It takes an optional
|
719
|
+
`timeout` argument that specifies the maximum number of seconds to wait,
|
720
|
+
which can be set to `0` to poll for an output immediately.
|
721
|
+
|
722
|
+
The returned coroutine is not cancellation-safe.
|
723
|
+
"""
|
724
|
+
...
|
725
|
+
|
726
|
+
async def aio(self, /, timeout: typing.Optional[float] = None) -> ReturnType_INNER:
|
727
|
+
"""Get the result of the function call.
|
728
|
+
|
729
|
+
This function waits indefinitely by default. It takes an optional
|
730
|
+
`timeout` argument that specifies the maximum number of seconds to wait,
|
731
|
+
which can be set to `0` to poll for an output immediately.
|
732
|
+
|
733
|
+
The returned coroutine is not cancellation-safe.
|
734
|
+
"""
|
735
|
+
...
|
362
736
|
|
363
737
|
get: __get_spec[modal._functions.ReturnType, typing_extensions.Self]
|
364
738
|
|
365
739
|
class __get_call_graph_spec(typing_extensions.Protocol[SUPERSELF]):
|
366
|
-
def __call__(self, /) -> list[modal.call_graph.InputInfo]:
|
367
|
-
|
740
|
+
def __call__(self, /) -> list[modal.call_graph.InputInfo]:
|
741
|
+
"""Returns a structure representing the call graph from a given root
|
742
|
+
call ID, along with the status of execution for each node.
|
743
|
+
|
744
|
+
See [`modal.call_graph`](/docs/reference/modal.call_graph) reference page
|
745
|
+
for documentation on the structure of the returned `InputInfo` items.
|
746
|
+
"""
|
747
|
+
...
|
748
|
+
|
749
|
+
async def aio(self, /) -> list[modal.call_graph.InputInfo]:
|
750
|
+
"""Returns a structure representing the call graph from a given root
|
751
|
+
call ID, along with the status of execution for each node.
|
752
|
+
|
753
|
+
See [`modal.call_graph`](/docs/reference/modal.call_graph) reference page
|
754
|
+
for documentation on the structure of the returned `InputInfo` items.
|
755
|
+
"""
|
756
|
+
...
|
368
757
|
|
369
758
|
get_call_graph: __get_call_graph_spec[typing_extensions.Self]
|
370
759
|
|
371
760
|
class __cancel_spec(typing_extensions.Protocol[SUPERSELF]):
|
372
|
-
def __call__(self, /, terminate_containers: bool = False):
|
373
|
-
|
761
|
+
def __call__(self, /, terminate_containers: bool = False):
|
762
|
+
"""Cancels the function call, which will stop its execution and mark its inputs as
|
763
|
+
[`TERMINATED`](/docs/reference/modal.call_graph#modalcall_graphinputstatus).
|
764
|
+
|
765
|
+
If `terminate_containers=True` - the containers running the cancelled inputs are all terminated
|
766
|
+
causing any non-cancelled inputs on those containers to be rescheduled in new containers.
|
767
|
+
"""
|
768
|
+
...
|
769
|
+
|
770
|
+
async def aio(self, /, terminate_containers: bool = False):
|
771
|
+
"""Cancels the function call, which will stop its execution and mark its inputs as
|
772
|
+
[`TERMINATED`](/docs/reference/modal.call_graph#modalcall_graphinputstatus).
|
773
|
+
|
774
|
+
If `terminate_containers=True` - the containers running the cancelled inputs are all terminated
|
775
|
+
causing any non-cancelled inputs on those containers to be rescheduled in new containers.
|
776
|
+
"""
|
777
|
+
...
|
374
778
|
|
375
779
|
cancel: __cancel_spec[typing_extensions.Self]
|
376
780
|
|
377
781
|
class __from_id_spec(typing_extensions.Protocol):
|
378
782
|
def __call__(
|
379
783
|
self, /, function_call_id: str, client: typing.Optional[modal.client.Client] = None
|
380
|
-
) -> FunctionCall[typing.Any]:
|
784
|
+
) -> FunctionCall[typing.Any]:
|
785
|
+
"""Instantiate a FunctionCall object from an existing ID.
|
786
|
+
|
787
|
+
Examples:
|
788
|
+
|
789
|
+
```python notest
|
790
|
+
# Spawn a FunctionCall and keep track of its object ID
|
791
|
+
fc = my_func.spawn()
|
792
|
+
fc_id = fc.object_id
|
793
|
+
|
794
|
+
# Later, use the ID to re-instantiate the FunctionCall object
|
795
|
+
fc = _FunctionCall.from_id(fc_id)
|
796
|
+
result = fc.get()
|
797
|
+
```
|
798
|
+
|
799
|
+
Note that it's only necessary to re-instantiate the `FunctionCall` with this method
|
800
|
+
if you no longer have access to the original object returned from `Function.spawn`.
|
801
|
+
"""
|
802
|
+
...
|
803
|
+
|
381
804
|
async def aio(
|
382
805
|
self, /, function_call_id: str, client: typing.Optional[modal.client.Client] = None
|
383
|
-
) -> FunctionCall[typing.Any]:
|
806
|
+
) -> FunctionCall[typing.Any]:
|
807
|
+
"""Instantiate a FunctionCall object from an existing ID.
|
808
|
+
|
809
|
+
Examples:
|
810
|
+
|
811
|
+
```python notest
|
812
|
+
# Spawn a FunctionCall and keep track of its object ID
|
813
|
+
fc = my_func.spawn()
|
814
|
+
fc_id = fc.object_id
|
815
|
+
|
816
|
+
# Later, use the ID to re-instantiate the FunctionCall object
|
817
|
+
fc = _FunctionCall.from_id(fc_id)
|
818
|
+
result = fc.get()
|
819
|
+
```
|
820
|
+
|
821
|
+
Note that it's only necessary to re-instantiate the `FunctionCall` with this method
|
822
|
+
if you no longer have access to the original object returned from `Function.spawn`.
|
823
|
+
"""
|
824
|
+
...
|
384
825
|
|
385
826
|
from_id: __from_id_spec
|
386
827
|
|
387
828
|
class __gather_spec(typing_extensions.Protocol):
|
388
|
-
def __call__(
|
389
|
-
|
390
|
-
|
829
|
+
def __call__(self, /, *function_calls: FunctionCall[modal._functions.T]) -> typing.Sequence[modal._functions.T]:
|
830
|
+
"""Wait until all Modal FunctionCall objects have results before returning.
|
831
|
+
|
832
|
+
Accepts a variable number of `FunctionCall` objects, as returned by `Function.spawn()`.
|
833
|
+
|
834
|
+
Returns a list of results from each FunctionCall, or raises an exception
|
835
|
+
from the first failing function call.
|
836
|
+
|
837
|
+
Examples:
|
838
|
+
|
839
|
+
```python notest
|
840
|
+
fc1 = slow_func_1.spawn()
|
841
|
+
fc2 = slow_func_2.spawn()
|
842
|
+
|
843
|
+
result_1, result_2 = modal.FunctionCall.gather(fc1, fc2)
|
844
|
+
```
|
845
|
+
|
846
|
+
*Added in v0.73.69*: This method replaces the deprecated `modal.functions.gather` function.
|
847
|
+
"""
|
848
|
+
...
|
849
|
+
|
391
850
|
async def aio(
|
392
851
|
self, /, *function_calls: FunctionCall[modal._functions.T]
|
393
|
-
) -> typing.Sequence[modal._functions.T]:
|
852
|
+
) -> typing.Sequence[modal._functions.T]:
|
853
|
+
"""Wait until all Modal FunctionCall objects have results before returning.
|
854
|
+
|
855
|
+
Accepts a variable number of `FunctionCall` objects, as returned by `Function.spawn()`.
|
856
|
+
|
857
|
+
Returns a list of results from each FunctionCall, or raises an exception
|
858
|
+
from the first failing function call.
|
859
|
+
|
860
|
+
Examples:
|
861
|
+
|
862
|
+
```python notest
|
863
|
+
fc1 = slow_func_1.spawn()
|
864
|
+
fc2 = slow_func_2.spawn()
|
865
|
+
|
866
|
+
result_1, result_2 = modal.FunctionCall.gather(fc1, fc2)
|
867
|
+
```
|
868
|
+
|
869
|
+
*Added in v0.73.69*: This method replaces the deprecated `modal.functions.gather` function.
|
870
|
+
"""
|
871
|
+
...
|
394
872
|
|
395
873
|
gather: __gather_spec
|
396
874
|
|
397
875
|
class __gather_spec(typing_extensions.Protocol):
|
398
|
-
def __call__(self, /, *function_calls) -> typing.Sequence[modal._functions.T]:
|
399
|
-
|
876
|
+
def __call__(self, /, *function_calls) -> typing.Sequence[modal._functions.T]:
|
877
|
+
"""mdmd:hidden
|
878
|
+
Deprecated: Please use `modal.FunctionCall.gather()` instead.
|
879
|
+
"""
|
880
|
+
...
|
881
|
+
|
882
|
+
async def aio(self, /, *function_calls) -> typing.Sequence[modal._functions.T]:
|
883
|
+
"""mdmd:hidden
|
884
|
+
Deprecated: Please use `modal.FunctionCall.gather()` instead.
|
885
|
+
"""
|
886
|
+
...
|
400
887
|
|
401
888
|
gather: __gather_spec
|