modal 1.6.2.dev8__py3-none-any.whl → 1.6.2.dev9__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/_workspace.py CHANGED
@@ -9,6 +9,7 @@ from typing import Optional
9
9
  from google.protobuf.empty_pb2 import Empty
10
10
 
11
11
  from modal.exception import DeprecationError, InvalidError
12
+ from modal.types import ServiceUserInfo
12
13
  from modal_proto import api_pb2
13
14
 
14
15
  from ._load_context import LoadContext
@@ -129,6 +130,15 @@ class _Workspace(_Object, type_prefix="ac"):
129
130
  """Namespace for Workspace settings APIs."""
130
131
  return _WorkspaceSettingsManager(self)
131
132
 
133
+ @property
134
+ def service_users(self) -> "_WorkspaceServiceUserManager":
135
+ """Namespace for managing Service Users in a Workspace.
136
+
137
+ See [the guide](https://modal.com/docs/guide/service-users) for more information about Service
138
+ Users.
139
+ """
140
+ return _WorkspaceServiceUserManager(self)
141
+
132
142
 
133
143
  class _WorkspaceProxyTokenManager:
134
144
  """mdmd:namespace"""
@@ -556,3 +566,169 @@ class _WorkspaceSettingsManager:
556
566
  await self._set_default_environment(value)
557
567
  case _:
558
568
  raise ValueError(f"Unknown setting {name!r}. Valid settings: {', '.join(self._valid_settings())}")
569
+
570
+
571
+ class _WorkspaceServiceUserManager:
572
+ """mdmd:namespace"""
573
+
574
+ def __init__(self, workspace: _Workspace):
575
+ """mdmd:hidden"""
576
+ self._workspace = workspace
577
+
578
+ async def create(self, name: str, *, expires_in: int | None) -> TokenData:
579
+ """Create a new Service User in the current workspace.
580
+
581
+ To call this function, you are required to have Manager permissions in the Workspace.
582
+
583
+ Args:
584
+ name: The name of the new Service User. Must consistent only of alphanumeric, '-', or '_'
585
+ characters.
586
+ expires_in: An expiration time, in seconds, after which the token will stop working. If
587
+ `None`, the token will never expire.
588
+
589
+ Returns:
590
+ A `TokenData` dataclass containing the credentials for the Service User. Note that this
591
+ is the only time you will be able to view these credentials.
592
+
593
+ Examples:
594
+
595
+ ```python notest
596
+ ws = modal.Workspace.from_context()
597
+
598
+ # Creates a Service User named "test-service-user", whose credentials expire after one year.
599
+ service_user_token_data = ws.service_users.create(
600
+ "test-service-user",
601
+ expires_in=datetime.timedelta(days=365).total_seconds(),
602
+ )
603
+ ```
604
+ """
605
+ if not self._workspace._is_hydrated:
606
+ await self._workspace.hydrate()
607
+
608
+ if expires_in is None:
609
+ req = api_pb2.ServiceUserCreateRequest(name=name)
610
+ else:
611
+ req = api_pb2.ServiceUserCreateRequest(name=name, expires_in_seconds=expires_in)
612
+
613
+ resp = await self._workspace.client._stub.ServiceUserCreate(req)
614
+
615
+ return TokenData(token_id=resp.token_id, token_secret=resp.token_secret)
616
+
617
+ async def set_role(
618
+ self,
619
+ service_user_name: str,
620
+ environment_name: str,
621
+ *,
622
+ role: str,
623
+ ) -> None:
624
+ """Set the role of a specified Service User within an Environment.
625
+
626
+ To call this function, you are required to have Manager permissions in the Workspace.
627
+
628
+ Args:
629
+ service_user_name: The name of the Service User.
630
+ environment_name: The name of the Environment to which the Service User's new role will
631
+ apply.
632
+ role: The access level to grant this Service User. Must be one of the strings `"no-access"`,
633
+ `"viewer"`, or `"contributor"`.
634
+
635
+ Examples:
636
+
637
+ ```python notest
638
+ ws = modal.Workspace.from_context()
639
+ # Grants Service User "test-service-user" the Viewer role in Environment "production"
640
+ ws.service_users.set_role("test-service-user", "production", role="viewer")
641
+
642
+ # Revokes access to "production" from Service User "test-service-user"
643
+ ws.service_users.set_role("test-service-user", "production", role="no-access")
644
+ ```
645
+ """
646
+
647
+ if not self._workspace._is_hydrated:
648
+ await self._workspace.hydrate()
649
+
650
+ from ._environments import _Environment
651
+
652
+ env = _Environment.from_name(environment_name, client=self._workspace.client)
653
+ await env.hydrate()
654
+
655
+ await self._workspace.client._stub.EnvironmentRoleSet(
656
+ api_pb2.EnvironmentRoleSetRequest(
657
+ service_user_name=service_user_name,
658
+ environment_id=env.object_id,
659
+ role_str=role,
660
+ )
661
+ )
662
+
663
+ async def info(self, name: str) -> ServiceUserInfo:
664
+ """Get information about a specific Service User.
665
+
666
+ To call this function, you are required to have Manager permissions in the Workspace.
667
+
668
+ Args:
669
+ name: The name of the Service User to introspect.
670
+
671
+ Returns:
672
+ A `ServiceUserInfo` dataclass containing information about the Service User.
673
+
674
+ Examples:
675
+
676
+ ```python notest
677
+ ws = modal.Workspace.from_context()
678
+ service_user = ws.service_users.info("test-service-user")
679
+ ```
680
+ """
681
+
682
+ if not self._workspace._is_hydrated:
683
+ await self._workspace.hydrate()
684
+
685
+ resp = await self._workspace.client._stub.ServiceUserInfo(
686
+ api_pb2.ServiceUserInfoRequest(service_user_name=name)
687
+ )
688
+
689
+ return ServiceUserInfo._from_proto(resp.service_user)
690
+
691
+ async def list(self) -> list[ServiceUserInfo]:
692
+ """List all Service Users in the current workspace.
693
+
694
+ To call this function, you are required to have Manager permissions in the Workspace.
695
+
696
+ Returns:
697
+ A list of `ServiceUserInfo` dataclasses.
698
+
699
+ Examples:
700
+
701
+ ```python notest
702
+ ws = modal.Workspace.from_context()
703
+ for service_user in ws.service_users.list():
704
+ print(service_user.name)
705
+ ```
706
+ """
707
+
708
+ if not self._workspace._is_hydrated:
709
+ await self._workspace.hydrate()
710
+
711
+ resp = await self._workspace.client._stub.ServiceUserList(Empty())
712
+
713
+ return [ServiceUserInfo._from_proto(su) for su in resp.service_users]
714
+
715
+ async def delete(self, name: str) -> None:
716
+ """Permanently delete a Service User.
717
+
718
+ To call this function, you are required to have Manager permissions in the Workspace.
719
+
720
+ Args:
721
+ name: The name of the Service User to delete.
722
+
723
+ Examples:
724
+
725
+ ```python notest
726
+ ws = modal.Workspace.from_context()
727
+ ws.service_users.delete("test-service-user")
728
+ ```
729
+ """
730
+
731
+ if not self._workspace._is_hydrated:
732
+ await self._workspace.hydrate()
733
+
734
+ await self._workspace.client._stub.ServiceUserDelete(api_pb2.ServiceUserDeleteRequest(service_user_name=name))
modal/cli/import_refs.py CHANGED
@@ -7,11 +7,14 @@ or the app lookup of `modal deploy some_file.py`.
7
7
  These functions are only called by the Modal CLI, not in tasks.
