The Modal client object is used to interact with the Modal API.
The Client is not intended to be instantiated directly by users in most cases. Modal automatically manages client instances.
Factory methods
Client.from_env
modal.Client.from_env() -> Client
Create a client from environment configuration.
This is the standard way to get a Modal client. It uses credentials from the Modal config file or environment variables.
The Modal client instance.
Example:
client = modal.Client.from_env()
Client.from_credentials
modal.Client.from_credentials(
token_id: str,
token_secret: str,
) -> Client
Constructor based on token credentials.
Useful for managing Modal on behalf of third-party users.
The Modal client instance.
Example:
client = modal.Client.from_credentials("my_token_id", "my_token_secret")
modal.Sandbox.create("echo", "hi", client=client, app=app)
Context manager usage
The Client can be used as an async context manager:
async with modal.Client.from_env() as client:
# Use client
pass
Properties
client.stub
client.stub -> ModalClientModal
The default stub for making RPC calls to Modal servers.
This is an internal property primarily used by Modal’s implementation.