LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coreutilsutilsfrom_env
    Function●Since v0.2

    from_env

    Create a factory method that gets a value from an environment variable.

    Copy
    from_env(
      key: str | Sequence[str],
      ,
      *,
      default: str | _NoDefaultType | None = _NoDefault,
      error_message: str | None = None
    ) -> Callable[[], str] | Callable[[], str | None]

    Parameters

    NameTypeDescription
    key*str | Sequence[str]

    The environment variable to look up.

    If a list of keys is provided, the first key found in the environment will be used. If no key is found, the default value will be used if set, otherwise an error will be raised.

    defaultstr | _NoDefaultType | None
    Default:_NoDefault

    The default value to return if the environment variable is not set.

    error_messagestr | None
    Default:None

    The error message which will be raised if the key is not found and no default value is provided.

    This will be raised as a ValueError.

    View source on GitHub