Home / Function/ get_from_env() — langchain Function Reference

get_from_env() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/langchain_core/utils/env.py lines 60–86

def get_from_env(key: str, env_key: str, default: str | None = None) -> str:
    """Get a value from a dictionary or an environment variable.

    Args:
        key: The key to look up in the dictionary.
        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 value of the key.

    Raises:
        ValueError: If the key is not in the dictionary and no default value is
            provided or if the environment variable is not set.
    """
    if env_value := os.getenv(env_key):
        return env_value
    if default is not None:
        return default
    msg = (
        f"Did not find {key}, please add an environment variable"
        f" `{env_key}` which contains it, or pass"
        f" `{key}` as a named parameter."
    )
    raise ValueError(msg)

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free