8
8
  """
9
9
 
10
+ import atexit
10
11
  import dataclasses
11
12
  import importlib
12
13
  import importlib.util
13
14
  import inspect
15
+ import shutil
14
16
  import sys
17
+ import tempfile
15
18
  import typing
16
19
  from collections import defaultdict
17
20
  from dataclasses import dataclass
@@ -60,15 +63,40 @@ def parse_import_ref(object_ref: str, use_module_mode: bool = False, command: st
60
63
 
61
64
  DEFAULT_APP_NAME = "app"
62
65
 
66
+ STDIN_REF = "-"
67
+ STDIN_MODULE_NAME = "modal_stdin_app"
63
68
 
64
- def import_file_or_module(import_ref: ImportRef, base_cmd: str = ""):
69
+
70
+ def _write_stdin_script() -> str:
71
+ if sys.stdin is None or sys.stdin.isatty():
72
+ raise InvalidError("No script was piped on stdin. Usage: `cat my_app.py | modal run -`")
73
+ source = sys.stdin.read()
74
+ # The file must outlive the import: the entrypoint mount is built from it when the App runs.
75
+ tmp_dir = tempfile.mkdtemp(prefix="modal-stdin-")
76
+ atexit.register(shutil.rmtree, tmp_dir, ignore_errors=True)
77
+ script_path = Path(tmp_dir) / f"{STDIN_MODULE_NAME}.py"
78
+ script_path.write_text(source)
79
+ return str(script_path)
80
+
81
+
82
+ def import_file_or_module(import_ref: ImportRef, base_cmd: str = "", allow_stdin: bool = False):
65
83
  if "" not in sys.path:
66
84
  # When running from a CLI like `modal run`
67
85
  # the current working directory isn't added to sys.path
68
86
  # so we add it in order to make module path specification possible
69
87
  sys.path.insert(0, "") # "" means the current working directory
70
88
 
71
- if not import_ref.file_or_module.endswith(".py") or import_ref.use_module_mode:
89
+ from_stdin = import_ref.file_or_module == STDIN_REF
90
+ if from_stdin:
91
+ if not allow_stdin:
92
+ raise InvalidError(f"`{base_cmd}` does not support reading a script from stdin.")
93
+ if import_ref.use_module_mode:
94
+ raise InvalidError("Reading a script from stdin (`-`) can't be combined with the -m flag.")
95
+ script_path = _write_stdin_script()
96
+ else:
97
+ script_path = import_ref.file_or_module
98
+
99
+ if not script_path.endswith(".py") or import_ref.use_module_mode:
72
100
  if not import_ref.use_module_mode:
73
101
  raise InvalidError(
74
102
  "Python module paths must be specified with the -m flag. "
@@ -82,7 +110,7 @@ def import_file_or_module(import_ref: ImportRef, base_cmd: str = ""):
82
110
  else:
83
111
  # when using a script path, that scripts directory should also be on the path as it is
84
112
  # with `python some/script.py`
85
- full_path = Path(import_ref.file_or_module).resolve()
113
+ full_path = Path(script_path).resolve()
86
114
  if "." in full_path.name.removesuffix(".py"):
87
115
  raise InvalidError(
88
116
  f"Invalid Modal source filename: {full_path.name!r}."
@@ -90,10 +118,10 @@ def import_file_or_module(import_ref: ImportRef, base_cmd: str = ""):
90
118
  )
91
119
  sys.path.insert(0, str(full_path.parent))
92
120
 
93
- module_name = inspect.getmodulename(import_ref.file_or_module)
121
+ module_name = inspect.getmodulename(script_path)
94
122
  assert module_name is not None
95
123
  # Import the module - see https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
96
- spec = importlib.util.spec_from_file_location(module_name, import_ref.file_or_module)
124
+ spec = importlib.util.spec_from_file_location(module_name, script_path)
97
125
  assert spec is not None
98
126
  module = importlib.util.module_from_spec(spec)
99
127
  sys.modules[module_name] = module
@@ -103,7 +131,7 @@ def import_file_or_module(import_ref: ImportRef, base_cmd: str = ""):
103
131
  spec.loader.exec_module(module)
104
132
  except Exception as exc:
105
133
  if isinstance(exc, ImportError) and "attempted relative import with no known parent package" in str(exc):
106
- if import_ref.file_or_module and import_ref.command and not import_ref.use_module_mode:
134
+ if import_ref.command and not import_ref.use_module_mode and not from_stdin:
107
135
  file_path = Path(import_ref.file_or_module)
108
136
  suggested_module_path = ".".join(file_path.parts).removesuffix(".py").lstrip(".")
109
137
  suffix = f"::{import_ref.object_path}" if import_ref.object_path else ""
@@ -356,6 +384,7 @@ def import_and_filter(
356
384
  accept_local_entrypoint=True,
357
385
  accept_webhook=False,
358
386
  accept_service_functions=False,
387
+ allow_stdin=False,
359
388
  ) -> tuple[Runnable | None, list[CLICommand]]:
360
389
  """Takes a function ref string and returns a single determined "runnable" to use, and a list of all available
