跳到主要内容

环境变量

Langflow 允许您使用环境变量配置多项设置。

配置环境变量

Langflow 从以下来源识别支持的环境变量

  • 您在终端中设置的环境变量。
  • 您使用 Langflow CLI 中的 --env-file 选项从 .env 文件导入的环境变量。

您可以选择专门使用一个来源,或者将两个来源一起使用。 如果您选择将两个来源一起使用,请注意从 .env 文件导入的环境变量比您在终端中设置的环境变量具有更高的优先级

在终端中设置环境变量

运行以下命令为当前终端会话设置环境变量:


_10
export VARIABLE_NAME='VALUE'

当您启动 Langflow 时,它会查找您在终端中设置的环境变量。 如果它检测到支持的环境变量,则会自动采用指定的值,遵循优先级规则

从 .env 文件导入环境变量

  1. 如果 Langflow 正在运行,请退出 Langflow。

  2. 创建 .env 文件,然后在您首选的编辑器中打开它。

  3. .env 文件中定义 Langflow 环境变量。例如:


    _30
    DO_NOT_TRACK=true
    _30
    LANGFLOW_AUTO_LOGIN=false
    _30
    LANGFLOW_AUTO_SAVING=true
    _30
    LANGFLOW_AUTO_SAVING_INTERVAL=1000
    _30
    LANGFLOW_BACKEND_ONLY=false
    _30
    LANGFLOW_BUNDLE_URLS=["https://github.com/user/repo/commit/hash"]
    _30
    LANGFLOW_CACHE_TYPE=async
    _30
    LANGFLOW_COMPONENTS_PATH=/path/to/components/
    _30
    LANGFLOW_CONFIG_DIR=/path/to/config/
    _30
    LANGFLOW_DATABASE_URL=postgresql://user:password@localhost:5432/langflow
    _30
    LANGFLOW_DEV=false
    _30
    LANGFLOW_FALLBACK_TO_ENV_VAR=false
    _30
    LANGFLOW_HEALTH_CHECK_MAX_RETRIES=5
    _30
    LANGFLOW_HOST=localhost
    _30
    LANGFLOW_LANGCHAIN_CACHE=InMemoryCache
    _30
    LANGFLOW_MAX_FILE_SIZE_UPLOAD=10000
    _30
    LANGFLOW_MAX_ITEMS_LENGTH=100
    _30
    LANGFLOW_MAX_TEXT_LENGTH=1000
    _30
    LANGFLOW_LOG_LEVEL=error
    _30
    LANGFLOW_OPEN_BROWSER=false
    _30
    LANGFLOW_PORT=7860
    _30
    LANGFLOW_REMOVE_API_KEYS=false
    _30
    LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true
    _30
    LANGFLOW_SECRET_KEY=somesecretkey
    _30
    LANGFLOW_STORE=true
    _30
    LANGFLOW_STORE_ENVIRONMENT_VARIABLES=true
    _30
    LANGFLOW_SUPERUSER=adminuser
    _30
    LANGFLOW_SUPERUSER_PASSWORD=adminpass
    _30
    LANGFLOW_WORKER_TIMEOUT=60000
    _30
    LANGFLOW_WORKERS=3

    有关其他示例,请参阅 Langflow 仓库中的 .env.example 文件。

  4. 保存并关闭 .env

  5. 使用您的 .env 文件启动 Langflow:


    _10
    python -m langflow run --env-file .env

    如果您的 .env 文件不在同一目录中,请提供您的 .env 文件的路径。

在启动时,Langflow 从您的 .env 文件以及您在终端中设置的任何环境变量导入环境变量,并采用它们指定的值。

优先级

您可以在终端、.env 中以及使用 Langflow CLI 选项 设置 Langflow 环境变量。

如果环境变量在多个位置设置,适用以下层次结构:

  1. Langflow CLI 选项覆盖 .env 和终端变量。
  2. .env 覆盖终端变量。
  3. 只有在 .env 或 Langflow CLI 选项中未设置变量时,才使用终端变量。

例如,如果您在 .env 和终端中都设置了 LANGFLOW_PORT,则 Langflow 使用 .env 中的值。 同样,如果您使用 --port 运行 Langflow CLI 命令,则 Langflow 使用该端口号而不是 .env 中的 LANGFLOW_PORT

支持的环境变量

下表列出了 Langflow 支持的环境变量。

