diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb216fa --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# ComfyUI-EnvVariable + +Minimal ComfyUI custom node that reads an environment variable by key and outputs it as a string. + +## Node + +- Name: `Environment Variable` +- Input: `key` (STRING) +- Output: `value` (STRING) + +At runtime, the node returns the value of `os.environ[key]` if it exists, otherwise an empty string. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..bed6e4d --- /dev/null +++ b/__init__.py @@ -0,0 +1,9 @@ +from .env_variable_node import EnvVariableNode + +NODE_CLASS_MAPPINGS = { + "EnvVariable": EnvVariableNode, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "EnvVariable": "Environment Variable", +} diff --git a/env_variable_node.py b/env_variable_node.py new file mode 100644 index 0000000..bad7c40 --- /dev/null +++ b/env_variable_node.py @@ -0,0 +1,24 @@ +class EnvVariableNode: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "key": ( + "STRING", + { + "default": "OPENAI_API_KEY", + "multiline": False, + }, + ), + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("value",) + FUNCTION = "get_value" + CATEGORY = "utils" + + def get_value(self, key): + import os + + return (os.environ.get(key, ""),)