modal.Environment

class Environment(modal.object.Object)

hydrate 

def hydrate(self, client: Optional[_Client] = None) -> Self:

Synchronize the local object with its identity on the Modal server.

It is rarely necessary to call this method explicitly, as most operations will lazily hydrate when needed. The main use case is when you need to access object metadata, such as its ID.

Added in v0.72.39: This method replaces the deprecated .resolve() method.

name 

@property
def name(self) -> Optional[str]:

objects 

objects: EnvironmentManager

Namespace with methods for managing Environment objects.

objects.create 

def create(
    self,
    name: str,  # Name to use for the new Environment
    *,
    restricted: bool = False,  # If True, enable RBAC restrictions on the Environment
    client: Optional[_Client] = None,  # Optional client with Modal credentials
) -> None:

Create a new Environment.

Examples:

modal.Environment.objects.create("my-environment")

objects.list 

def list(
    self,
    *,
    client: Optional[_Client] = None,  # Optional client with Modal credentials
) -> builtins.list["_Environment"]:

Return a list of hydrated Environment objects.

Examples:

environments = modal.Environment.objects.list()
print([e.name for e in environments])

objects.delete 

def delete(
    self,
    name: str,  # Name of the Environment to delete
    *,
    client: Optional[_Client] = None,  # Optional client with Modal credentials
) -> None:

Delete a named Environment.

Warning: This is irreversible and will transitively delete all objects in the Environment.

Examples:

modal.Environment.objects.delete("my-environment")

members 

members: EnvironmentMembersManager

Namespace with methods for managing the membership of a restricted Environment.

See https://modal.com/docs/guide/rbac for more information on restricted Environments.

members.list 

async def list(self) -> dict[Literal["users", "service_users"], dict[str, MemberRole]]:

Return the members of a restricted Environment with their roles.

Examples:

members = modal.Environment.from_name("my-restricted-env").members.list()
print(members)
# {
#     "users": {"alice": "contributor", "bob": "viewer"},
#     "service_users": {"alice-bot": "contributor"},
# }

members.update 

async def update(
    self,
    *,
    users: Optional[Mapping[str, MemberRole]] = None,
    service_users: Optional[Mapping[str, MemberRole]] = None,
) -> None:

Add or modify roles for members of a restricted Environment.

Each user or service user will be added to the Environment if not currently a member; if already a member, the user or service user’s role will be updated.

Examples:

env = modal.Environment.from_name("my-restricted-env")
env.members.update(
    users={"alice": "contributor", "bob": "viewer"},
    service_users={"alice-bot": "contributor"},
)

members.remove 

async def remove(
    self,
    *,
    users: Optional[Iterable[str]] = None,
    service_users: Optional[Iterable[str]] = None,
) -> None:

Remove members from a restricted Environment.

Examples:

env = modal.Environment.from_name("my-restricted-env")
env.members.remove(
    users=["alice"],
    service_users=["alice-bot"],
)

from_context 

@staticmethod
def from_context(*, client: Optional[_Client] = None) -> "_Environment":

Look up an Environment object using the current context.

This method returns the Environment that is defined by the local configuration (i.e., your active profile or the MODAL_ENVIRONMENT environment variable), or it fetches the default environment from the server when not defined locally. If called inside a Modal container, it will return the Environment that container is associated with.

from_name 

@staticmethod
def from_name(
    name: str,
    *,
    create_if_missing: bool = False,
    client: Optional[_Client] = None,
) -> "_Environment":

Look up an Environment object using its name.