Home / Function/ get_from_dict_or_env() — langchain Function Reference

get_from_dict_or_env() — langchain Function Reference

Architecture documentation for the get_from_dict_or_env() function in env.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8809afec_6c7d_4fe4_44c9_83395cf2857e["get_from_dict_or_env()"]
  359da5b8_85a8_468a_12ae_f45ea1dc33e4["env.py"]
  8809afec_6c7d_4fe4_44c9_83395cf2857e -->|defined in| 359da5b8_85a8_468a_12ae_f45ea1dc33e4
  9b8a91b5_11cc_2313_0a45_c3f33f349687["get_from_env()"]
  8809afec_6c7d_4fe4_44c9_83395cf2857e -->|calls| 9b8a91b5_11cc_2313_0a45_c3f33f349687
  style 8809afec_6c7d_4fe4_44c9_83395cf2857e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/utils/env.py lines 26–57

def get_from_dict_or_env(
    data: dict[str, Any],
    key: str | list[str],
    env_key: str,
    default: str | None = None,
) -> str:
    """Get a value from a dictionary or an environment variable.

    Args:
        data: The dictionary to look up the key in.
        key: The key to look up in the dictionary.

            This can be a list of keys to try in order.
        env_key: The environment variable to look up if the key is not
            in the dictionary.
        default: The default value to return if the key is not in the dictionary
            or the environment.

    Returns:
        The dict value or the environment variable value.
    """
    if isinstance(key, (list, tuple)):
        for k in key:
            if value := data.get(k):
                return str(value)

    if isinstance(key, str) and key in data and data[key]:
        return str(data[key])

    key_for_err = key[0] if isinstance(key, (list, tuple)) else key

    return get_from_env(key_for_err, env_key, default=default)

Domain

Subdomains

Frequently Asked Questions

What does get_from_dict_or_env() do?
get_from_dict_or_env() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/env.py.
Where is get_from_dict_or_env() defined?
get_from_dict_or_env() is defined in libs/core/langchain_core/utils/env.py at line 26.
What does get_from_dict_or_env() call?
get_from_dict_or_env() calls 1 function(s): get_from_env.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free