变量格式默认值描述
DO_NOT_TRACKBooleanfalse如果启用此选项,Langflow 不会跟踪遥测数据。
LANGFLOW_AUTO_LOGINBooleantrue为 Langflow 启用自动登录。设置为 false 可禁用自动登录并需要登录表单来登录 Langflow UI。设置为 false 需要设置 LANGFLOW_SUPERUSERLANGFLOW_SUPERUSER_PASSWORD。有关更多信息,请参阅身份验证
LANGFLOW_AUTO_SAVINGBooleantrue启用 flow 自动保存。
参阅 --auto-saving 选项
LANGFLOW_AUTO_SAVING_INTERVALInteger1000设置 flow 自动保存的间隔(毫秒)。
参阅 --auto-saving-interval 选项
LANGFLOW_BACKEND_ONLYBooleanfalse仅运行 Langflow 的后端服务器(无前端)。
参阅 --backend-only 选项
LANGFLOW_BUNDLE_URLSList[String][]A list of URLs from which to load component bundles and flows. Supports GitHub URLs. If LANGFLOW_AUTO_LOGIN is enabled, flows from these bundles are loaded into the database.
LANGFLOW_CACHE_TYPEStringasyncSet the cache type for Langflow. Possible values: async, redis, memory, disk.
If you set the type to redis, then you must also set the following environment variables: LANGFLOW_REDIS_HOST, LANGFLOW_REDIS_PORT, LANGFLOW_REDIS_DB, and LANGFLOW_REDIS_CACHE_EXPIRE.
LANGFLOW_COMPONENTS_PATHStringlangflow/componentsPath to the directory containing custom components.
See --components-path option.
LANGFLOW_CONFIG_DIRStringSee descriptionSet the Langflow configuration directory where files, logs, and the Langflow database are stored. Defaults:
macOS Desktop cache: /Users/<username>/.langflow/cache
Windows Desktop cache: C:\Users\<username>\AppData\Roaming\com.Langflow\cache
OSS macOS/Windows/Linux/WSL (uv pip install) cache: <path_to_venv>/lib/python3.12/site-packages/langflow/cache
OSS macOS/Windows/Linux/WSL (git clone) cache: <path_to_clone>/src/backend/base/langflow/cache
LANGFLOW_DATABASE_URLStringNot setSet the database URL for Langflow. If not provided, Langflow uses a SQLite database.
LANGFLOW_USE_NOOP_DATABASEBooleanfalseUse a no-op database, which avoids database connections and operations. Useful for running flows without a database.
LANGFLOW_DATABASE_CONNECTION_RETRYBooleanfalseIf True, Langflow tries to connect to the database again if it fails.
LANGFLOW_DB_POOL_SIZEInteger10DEPRECATED: Use LANGFLOW_DB_CONNECTION_SETTINGS instead. The number of connections to keep open in the connection pool.
LANGFLOW_DB_MAX_OVERFLOWInteger20DEPRECATED: Use LANGFLOW_DB_CONNECTION_SETTINGS instead. The number of connections to allow that can be opened beyond the pool size.
LANGFLOW_DB_CONNECT_TIMEOUTInteger20The number of seconds to wait before giving up on a lock to be released or establishing a connection to the database.
LANGFLOW_DB_CONNECTION_SETTINGSJSONNot setA JSON dictionary to centralize database connection parameters. Example: {"pool_size": 10, "max_overflow": 20}
LANGFLOW_DISABLE_TRACK_APIKEY_USAGEBooleanfalseIf set to true, disables tracking of API key usage (total_uses and last_used_at) to avoid database contention under high concurrency.
LANGFLOW_ENABLE_LOG_RETRIEVALBooleanfalseEnable log retrieval functionality.
LANGFLOW_FALLBACK_TO_ENV_VARBooleantrueIf enabled, global variables set in the Langflow UI fall back to an environment variable with the same name when Langflow fails to retrieve the variable value.
LANGFLOW_FRONTEND_PATHString./frontendPath to the frontend directory containing build files. This is for development purposes only.
See --frontend-path option.
LANGFLOW_HEALTH_CHECK_MAX_RETRIESInteger5Set the maximum number of retries for the health check.
See --health-check-max-retries option.
LANGFLOW_HOSTStringlocalhostThe host on which the Langflow server will run.
See --host option.
LANGFLOW_LANGCHAIN_CACHEStringInMemoryCacheType of cache to use. Possible values: InMemoryCache, SQLiteCache.
See --cache option.
LANGFLOW_LOG_LEVELStringINFOSet the logging level for Langflow. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL.
LANGFLOW_LOG_FILEStringNot setPath to the log file. If this option is not set, logs are written to stdout.
LANGFLOW_LOG_RETRIEVER_BUFFER_SIZEInteger10000Set the buffer size for log retrieval. Only used if LANGFLOW_ENABLE_LOG_RETRIEVAL is enabled.
LANGFLOW_MAX_FILE_SIZE_UPLOADInteger100Set the maximum file size for the upload in megabytes.
See --max-file-size-upload option.
LANGFLOW_MAX_ITEMS_LENGTHInteger100Maximum number of items to store and display in the UI. Lists longer than this will be truncated when displayed in the UI. Does not affect data passed between components nor outputs.
LANGFLOW_MAX_TEXT_LENGTHInteger1000Maximum number of characters to store and display in the UI. Responses longer than this will be truncated when displayed in the UI. Does not truncate responses between components nor outputs.
LANGFLOW_MCP_SERVER_ENABLEDBooleantrueIf this option is set to False, Langflow does not enable the MCP server.
LANGFLOW_MCP_SERVER_ENABLE_PROGRESS_NOTIFICATIONSBooleanfalseIf this option is set to True, Langflow sends progress notifications in the MCP server.
LANGFLOW_NEW_USER_IS_ACTIVEBooleanfalseWhen enabled, new users are automatically activated and can log in without requiring explicit activation by the superuser.
LANGFLOW_OPEN_BROWSERBooleanfalseOpen the system web browser on startup.
See --open-browser option.
LANGFLOW_PORTInteger7860The port on which the Langflow server runs. The server automatically selects a free port if the specified port is in use.
See --port option.
LANGFLOW_PROMETHEUS_ENABLEDBooleanfalseExpose Prometheus metrics.
LANGFLOW_PROMETHEUS_PORTInteger9090Set the port on which Langflow exposes Prometheus metrics.
LANGFLOW_REDIS_CACHE_EXPIREInteger3600See LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_DBInteger0See LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_HOSTStringlocalhostSee LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_PORTString6379See LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_PASSWORDStringNot setPassword for Redis authentication when using Redis cache type.
LANGFLOW_REMOVE_API_KEYSBooleanfalseRemove API keys from the projects saved in the database.
See --remove-api-keys option.
LANGFLOW_SAVE_DB_IN_CONFIG_DIRBooleanfalseSave the Langflow database in LANGFLOW_CONFIG_DIR instead of in the Langflow package directory. Note, when this variable is set to default (false), the database isn't shared between different virtual environments and the database is deleted when you uninstall Langflow.
LANGFLOW_SECRET_KEYStringAuto-generatedKey used for encrypting sensitive data like API keys. If a key is not provided, a secure key is auto-generated. For production environments with multiple instances, you should explicitly set this to ensure consistent encryption across instances.
LANGFLOW_STOREBooleantrueEnable the Langflow Store.
See --store option.
LANGFLOW_STORE_ENVIRONMENT_VARIABLESBooleantrueStore environment variables as global variables in the database.
LANGFLOW_CREATE_STARTER_PROJECTSBooleantrueIf this option is enabled, Langflow creates starter projects during initialization. Set to false to skip all starter project creation and updates.
LANGFLOW_UPDATE_STARTER_PROJECTSBooleantrueIf this option is enabled, Langflow updates starter projects with the latest component versions when initializing.
LANGFLOW_SUPERUSERStringlangflowSet the name for the superuser. Required if LANGFLOW_AUTO_LOGIN is set to false.
See superuser --username option.
LANGFLOW_SUPERUSER_PASSWORDStringlangflowSet the password for the superuser. Required if LANGFLOW_AUTO_LOGIN is set to false.
See superuser --password option.
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENTStringNot setComma-separated list of environment variables to get from the environment and store as global variables.
LANGFLOW_LOAD_FLOWS_PATHStringNot setPath to a directory containing flow JSON files to be loaded on startup. Note that this feature only works if LANGFLOW_AUTO_LOGIN is enabled.
LANGFLOW_WORKER_TIMEOUTInteger300Worker timeout in seconds.
See --worker-timeout option.
LANGFLOW_WORKERSInteger1Number of worker processes.
See --workers option.
LANGFLOW_SSL_CERT_FILEStringNot setPath to the SSL certificate file on the local system.
LANGFLOW_SSL_KEY_FILEStringNot setPath to the SSL key file on the local system.
LANGFLOW_SKIP_AUTH_AUTO_LOGINBooleantrueIf set to true, and LANGFLOW_AUTO_LOGIN is set to true, skips authentication and allows automatic login as the superuser. If set to false, and LANGFLOW_AUTO_LOGIN is set to true, disables automatic login and enforces authentication. If LANGFLOW_AUTO_LOGIN is false, has no effect.

