code: def client(env_name: Optional[str] = None) -> Client:
      """
      Initialize a client based on the specified environment. If no environment is specified, it will attempt to use the default environment.
  
      Args:
          env_name: Name of the environment to use.
  
      Returns:
          Cortex client that can be used to deploy and manage APIs in the specified environment.
      """
      environments = env_list()
  
      if env_name is None:
          if not environments.get("default_environment"):
              raise NotFound("no default environment configured")
          env_name = environments["default_environment"]
  
      found = False
      for environment in environments["environments"]:
          if environment["name"] == env_name:
              found = True
              break
      if not found:
          raise NotFound(
              f"can't find environment {env_name}, create one by calling `cortex.new_client()`"
          )
  
      return Client(environment)
  
file_path: cortex/python/client/cortex/__init__.py
imports: import json
  from typing import Optional, List
  from cortex.binary import run_cli
  from cortex.client import Client
  from cortex.exceptions import NotFound
  from cortex.telemetry import sentry_wrapper
label_desc: Use image node_id 1 for calling a global function with example usage: client(env_name) and returns: Client