Secret

Secrets such as provider keys and environment variables can be set when defining compute. These are set at launch time and accessible during the scope of your program.

Factory Method

kubetorch.secret(name: str | None = None, provider: str | None = None, path: str | None = None, env_vars: Dict | None = None, namespace: str | None = 'default', override: bool | None = False) Secret

Builds an instance of Secret. At most one of provider, path, or env_vars can be provided, to maintain one source of truth. For a provider, the values are inferred from the default path or environment variables for that provider. To load a secret by name, provide its name and namespace.

Parameters:
  • namespace (str, optional) – Namespace to load the secret from, if we create a secret from name. Default: “default”.

  • name (str, optional) – Name to assign the resource. If none is provided, resource name defaults to the provider name.

  • provider (str, optional) – Provider corresponding to the secret (e.g. “aws”, “gcp”). To see all supported provider types, run kt.Secret.builtin_providers(as_str=True).

  • path (str, optional) – Path where the secret values are held.

  • env_vars (Dict, optional) – Dictionary mapping secret keys to the corresponding environment variable key.

  • override (Bool, optional) – If True, override the secret’s values in Kubernetes if a secret with the same name already exists.

Returns:

The resulting secret object.

Return type:

Secret

Examples:

import kubetorch as kt local_secret = kt.secret(name="in_memory_secret", values={"secret_key": "secret_val"}) aws_secret = kt.secret(provider="aws") gcp_secret = kt.secret(name="my-gcp-secret", path="~/.gcp/credentials") lambda_secret = kt.secret(name= "my-lambda-secret", env_vars={"api_key": "LAMBDA_API_KEY"})

Class

class kubetorch.Secret(name: str | None = None, provider: str | None = None, values: Dict | None = None, path: str | None = None, env_vars: Dict | None = None, override: bool = False, **kwargs)
__init__(name: str | None = None, provider: str | None = None, values: Dict | None = None, path: str | None = None, env_vars: Dict | None = None, override: bool = False, **kwargs)

Secret class. Built-in provider classes contain default path and/or environment variable mappings, based on it’s expected usage.

Note

Currently supported built-in providers: anthropic, aws, azure, gcp, github, huggingface, lambda, langchain, openai, pinecone, ssh, wandb.

Parameters:
  • name (str, optional) – Name to assign the Kubetorch secret.

  • provider (str, optional) – Provider corresponding to the secret (e.g. “aws”, “gcp”).

  • values (Dict, optional) – Dictionary mapping secret keys to the corresponding secret values.

  • path (str, optional) – Path where the secret values are held.

  • env_vars (Dict, optional) – Dictionary mapping secret keys to the corresponding environment variable key.

  • override (bool, optional) – If True, override the secret’s values in Kubernetes if a secret with the same name already exists.

property name

Name of the secret.

property override

Should we override secret’s values in Kubernetes if a secret with the same name already exists

property values

Secret values.

classmethod builtin_providers(as_str: bool = False) List

Return list of all Kubetorch providers (as class objects) supported out of the box.

Parameters:

as_str (bool, optional) – Whether to return the providers as a string or as a class. (Default: False)

classmethod from_provider(provider: str, name: str | None = None, path: str | None = None, override: bool = False)

Return kubetorch provider secret object

Parameters:
  • provider (str) – Provider’s name

  • name (str, Optional) – Secret name

  • path (str, optional) – Path where the secret values are held.

  • override (Bool, optional) – If True, override the secret’s values in Kubernetes if a secret with the same name already exists.

classmethod from_path(path: str, name: str | None = None, override: bool = False)

Return kubetorch provider secret object

Parameters:
  • path (str) – Local path to the secret values file

  • name (str, Optional) – Secret name

  • override (Bool, optional) – If True, override the secret’s values in Kubernetes if a secret with the same name already exists.

classmethod from_env(env_vars: dict, name: str | None = None, override: bool = False)

Return kubetorch provider secret object

Parameters:
  • env_vars (dict) – Dictionary mapping secret keys to the corresponding

  • key. (environment variable) –

  • name (str, Optional) – Secret name

  • override (Bool, optional) – If True, override the secret’s values in Kubernetes if a secret with the same name already exists.