Configure .env, override.conf, and tasks.json files

The following examples show how to configure Langflow using environment variables in different scenarios.

The .env file is a text file that contains key-value pairs of environment variables.

Create or edit a file named .env in your project root directory and add your configuration:


_30
DO_NOT_TRACK=true
_30
LANGFLOW_AUTO_LOGIN=false
_30
LANGFLOW_AUTO_SAVING=true
_30
LANGFLOW_AUTO_SAVING_INTERVAL=1000
_30
LANGFLOW_BACKEND_ONLY=false
_30
LANGFLOW_BUNDLE_URLS=["https://github.com/user/repo/commit/hash"]
_30
LANGFLOW_CACHE_TYPE=async
_30
LANGFLOW_COMPONENTS_PATH=/path/to/components/
_30
LANGFLOW_CONFIG_DIR=/path/to/config/
_30
LANGFLOW_DATABASE_URL=postgresql://user:password@localhost:5432/langflow
_30
LANGFLOW_DEV=false
_30
LANGFLOW_FALLBACK_TO_ENV_VAR=false
_30
LANGFLOW_HEALTH_CHECK_MAX_RETRIES=5
_30
LANGFLOW_HOST=localhost
_30
LANGFLOW_LANGCHAIN_CACHE=InMemoryCache
_30
LANGFLOW_MAX_FILE_SIZE_UPLOAD=10000
_30
LANGFLOW_MAX_ITEMS_LENGTH=100
_30
LANGFLOW_MAX_TEXT_LENGTH=1000
_30
LANGFLOW_LOG_LEVEL=error
_30
LANGFLOW_OPEN_BROWSER=false
_30
LANGFLOW_PORT=7860
_30
LANGFLOW_REMOVE_API_KEYS=false
_30
LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true
_30
LANGFLOW_SECRET_KEY=somesecretkey
_30
LANGFLOW_STORE=true
_30
LANGFLOW_STORE_ENVIRONMENT_VARIABLES=true
_30
LANGFLOW_SUPERUSER=adminuser
_30
LANGFLOW_SUPERUSER_PASSWORD=adminpass
_30
LANGFLOW_WORKER_TIMEOUT=60000
_30
LANGFLOW_WORKERS=3