361
390
  runnables.
@@ -371,7 +400,7 @@ def import_and_filter(
371
400
  3. if there is a single method (within a class) that one is used
372
401
  """
373
402
  # all commands:
374
- module = import_file_or_module(import_ref, base_cmd)
403
+ module = import_file_or_module(import_ref, base_cmd, allow_stdin=allow_stdin)
375
404
  cli_commands = list_cli_commands(
376
405
  dict(inspect.getmembers(module)),
377
406
  include_service_functions=accept_service_functions,
modal/cli/run.py CHANGED
@@ -2,7 +2,9 @@
2
2
  import asyncio
3
3
  import functools
4
4
  import inspect
5
+ import os
5
6
  import re
7
+ import stat
6
8
  import sys
7
9
  import time
8
10
  import typing
@@ -25,6 +27,7 @@ from ..runner import DEPLOYMENT_STRATEGY_TYPE, deploy_app, run_app
25
27
  from ..serving import serve_app
26
28
  from ._help import ModalCommand, ModalGroup, _consume_global_options, _global_option_token_length
27
29
  from .import_refs import (
30
+ STDIN_REF,
28
31
  CLICommand,
29
32
  MethodReference,
30
33
  _get_runnable_app,
@@ -399,6 +402,14 @@ def _get_click_command_for_local_entrypoint(app: App, entrypoint: LocalEntrypoin
399
402
  return click.command(cls=ModalCommand)(with_click_options)
400
403
 
401
404
 
405
+ def _stdin_is_piped() -> bool:
406
+ try:
407
+ mode = os.fstat(sys.stdin.fileno()).st_mode
408
+ except (AttributeError, OSError, ValueError):
409
+ return False
410
+ return stat.S_ISFIFO(mode) or stat.S_ISREG(mode)
411
+
412
+
402
413
  def _get_runnable_list(all_usable_commands: list[CLICommand]) -> str:
403
414
  usable_command_lines = []
404
415
  for cmd in all_usable_commands:
@@ -428,6 +439,8 @@ class RunGroup(ModalGroup):
428
439
  elif arg == "--":
429
440
  func_ref_index += 1
430
441
  break
442
+ elif arg == STDIN_REF:
443
+ break
431
444
  elif param := option_params.get(arg.split("=", 1)[0]):
432
445
  func_ref_index += 1 if "=" in arg or param.is_flag else param.nargs + 1
433
446
  elif arg.startswith("-"):
@@ -435,6 +448,14 @@ class RunGroup(ModalGroup):
435
448
  else:
436
449
  break
437
450
 
451
+ missing_func_ref = func_ref_index >= len(args)
452
+ requests_help = any(arg in ctx.help_option_names for arg in args)
453
+ if missing_func_ref and not requests_help and not ctx.resilient_parsing and _stdin_is_piped():
454
+ raise click.UsageError(
455
+ f"Missing FUNC_REF. To read the script from stdin, pass `{STDIN_REF}`: `cat my_app.py | modal run -`",
456
+ ctx,
457
+ )
458
+
438
459
  args[:] = _consume_global_options(ctx, args[:func_ref_index]) + args[func_ref_index:]
439
460
  return click.Group.parse_args(self, ctx, args)
440
461
 
@@ -448,9 +469,23 @@ class RunGroup(ModalGroup):
448
469
  func_ref = cmd_name
449
470
 
450
471
  import_ref = parse_import_ref(func_ref, use_module_mode=ctx.params["m"], command="modal run")
472
+ from_stdin = import_ref.file_or_module == STDIN_REF
473
+ if from_stdin and ctx.params["interactive"]:
474
+ raise ClickException("Interactive mode can't be used when reading a script from stdin.")
451
475
  runnable, all_usable_commands = import_and_filter(
452
- import_ref, base_cmd="modal run", accept_local_entrypoint=True, accept_webhook=False
476
+ import_ref, base_cmd="modal run", accept_local_entrypoint=True, accept_webhook=False, allow_stdin=True
453
477
  )
478
+ if not runnable and from_stdin:
479
+ help_header = (
480
+ "Couldn't determine what to run from the script on stdin. Define a single "
481
+ "`@app.local_entrypoint()`, or save the script to a file and pass `my_app.py::my_function`."
482
+ )
483
+ if all_usable_commands:
484
+ help_footer = "The script has the following functions and local entrypoints:\n"
485
+ help_footer += _get_runnable_list(all_usable_commands)
486
+ else:
487
+ help_footer = "The script has no functions or local entrypoints."
488
+ raise ClickException(f"{help_header}\n\n{help_footer}")
454
489
  if not runnable:
455
490
  help_header = (
456
491
  "Specify a Modal Function or local entrypoint to run. E.g.\n"
@@ -535,6 +570,21 @@ def run(
535
570
  ```
536
571
  modal run -m my_project.my_app
537
572
  ```
573
+
574
+ Pass `-` to read the script from stdin. The script must have a single local
575
+ entrypoint (or a single function):
576
+
577
+ ```
578
+ modal run - <<'EOF'
579
+ import modal
580
+
581
+ app = modal.App()
582
+
583
+ @app.function()
584
+ def hello():
585
+ print("hello from Modal")
586
+ EOF
587
+ ```
538
588
  """
539
589
  ctx.ensure_object(dict)
540
590
  ctx.obj["name"] = name
modal/client.pyi CHANGED
@@ -80,7 +80,7 @@ class _Client:
80
80
  server_url: str,
81
81
  client_type: int,
82
82
  credentials: typing.Optional[tuple[str, str]],
83
- version: str = "1.6.2.dev8",
83
+ version: str = "1.6.2.dev9",
84
84
  *,
85
85
  oauth_credentials: typing.Optional[_OAuthCredentials] = None,
86
86
  ):