Set environment variables for Langflow Desktop

Environment variables set in your terminal aren't automatically available to GUI-based applications like Langflow Desktop when you launch them from the Windows or macOS GUI.

For Windows, this means any GUI-based app launched from the Start menu, desktop shortcuts, or Windows Explorer.

For macOS, this means any GUI-based app launched from Finder, Spotlight, Launchpad, or the Dock.

To set environment variables for Langflow Desktop, you need to use specific commands or files, depending on your OS.

Langflow Desktop for macOS cannot automatically use variables set in your terminal, such as those in.zshrc or .bash_profile, when launched from the macOS GUI.

To make environment variables available to GUI apps on macOS, you need to use launchctl with a plist file:

  1. Create the LaunchAgents directory if it doesn't exist:


    _10
    mkdir -p ~/Library/LaunchAgents

  2. In the LaunchAgents directory, create a .plist file called dev.langflow.env.

  3. Add the following content to dev.langflow.env.plist, and then add, change, or remove Langflow environment variables as needed for your configuration.

    This example sets the LANGFLOW_CONFIG_DIR environment variable for all GUI apps launched from the macOS GUI.


    _18
    <?xml version="1.0" encoding="UTF-8"?>
    _18
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
    _18
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    _18
    <plist version="1.0">
    _18
    <dict>
    _18
    <key>Label</key>
    _18
    <string>dev.langflow.env</string>
    _18
    <key>ProgramArguments</key>
    _18
    <array>
    _18
    <string>launchctl</string>
    _18
    <string>setenv</string>
    _18
    <string>LANGFLOW_CONFIG_DIR</string>
    _18
    <string>/Users/your_user/custom/config</string>
    _18
    </array>
    _18
    <key>RunAtLoad</key>
    _18
    <true/>
    _18
    </dict>
    _18
    </plist>

  4. Load the file with launchctl:


    _10
    launchctl load ~/Library/LaunchAgents/dev.langflow.env.plist

Search