@@ -290,7 +290,7 @@ class Client:
290
290
  server_url: str,
291
291
  client_type: int,
292
292
  credentials: typing.Optional[tuple[str, str]],
293
- version: str = "1.6.2.dev8",
293
+ version: str = "1.6.2.dev9",
294
294
  *,
295
295
  oauth_credentials: typing.Optional[_OAuthCredentials] = None,
296
296
  ):
modal/functions.pyi CHANGED
@@ -619,7 +619,7 @@ class Function(
619
619
 
620
620
  _call_generator: ___call_generator_spec
621
621
 
622
- class __remote_spec(typing_extensions.Protocol[P_INNER, ReturnType_INNER]):
622
+ class __remote_spec(typing_extensions.Protocol[ReturnType_INNER, P_INNER]):
623
623
  def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> ReturnType_INNER:
624
624
  """Calls the function remotely, executing it with the given arguments and returning the execution's result.
625
625
 
@@ -644,7 +644,7 @@ class Function(
644
644
  """
645
645
  ...
646
646
 
647
- remote: __remote_spec[modal._functions.P, modal._functions.ReturnType]
647
+ remote: __remote_spec[modal._functions.ReturnType, modal._functions.P]
648
648
 
649
649
  class __remote_gen_spec(typing_extensions.Protocol):
650
650
  def __call__(self, /, *args, **kwargs) -> typing.Generator[typing.Any, None, None]:
@@ -694,7 +694,7 @@ class Function(
694
694
  """
695
695
  ...
696
696
 
697
- class ___experimental_spawn_spec(typing_extensions.Protocol[P_INNER, ReturnType_INNER]):
697
+ class ___experimental_spawn_spec(typing_extensions.Protocol[ReturnType_INNER, P_INNER]):
698
698
  def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
699
699
  """[Experimental] Calls the function with the given arguments, without waiting for the results.
700
700
 
@@ -727,7 +727,7 @@ class Function(
727
727
  """
728
728
  ...
729
729
 
730
- _experimental_spawn: ___experimental_spawn_spec[modal._functions.P, modal._functions.ReturnType]
730
+ _experimental_spawn: ___experimental_spawn_spec[modal._functions.ReturnType, modal._functions.P]
731
731
 
732
732
  class ___spawn_map_inner_spec(typing_extensions.Protocol[P_INNER]):
733
733
  def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> None: ...
@@ -735,7 +735,7 @@ class Function(
735
735
 
736
736
  _spawn_map_inner: ___spawn_map_inner_spec[modal._functions.P]
737
737
 
738
- class __spawn_spec(typing_extensions.Protocol[P_INNER, ReturnType_INNER]):
738
+ class __spawn_spec(typing_extensions.Protocol[ReturnType_INNER, P_INNER]):
739
739
  def __call__(self, /, *args: P_INNER.args, **kwargs: P_INNER.kwargs) -> FunctionCall[ReturnType_INNER]:
740
740
  """Calls the function with the given arguments, without waiting for the results.
741
741
 
@@ -768,7 +768,7 @@ class Function(
768
768
  """
769
769
  ...
770
770
 
771
- spawn: __spawn_spec[modal._functions.P, modal._functions.ReturnType]
771
+ spawn: __spawn_spec[modal._functions.ReturnType, modal._functions.P]
772
772
 
773
773
  @property
774
774
  def _raw_f_(self) -> collections.abc.Callable[..., typing.Any]: ...
modal/types.py CHANGED
@@ -441,6 +441,43 @@ class TokenData:
441
441
  token_secret: str
442
442
 
443
443
 
444
+ @dataclass(frozen=True)
445
+ class ServiceUserInfo:
446
+ """A lightweight dataclass containing metadata about a Modal Service User."""
447
+
448
+ service_user_id: str
449
+ name: str
450
+ token_id: str
451
+ created_by: str
452
+ created_at: datetime
453
+ last_used_at: datetime | None
454
+ expires_at: datetime | None
455
+
456
+ # Environment Name -> Role
457
+ environment_roles: dict[str, str]
458
+
459
+ @classmethod
460
+ def _from_proto(cls, proto: api_pb2.ServiceUser) -> "ServiceUserInfo":
461
+ created_at = datetime.fromtimestamp(proto.created_at, tz=timezone.utc)
462
+ last_used_at = datetime.fromtimestamp(proto.last_used_at, tz=timezone.utc) if proto.last_used_at else None
463
+ expires_at = datetime.fromtimestamp(proto.expires_at, tz=timezone.utc) if proto.expires_at else None
464
+
465
+ environment_roles: dict[str, str] = {}
466
+ for item in proto.environment_roles:
467
+ environment_roles[item.environment_name] = item.role_str
468
+
469
+ return cls(
470
+ service_user_id=proto.service_user_id,
471
+ name=proto.name,
472
+ token_id=proto.token_id,
473
+ created_by=proto.created_by,
474
+ created_at=created_at,
475
+ last_used_at=last_used_at,
476
+ expires_at=expires_at,
477
+ environment_roles=environment_roles,
478
+ )
479
+
480
+
444
481
  @dataclass(frozen=True)
445
482
  class ProxyTokenInfo:
446
483
  """Metadata about a proxy token, not including the token secret."""
modal/workspace.py CHANGED
@@ -9,6 +9,7 @@ from ._workspace import (
9
9
  _WorkspaceBillingManager,
10
10
  _WorkspaceMembersManager,
11
11
  _WorkspaceProxyTokenManager,
12
+ _WorkspaceServiceUserManager,
12
13
  _WorkspaceSettingsManager,
13
14
  )
14
15
 
@@ -17,6 +18,7 @@ WorkspaceMembersManager = synchronize_api(_WorkspaceMembersManager, target_modul
17
18
  WorkspaceBillingManager = synchronize_api(_WorkspaceBillingManager, target_module=__name__)
18
19
  WorkspaceProxyTokenManager = synchronize_api(_WorkspaceProxyTokenManager, target_module=__name__)
19
20
  WorkspaceSettingsManager = synchronize_api(_WorkspaceSettingsManager, target_module=__name__)
21
+ WorkspaceServiceUserManager = synchronize_api(_WorkspaceServiceUserManager, target_module=__name__)
20
22
 
21
23
  __all__ = [
22
24
  "ProxyTokenInfo",
@@ -25,6 +27,7 @@ __all__ = [
25
27
  "WorkspaceMemberInfo",
26
28
  "WorkspaceMembersManager",
27
29
  "WorkspaceProxyTokenManager",
30
+ "WorkspaceServiceUserManager",
28
31
  "WorkspaceSettingsManager",
29
32
  "WorkspaceSettings",
30
33
  ]
modal/workspace.pyi CHANGED
@@ -186,6 +186,15 @@ class Workspace(modal.object.Object):
186
186
  """Namespace for Workspace settings APIs."""
187
187
  ...
188
188
 
189
+ @property
190
+ def service_users(self) -> WorkspaceServiceUserManager:
191
+ """Namespace for managing Service Users in a Workspace.
192
+
193
+ See [the guide](https://modal.com/docs/guide/service-users) for more information about Service
194
+ Users.
195
+ """
196
+ ...
197
+
189
198
  class WorkspaceMembersManager:
190
199
  """mdmd:namespace"""
191
200
  def __init__(self, workspace: Workspace):
@@ -720,3 +729,242 @@ class WorkspaceSettingsManager:
720
729
  ...
721
730
 
722
731
  set: __set_spec
732
+
733
+ class WorkspaceServiceUserManager:
734
+ """mdmd:namespace"""
735
+ def __init__(self, workspace: Workspace):
736
+ """mdmd:hidden"""
737
+ ...
738
+
739
+ class __create_spec(typing_extensions.Protocol):
740
+ def __call__(self, /, name: str, *, expires_in: typing.Optional[int]) -> modal.types.TokenData:
741
+ """Create a new Service User in the current workspace.
742
+
743
+ To call this function, you are required to have Manager permissions in the Workspace.
744
+
745
+ Args:
746
+ name: The name of the new Service User. Must consistent only of alphanumeric, '-', or '_'
747
+ characters.
748
+ expires_in: An expiration time, in seconds, after which the token will stop working. If
749
+ `None`, the token will never expire.
750
+
751
+ Returns:
752
+ A `TokenData` dataclass containing the credentials for the Service User. Note that this
753
+ is the only time you will be able to view these credentials.
754
+
755
+ Examples:
756
+
757
+ ```python notest
758
+ ws = modal.Workspace.from_context()
759
+
760
+ # Creates a Service User named "test-service-user", whose credentials expire after one year.
761
+ service_user_token_data = ws.service_users.create(
762
+ "test-service-user",
763
+ expires_in=datetime.timedelta(days=365).total_seconds(),
764
+ )
765
+ ```
766
+ """
767
+ ...
768
+
769
+ async def aio(self, /, name: str, *, expires_in: typing.Optional[int]) -> modal.types.TokenData:
770
+ """Create a new Service User in the current workspace.
771
+
772
+ To call this function, you are required to have Manager permissions in the Workspace.
773
+
774
+ Args:
775
+ name: The name of the new Service User. Must consistent only of alphanumeric, '-', or '_'
776
+ characters.
777
+ expires_in: An expiration time, in seconds, after which the token will stop working. If
778
+ `None`, the token will never expire.
779
+
780
+ Returns:
781
+ A `TokenData` dataclass containing the credentials for the Service User. Note that this
782
+ is the only time you will be able to view these credentials.
783
+
784
+ Examples:
785
+
786
+ ```python notest
787
+ ws = modal.Workspace.from_context()
788
+
789
+ # Creates a Service User named "test-service-user", whose credentials expire after one year.
790
+ service_user_token_data = ws.service_users.create(
791
+ "test-service-user",
792
+ expires_in=datetime.timedelta(days=365).total_seconds(),
793
+ )
794
+ ```
795
+ """
796
+ ...
797
+
798
+ create: __create_spec
799
+
800
+ class __set_role_spec(typing_extensions.Protocol):
801
+ def __call__(self, /, service_user_name: str, environment_name: str, *, role: str) -> None:
802
+ """Set the role of a specified Service User within an Environment.
803
+
804
+ To call this function, you are required to have Manager permissions in the Workspace.
805
+
806
+ Args:
807
+ service_user_name: The name of the Service User.
808
+ environment_name: The name of the Environment to which the Service User's new role will
809
+ apply.
810
+ role: The access level to grant this Service User. Must be one of the strings `"no-access"`,
811
+ `"viewer"`, or `"contributor"`.
812
+
813
+ Examples:
814
+
815
+ ```python notest
816
+ ws = modal.Workspace.from_context()
817
+ # Grants Service User "test-service-user" the Viewer role in Environment "production"
818
+ ws.service_users.set_role("test-service-user", "production", role="viewer")
819
+
820
+ # Revokes access to "production" from Service User "test-service-user"
821
+ ws.service_users.set_role("test-service-user", "production", role="no-access")
822
+ ```
823
+ """
824
+ ...
825
+
826
+ async def aio(self, /, service_user_name: str, environment_name: str, *, role: str) -> None:
827
+ """Set the role of a specified Service User within an Environment.
828
+
829
+ To call this function, you are required to have Manager permissions in the Workspace.
830
+
831
+ Args:
832
+ service_user_name: The name of the Service User.
833
+ environment_name: The name of the Environment to which the Service User's new role will
834
+ apply.
835
+ role: The access level to grant this Service User. Must be one of the strings `"no-access"`,
836
+ `"viewer"`, or `"contributor"`.
837
+
838
+ Examples:
839
+
840
+ ```python notest
841
+ ws = modal.Workspace.from_context()
842
+ # Grants Service User "test-service-user" the Viewer role in Environment "production"
843
+ ws.service_users.set_role("test-service-user", "production", role="viewer")
844
+
845
+ # Revokes access to "production" from Service User "test-service-user"
846
+ ws.service_users.set_role("test-service-user", "production", role="no-access")
847
+ ```
848
+ """
849
+ ...
850
+
851
+ set_role: __set_role_spec
852
+
853
+ class __info_spec(typing_extensions.Protocol):
854
+ def __call__(self, /, name: str) -> modal.types.ServiceUserInfo:
855
+ """Get information about a specific Service User.
856
+
857
+ To call this function, you are required to have Manager permissions in the Workspace.
858
+
859
+ Args:
860
+ name: The name of the Service User to introspect.
861
+
862
+ Returns:
863
+ A `ServiceUserInfo` dataclass containing information about the Service User.
864
+
865
+ Examples:
866
+
867
+ ```python notest
868
+ ws = modal.Workspace.from_context()
869
+ service_user = ws.service_users.info("test-service-user")
870
+ ```
871
+ """
872
+ ...
873
+
874
+ async def aio(self, /, name: str) -> modal.types.ServiceUserInfo:
875
+ """Get information about a specific Service User.
876
+
877
+ To call this function, you are required to have Manager permissions in the Workspace.
878
+
879
+ Args:
880
+ name: The name of the Service User to introspect.
881
+
882
+ Returns:
883
+ A `ServiceUserInfo` dataclass containing information about the Service User.
884
+
885
+ Examples:
886
+
887
+ ```python notest
888
+ ws = modal.Workspace.from_context()
889
+ service_user = ws.service_users.info("test-service-user")
890
+ ```
891
+ """
892
+ ...
893
+
894
+ info: __info_spec
895
+
896
+ class __list_spec(typing_extensions.Protocol):
897
+ def __call__(self, /) -> list[modal.types.ServiceUserInfo]:
898
+ """List all Service Users in the current workspace.
899
+
900
+ To call this function, you are required to have Manager permissions in the Workspace.
901
+
902
+ Returns:
903
+ A list of `ServiceUserInfo` dataclasses.
904
+
905
+ Examples:
906
+
907
+ ```python notest
908
+ ws = modal.Workspace.from_context()
909
+ for service_user in ws.service_users.list():
910
+ print(service_user.name)
911
+ ```
912
+ """
913
+ ...
914
+
915
+ async def aio(self, /) -> list[modal.types.ServiceUserInfo]:
916
+ """List all Service Users in the current workspace.
917
+
918
+ To call this function, you are required to have Manager permissions in the Workspace.
919
+
920
+ Returns:
921
+ A list of `ServiceUserInfo` dataclasses.
922
+
923
+ Examples:
924
+
925
+ ```python notest
926
+ ws = modal.Workspace.from_context()
927
+ for service_user in ws.service_users.list():
928
+ print(service_user.name)
929
+ ```
930
+ """
931
+ ...
932
+
933
+ list: __list_spec
934
+
935
+ class __delete_spec(typing_extensions.Protocol):
936
+ def __call__(self, /, name: str) -> None:
937
+ """Permanently delete a Service User.
938
+
939
+ To call this function, you are required to have Manager permissions in the Workspace.
940
+
941
+ Args:
942
+ name: The name of the Service User to delete.
943
+
944
+ Examples:
945
+
946
+ ```python notest
947
+ ws = modal.Workspace.from_context()
948
+ ws.service_users.delete("test-service-user")
949
+ ```
950
+ """
951
+ ...
952
+
953
+ async def aio(self, /, name: str) -> None:
954
+ """Permanently delete a Service User.
955
+
956
+ To call this function, you are required to have Manager permissions in the Workspace.
957
+
958
+ Args:
959
+ name: The name of the Service User to delete.
960
+
961
+ Examples:
962
+
963
+ ```python notest
964
+ ws = modal.Workspace.from_context()
965
+ ws.service_users.delete("test-service-user")
966
+ ```
967
+ """
968
+ ...
969
+
970
+ delete: __delete_spec
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modal
3
- Version: 1.6.2.dev8
3
+ Version: 1.6.2.dev9
4
4
  Summary: Python client library for Modal
5
5
  Author-email: Modal Labs <support@modal.com>
6
6
  License-Expression: Apache-2.0
@@ -32,14 +32,14 @@ modal/_tunnel.py,sha256=4M1qLFXvJLV2s_vr5vHXDtGdZr0OUNmXNj1C3lyF4qE,7360
32
32
  modal/_tunnel.pyi,sha256=WVP0dkoN__mM73ZQ-r3nHKCXvYlRMmEWW8iw2xrSY6M,14698
33
33
  modal/_type_manager.py,sha256=DWjgmjYJuOagw2erin506UUbG2H5UzZCFEekS-7hmfA,9087
34
34
  modal/_watcher.py,sha256=Ot1My6fhTp5v0NXR7-ESV8kNQqvpgozrIcvLBtf5r-U,3564
35
- modal/_workspace.py,sha256=IfjcknvmWKVqiltkvHFKVBAKi2EVo-nMOTVKlWCOll4,21849
35
+ modal/_workspace.py,sha256=zZm5eo2JAyj6MYkZD61jl58ne1fp6vok7acmZ1CVl3A,27825
36
36
  modal/app.py,sha256=tAILXi3rk-d2KgdLKGMsB7awShiPBcPfEfiPLn1fGQY,74703
37
37
  modal/app.pyi,sha256=TjcJhoWwZTK2eQ_HCIChU62xSdLi6SvHVQYksy-eZ7w,88565
38
38
  modal/billing.py,sha256=E1-P_P8bJFLp-bTaggYd4BaaViImPB5UdtXiY8VeAZQ,390
39
39
  modal/billing.pyi,sha256=4m7VLYNS8IiJ2I3CJx0awvrOM6BILWRVLfdeqtAYr8M,7189
40
40
  modal/call_graph.py,sha256=XGALIDn1bLchWo_goyX23bcPjzCZcfqKUo8INIfDapo,1775
41
41
  modal/client.py,sha256=cstrL0wpXCZmcvRs7Sy3QRw9Vz8zkZy8NNk0tPe38sk,22852
42
- modal/client.pyi,sha256=5VcbRBy5EfVsMzw0sU9MFtyymwPi6LKigWuAYqzSums,23488
42
+ modal/client.pyi,sha256=MB-HfDpp1QFox_pWh2XDH70EZQlFwGP4jRPYeFZP-hk,23488
43
43
  modal/cloud_bucket_mount.py,sha256=ZOg69dhIFcJcwim4JP-6s1tqwOYAfgS9806jRpspifw,7511
44
44
  modal/cloud_bucket_mount.pyi,sha256=HoPe_NG5jYdVfmTNY-ZJ3-C8Eo_FzJovl9orJRjkGbE,10252
45
45
  modal/cls.py,sha256=qoGJD590GnHHLvVhkn-BMl4ATMrw2Fg_V4evy5ZQbJQ,41784
@@ -56,7 +56,7 @@ modal/environments.pyi,sha256=drmg6yVLjpPhGJ4byOrdBEp2KRLburPrKT-FYtgNPoM,23628
56
56
  modal/exception.py,sha256=L-dUKust6feZzn5qhTVusSAr0IBa4Wa3qIA225IT_lY,12334
57
57
  modal/file_pattern_matcher.py,sha256=CpaNNj7oBlOSewX-AAUZCF8KDxH0_DmgwzfpVGbPYJ4,8138
58
58
  modal/functions.py,sha256=EZRcHFfnoYbvawUJnAHF5nIvoo9GX2Djy7mUmOCXmXc,258
59
- modal/functions.pyi,sha256=SuolW78OayX4pRq8rsIZr7SXUH6Qsf_sPagsB-YCAqE,56516
59
+ modal/functions.pyi,sha256=Ts7fwfZP4JSuq6rkHdeaa3kGjDItYfip5jKoD_fUhZo,56516
60
60
  modal/image.py,sha256=c0lUSAoU-Ip3g5DGZ0uhdCzoWSQWh1g0i-7Rxo-Sz-I,160
61
61
  modal/image.pyi,sha256=R5rdY4P30IEm-F7A2S9CdXa6QYNk-pQwsEun9BKTyLw,61094
62
62
  modal/io_streams.py,sha256=iWwhGCcTwhNtIo2t2f-qVV3FBEK1DIi40Tm_Ai01eYA,32992
@@ -92,11 +92,11 @@ modal/serving.pyi,sha256=nKgt3i2X93NpAAZzIpbj4fiR1TIJxSXnK659w4UD2sE,3962
92
92
  modal/stream_type.py,sha256=A6320qoAAWhEfwOCZfGtymQTu5AfLfJXXgARqooTPvY,417
93
93
  modal/token_flow.py,sha256=1Os7Zw41Fh_YU8CMSWRILDKRlUZcl9pExaX_EDVdBiU,7446
94
94
  modal/token_flow.pyi,sha256=nqs_KHmwM-ssXKeWUTnMVjOgliSzZLl30Tcg6VvMzG0,2605
95
- modal/types.py,sha256=dF7Tm2sV2gmi6Vv7oHzQdzNmVIHgUywIfqy7vYJ-Fh4,36199
95
+ modal/types.py,sha256=LuOQoaDt8T-1i2XOfXzy3Ym1yxHEZ08HTszhGddvCvI,37474
96
96
  modal/volume.py,sha256=wbTVEriIv3djjeUAuUWkLABgG4ppbNMmXLJeV0bev3Q,71117
97
97
  modal/volume.pyi,sha256=Rp2gw_zh8HAAHRbdDkF782tttQfyv3uzSriO-zpMXDU,67350
98
- modal/workspace.py,sha256=_phlb1Bxie_KR1Y9atBzkB21Q_qmRztf1JLzQYdK0qk,988
99
- modal/workspace.pyi,sha256=X3wZ5GWrIpxJVxya4NDKvzdxJqGRhsoc1wNgKSMOySg,26497
98
+ modal/workspace.py,sha256=83AGrCXEN1-QhC6XfQusgWO50GOIJX_c1QKsF52wjdA,1157
99
+ modal/workspace.pyi,sha256=S7QwyBm0wzQgR6lToTvSAKD2AdSLo0e8UbBS8TPlckU,35519
100
100
  modal/_output/__init__.py,sha256=xtGN6SPv2zvByrJ32JPao0yJKpxyCIZ-2JMTScrisuQ,28
101
101
  modal/_output/manager.py,sha256=DqEguniI8uWMFUZFX4U4gsCFpio1zQeWjJhJC_GZhi4,18286
102
102
  modal/_output/pty.py,sha256=ngkKVpU8zDOxg94LiWYmdwXavd305HQDXzjWGrHQBIM,10408
@@ -175,12 +175,12 @@ modal/cli/entry_point.py,sha256=Sy9w9C2RHG9XDalJ0Fjwr4yQc4dTEL9gVNQuDrj3woI,5050
175
175
  modal/cli/environment.py,sha256=rKnKQFsbcLXjBtYWLFRqhP1NeCjMnqvSPci7Md4ZjIM,18377
176
176
  modal/cli/function.py,sha256=gyY7cgwfxZfNRwyO1X4I1XK8xL97heoEp7CuVwPrRoI,57624
177
177
  modal/cli/image.py,sha256=Ve-PDT4XTH9KEQrZxvUc2ocAW4mLI5QfwQssaajK4MI,8073
178
- modal/cli/import_refs.py,sha256=gxoogHVixec1-qj_FUwhWQXqjy9yvqYCNuAYWCCFEWk,15994
178
+ modal/cli/import_refs.py,sha256=cI9njDM4alDawlgAGsFLBQ6eP7K06aFHOp0-K7OSd_8,17093
179
179
  modal/cli/logo.py,sha256=plv82syvPb8j3qrR1A_nojZwp823t3VEXaDlrx1jkt0,3221
180
180
  modal/cli/network_file_system.py,sha256=xNvau_6fziIfbPIlVGAh1-wOGVCNko28GweAjO51LCU,7681
181
181
  modal/cli/profile.py,sha256=JbpSo5bcK2gdVx3QDrGWwnfRRG-_QtrsLAaQXnwh4K0,4782
182
182
  modal/cli/queues.py,sha256=cpoza1mEwupQoaBy7kaTqsTaWPto9tHRQrOeLXxZAUU,6951
183
- modal/cli/run.py,sha256=rzLG_eDO4uxcIxPQsz_PbGe8MZTcPNzA3p83HDFEcUk,24508
183
+ modal/cli/run.py,sha256=rkAsn4aDa80JjMj1rwGwrVdlkJkazclSyvar7YSmi3Y,26410
184
184
  modal/cli/secret.py,sha256=lckWyas1J3uQm1f8D9nkWlRlmToNzmy5a-0q4IsJFCc,8254
185
185
  modal/cli/selector.py,sha256=OJr9Ua3K_l-qu3N3-I8z8oVq8lBakws2-XgfheR5p-c,4741
186
186
  modal/cli/server.py,sha256=H0u3u9S-DARMFKdYuvWJcu5s8egOQYxvRr79X_Lceeg,49723
@@ -207,7 +207,7 @@ modal/sandbox/_task_command_router_client.py,sha256=qhFXy8eyGIxwxRFZkTsxJVxsAc8c
207
207
  modal/sandbox/sandbox.py,sha256=4ekghND9qUGf5wtIQH4mVa6PHGjHgY0UN5RKryOM05k,683
208
208
  modal/sandbox/sandbox.pyi,sha256=HYxopAUYMfMEVMWgzeb4qPATPFzLkTCnqpSl9lI-3ac,150321
209
209
  modal/skills/modal/SKILL.md,sha256=Bm-0BPTYppJoeQzA-N-Re8L6-nKnV6gspJXMl4cD0P0,5490
210
- modal-1.6.2.dev8.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
210
+ modal-1.6.2.dev9.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
211
211
  modal_docs/__init__.py,sha256=svYKtV8HDwDCN86zbdWqyq5T8sMdGDj0PVlzc2tIxDM,28
212
212
  modal_docs/gen_cli_docs.py,sha256=9-b8vl2EsLWD9zJqpCK8IUi5h44Bjn3i3rSdedZV4bA,6415
213
213
  modal_docs/gen_cli_docs_main.py,sha256=UPGr7O1DYTIRLwfINe2rbdh89J3cPVTU1OWL-SjxnOQ,198
@@ -231,10 +231,10 @@ modal_proto/task_command_router_pb2.py,sha256=ysC0d8p3YxwyOpP3B-qDlvE81Yo4ntQiwi
231
231
  modal_proto/task_command_router_pb2.pyi,sha256=FDcd5t3ZCmQHUjefOzg07iglrgKYcBrzFvdKIWsEMHI,50628
232
232
  modal_proto/task_command_router_pb2_grpc.py,sha256=8iGUGwEVbqOsZWPJ7OsQ9OKUGaSCf9Dr2tvb04Ww6d4,44620
233
233
  modal_proto/task_command_router_pb2_grpc.pyi,sha256=26Fq9RQo09B9KLHsgdpRuw-I6Z4-2jrXLQkuDzB-moI,15097
234
- modal_version/__init__.py,sha256=WsuSyNuz9p14Rv35_HGOr5gTGppmiBErxZvIpLsh-Y4,120
234
+ modal_version/__init__.py,sha256=BO-DM7wsEgysII6-KveacoC7VbNzkiPdH-MGsOiTomQ,120
235
235
  modal_version/__main__.py,sha256=nLUbubxKx7GXNzJIkTB7M7_u8080LyLM0IS0rzFkC_c,119
236
- modal-1.6.2.dev8.dist-info/METADATA,sha256=Ra0MKB3MFjRNZdmVPh0Mc-HvN-Uw8yTC1onPfOiu-K0,2512
237
- modal-1.6.2.dev8.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
238
- modal-1.6.2.dev8.dist-info/entry_points.txt,sha256=An-wYgeEUnm6xzrAP9_NTSTSciYvvEWsMZILtYrvpAI,46
239
- modal-1.6.2.dev8.dist-info/top_level.txt,sha256=4BWzoKYREKUZ5iyPzZpjqx4G8uB5TWxXPDwibLcVa7k,43
240
- modal-1.6.2.dev8.dist-info/RECORD,,
236
+ modal-1.6.2.dev9.dist-info/METADATA,sha256=m8MgmkSOJS_QswrCMRdd_b-t8D2lh7Ws830RJPwVup0,2512
237
+ modal-1.6.2.dev9.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
238
+ modal-1.6.2.dev9.dist-info/entry_points.txt,sha256=An-wYgeEUnm6xzrAP9_NTSTSciYvvEWsMZILtYrvpAI,46
239
+ modal-1.6.2.dev9.dist-info/top_level.txt,sha256=4BWzoKYREKUZ5iyPzZpjqx4G8uB5TWxXPDwibLcVa7k,43
240
+ modal-1.6.2.dev9.dist-info/RECORD,,
modal_version/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # Copyright Modal Labs 2026
2
2
  """Supplies the current version of the modal client library."""
3
3
 
4
- __version__ = "1.6.2.dev8"
4
+ __version__ = "1.6.2.dev9"