Files
langflow/next/python-interpreter.html
2026-05-04 19:25:36 +00:00

118 lines
62 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-Components/python-interpreter" data-has-hydrated="false">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v3.9.2">
<title data-rh="true">Python Interpreter | Langflow Documentation</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://docs.langflow.org/next/python-interpreter"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="Python Interpreter | Langflow Documentation"><meta data-rh="true" name="description" content="This component allows you to execute Python code with imported packages."><meta data-rh="true" property="og:description" content="This component allows you to execute Python code with imported packages."><link data-rh="true" rel="icon" href="/img/favicon.ico"><link data-rh="true" rel="canonical" href="https://docs.langflow.org/next/python-interpreter"><link data-rh="true" rel="alternate" href="https://docs.langflow.org/next/python-interpreter" hreflang="en"><link data-rh="true" rel="alternate" href="https://docs.langflow.org/next/python-interpreter" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://UZK6BDPCVY-dsn.algolia.net" crossorigin="anonymous"><script data-rh="true" type="application/ld+json">{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Python Interpreter","item":"https://docs.langflow.org/next/python-interpreter"}]}</script><link rel="preconnect" href="https://www.google-analytics.com">
<link rel="preconnect" href="https://www.googletagmanager.com">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-SLQFLQ3KPT"></script>
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-SLQFLQ3KPT",{})</script>
<link rel="search" type="application/opensearchdescription+xml" title="Langflow Documentation" href="/opensearch.xml">
<script>window._ibmAnalytics={settings:{name:"DataStax",tealiumProfileName:"ibm-subsidiary"},trustarc:{privacyPolicyLink:"https://ibm.com/privacy"},"digitalData.page.services.google.enabled":!0},window.digitalData={page:{pageInfo:{ibm:{siteId:"IBM_"+_ibmAnalytics.settings.name},segment:{enabled:!0,env:"prod",key:"B04fNhD06DqDPuaRfQl5lZ2iQICdxxuh",coremetrics:!1,carbonComponentEvents:!1}},category:{primaryCategory:"PC230"}},commonProperties:{productTitle:"IBM Elite Support for Langflow",productCode:"5900BUB",productCodeType:"WWPC",UT30:"30AS5",instanceId:"docs-site",subscriptionId:"public-access",productPlanName:"Public",productPlanType:"freemium",userId:"IBMid-ANONYMOUS"}}</script>
<script src="//1.www.s81c.com/common/stats/ibm-common.js" async="true"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&amp;family=Geist+Mono:wght@400;500&amp;family=Sora:wght@550;600&amp;display=swap">
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("consent","default",{ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied"})</script>
<script>!function(){function e(){if(void 0!==window.truste&&window.truste.cma){var e=window.truste.cma.callApi("getConsent",window.location.href)||{},n=1===e[2],t=1===e[3];gtag("consent","update",{ad_storage:n?"granted":"denied",ad_user_data:n?"granted":"denied",ad_personalization:n?"granted":"denied",analytics_storage:t?"granted":"denied"})}}window.addEventListener&&(window.addEventListener("cm_data_subject_consent_changed",e),window.addEventListener("cm_consent_preferences_set",e)),"complete"===document.readyState?e():window.addEventListener("load",e)}()</script><link rel="stylesheet" href="/assets/css/styles.d29a2eb4.css">
<script src="/assets/js/runtime~main.6cbdbac2.js" defer="defer"></script>
<script src="/assets/js/main.18ca0898.js" defer="defer"></script>
</head>
<body class="navigation-with-keyboard">
<svg style="display: none;"><defs>
<symbol id="theme-svg-external-link" viewBox="0 0 24 24"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"/></symbol>
</defs></svg>
<script>!function(){var t=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return window.localStorage.getItem("theme")}catch(t){}}();document.documentElement.setAttribute("data-theme",t||(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")),document.documentElement.setAttribute("data-theme-choice",t||"system")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="theme-layout-navbar navbar navbar--fixed-top"><div class="navbar__inner"><div class="theme-layout-navbar-left navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/lf-docs-light.svg" alt="Langflow" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="/img/lf-docs-dark.svg" alt="Langflow" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div></a><div class="navbar__item dropdown dropdown--hoverable"><a aria-current="page" class="navbar__link active" aria-haspopup="true" aria-expanded="false" role="button" href="/next/python-interpreter">1.10.x (Next)</a><ul class="dropdown__menu"><li><a aria-current="page" class="dropdown__link dropdown__link--active" href="/next/python-interpreter">1.10.x (Next)</a></li><li><a class="dropdown__link" href="/python-interpreter">1.9.x</a></li><li><a class="dropdown__link" href="/1.8.0/python-interpreter">1.8.x</a></li></ul></div></div><div class="theme-layout-navbar-right navbar__items navbar__items--right"><a href="https://github.com/langflow-ai/langflow" target="_blank" class="navbar__item navbar__link header-github-link" aria-label="GitHub" data-event="UI Interaction" data-action="clicked" data-channel="docs" data-element-id="social-github" data-namespace="header" data-platform-title="Langflow"></a><a href="https://twitter.com/langflow_ai" target="_blank" class="navbar__item navbar__link header-twitter-link" aria-label="Twitter" data-event="UI Interaction" data-action="clicked" data-channel="docs" data-element-id="social-twitter" data-namespace="header" data-platform-title="Langflow"></a><a href="https://discord.gg/EqksyE2EX9" target="_blank" class="navbar__item navbar__link header-discord-link" aria-label="Discord" data-event="UI Interaction" data-action="clicked" data-channel="docs" data-element-id="social-discord" data-namespace="header" data-platform-title="Langflow"></a><div class="toggle_MW0i colorModeToggle_DEke"><button class="clean-btn toggleButton_yw5v toggleButtonDisabled_BJd7" type="button" disabled="" title="system mode" aria-label="Switch between dark and light mode (currently system mode)"><svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false" role="presentation" class="toggleIcon_oIOL lightToggleIcon_SFTY"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false" role="presentation" class="toggleIcon_oIOL darkToggleIcon_ekgs"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false" role="presentation" class="toggleIcon_oIOL systemToggleIcon_yi_a"><path fill="currentColor" d="m12 21c4.971 0 9-4.029 9-9s-4.029-9-9-9-9 4.029-9 9 4.029 9 9 9zm4.95-13.95c1.313 1.313 2.05 3.093 2.05 4.95s-0.738 3.637-2.05 4.95c-1.313 1.313-3.093 2.05-4.95 2.05v-14c1.857 0 3.637 0.737 4.95 2.05z"></path></svg></button></div><div class="navbarSearchContainer_Bca1"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search (Meta+k)" aria-keyshortcuts="Meta+k"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="8" stroke="currentColor" fill="none" stroke-width="1.4"></circle><path d="m21 21-4.3-4.3" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="theme-layout-main main-wrapper mainWrapper_z2l0"><div class="docsWrapper_hBAB"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docRoot_UBD9"><aside aria-label="Documentation sidebar" class="theme-doc-sidebar-container docSidebarContainer_RSuS"><div class="sidebarViewport_pYEE"><div class="sidebar_njMd"><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 sidebar-group-divider"><div class="sidebar-group-label">Build</div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-rocket"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next"><span title="Get started" class="categoryLinkLabel_W154">Get started</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-workflow"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/concepts-overview"><span title="Flows" class="categoryLinkLabel_W154">Flows</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-bot"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/agents"><span title="Agents" class="categoryLinkLabel_W154">Agents</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-plug"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/mcp-client"><span title="Model Context Protocol (MCP)" class="categoryLinkLabel_W154">Model Context Protocol (MCP)</span></a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 sidebar-group-divider"><div class="sidebar-group-label">Develop & Deploy</div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-code"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/api-keys-and-authentication"><span title="Develop" class="categoryLinkLabel_W154">Develop</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-cloud"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/deployment-overview"><span title="Deploy" class="categoryLinkLabel_W154">Deploy</span></a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 sidebar-group-divider"><div class="sidebar-group-label">Reference</div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item sidebar-category-with-icon sidebar-icon-blocks"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" role="button" aria-expanded="true" href="/next/concepts-components"><span title="Components reference" class="categoryLinkLabel_W154">Components reference</span></a></div><ul class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/next/concepts-components"><span title="Components overview" class="linkLabel_WmDU">Components overview</span></a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" role="button" aria-expanded="true" tabindex="0" href="/next/chat-input-and-output"><span title="Core components" class="categoryLinkLabel_W154">Core components</span></a></div><ul class="menu__list"><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/chat-input-and-output"><span title="Input / Output" class="categoryLinkLabel_W154">Input / Output</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/data-operations"><span title="Processing" class="categoryLinkLabel_W154">Processing</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/api-request"><span title="Data Source" class="categoryLinkLabel_W154">Data Source</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/directory"><span title="Files and Knowledge" class="categoryLinkLabel_W154">Files and Knowledge</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/if-else"><span title="Flow Controls" class="categoryLinkLabel_W154">Flow Controls</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/batch-run"><span title="LLM Operations" class="categoryLinkLabel_W154">LLM Operations</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/components-models"><span title="Models and Agents" class="categoryLinkLabel_W154">Models and Agents</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-3 menu__list-item"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" role="button" aria-expanded="true" tabindex="0" href="/next/calculator"><span title="Utilities" class="categoryLinkLabel_W154">Utilities</span></a></div><ul class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-4 menu__list-item"><a class="menu__link" tabindex="0" href="/next/calculator"><span title="Calculator" class="linkLabel_WmDU">Calculator</span></a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-4 menu__list-item"><a class="menu__link" tabindex="0" href="/next/current-date"><span title="Current Date" class="linkLabel_WmDU">Current Date</span></a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-4 menu__list-item"><a class="menu__link menu__link--active" aria-current="page" tabindex="0" href="/next/python-interpreter"><span title="Python Interpreter" class="linkLabel_WmDU">Python Interpreter</span></a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-4 menu__list-item"><a class="menu__link" tabindex="0" href="/next/sql-database"><span title="SQL Database" class="linkLabel_WmDU">SQL Database</span></a></li></ul></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link" tabindex="0" href="/next/legacy-core-components"><span title="Legacy core components" class="linkLabel_WmDU">Legacy core components</span></a></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" tabindex="0" href="/next/components-bundle-components"><span title="Bundles" class="categoryLinkLabel_W154">Bundles</span></a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/next/components-custom-components"><span title="Create custom Python components" class="linkLabel_WmDU">Create custom Python components</span></a></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-fileCode"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/api-reference-api-examples"><span title="API reference" class="categoryLinkLabel_W154">API reference</span></a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 sidebar-group-divider"><div class="sidebar-group-label">Community</div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-gitPR"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/contributing-community"><span title="Contribute" class="categoryLinkLabel_W154">Contribute</span></a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed sidebar-category-with-icon sidebar-icon-helpCircle"><div class="menu__list-item-collapsible"><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role="button" aria-expanded="false" href="/next/troubleshoot"><span title="Support" class="categoryLinkLabel_W154">Support</span></a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 sidebar-ad">
<a href="https://www.langflow.org/desktop" target="_blank" rel="noopener noreferrer" class="menu__link">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<g clip-path="url(#clip0_1645_37)">
<path d="M12 17H20C21.1046 17 22 16.1046 22 15V13M12 17H4C2.89543 17 2 16.1046 2 15V5C2 3.89543 2.89543 3 4 3H10M12 17V21M8 21H12M12 21H16M11.75 10.2917H13.2083L16.125 7.375H17.5833L20.5 4.45833H21.9583M16.125 11.75H17.5833L20.5 8.83333H21.9583M11.75 5.91667H13.2083L16.125 3H17.5833" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</g>
<defs>
<clipPath id="clip0_1645_37">
<rect width="24" height="24" fill="white"/>
</clipPath>
</defs>
</svg>
<div class="sidebar-ad-text-container">
<span class="sidebar-ad-text">Get started in minutes</span>
<span class="sidebar-ad-text sidebar-ad-text-gradient">Download Langflow Desktop</span>
</div>
</a>
</li></ul></nav></div></div></aside><main class="docMainContainer_TBSr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_z5aJ"><div class="theme-doc-version-banner alert alert--warning margin-bottom--md" role="alert"><div>This is unreleased documentation for <!-- -->Langflow Documentation<!-- --> <b>1.10.x (Next)</b> version.</div><div class="margin-top--md">For up-to-date documentation, see the <b><a href="/python-interpreter">latest version</a></b> (<!-- -->1.9.x<!-- -->).</div></div><div class="docItemContainer_c0TR"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label="Breadcrumbs"><ul class="breadcrumbs"><li class="breadcrumbs__item"><a aria-label="Home page" class="breadcrumbs__link" href="/"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" role="presentation" class="breadcrumbHomeIcon_xK9p"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li class="breadcrumbs__item"><span class="breadcrumbs__link">Components reference</span></li><li class="breadcrumbs__item"><span class="breadcrumbs__link">Core components</span></li><li class="breadcrumbs__item"><span class="breadcrumbs__link">Utilities</span></li><li class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link">Python Interpreter</span></li></ul></nav><div class="docMetaRow_c2hx"><div class="root_Eutc"><button type="button" class="button_gpNY"><span aria-hidden="true" class="icon_Bm9L"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path></svg></span><span class="label_LzDG">Copy page</span></button></div><span class="theme-doc-version-badge badge badge--secondary">Version: 1.10.x (Next)</span></div><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><header><h1>Python Interpreter</h1></header><style>[data-ch-theme="github-dark"] { --ch-t-colorScheme: dark;--ch-t-foreground: #c9d1d9;--ch-t-background: #0d1117;--ch-t-lighter-inlineBackground: #0d1117e6;--ch-t-editor-background: #0d1117;--ch-t-editor-foreground: #c9d1d9;--ch-t-editor-lineHighlightBackground: #6e76811a;--ch-t-editor-rangeHighlightBackground: #ffffff0b;--ch-t-editor-infoForeground: #3794FF;--ch-t-editor-selectionBackground: #264F78;--ch-t-focusBorder: #1f6feb;--ch-t-tab-activeBackground: #0d1117;--ch-t-tab-activeForeground: #c9d1d9;--ch-t-tab-inactiveBackground: #010409;--ch-t-tab-inactiveForeground: #8b949e;--ch-t-tab-border: #30363d;--ch-t-tab-activeBorder: #0d1117;--ch-t-editorGroup-border: #30363d;--ch-t-editorGroupHeader-tabsBackground: #010409;--ch-t-editorLineNumber-foreground: #6e7681;--ch-t-input-background: #0d1117;--ch-t-input-foreground: #c9d1d9;--ch-t-input-border: #30363d;--ch-t-icon-foreground: #8b949e;--ch-t-sideBar-background: #010409;--ch-t-sideBar-foreground: #c9d1d9;--ch-t-sideBar-border: #30363d;--ch-t-list-activeSelectionBackground: #6e768166;--ch-t-list-activeSelectionForeground: #c9d1d9;--ch-t-list-hoverBackground: #6e76811a;--ch-t-list-hoverForeground: #c9d1d9; }</style>
<!-- -->
<p>This component allows you to execute Python code with imported packages.</p>
<p>The <strong>Python Interpreter</strong> component can only import packages that are already installed in your Langflow environment.
If you encounter an <code>ImportError</code> when trying to use a package, you need to install it first.</p>
<p>To install custom packages, see <a class="" href="/install-custom-dependencies">Install custom dependencies</a>.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="use-the-python-interpreter-in-a-flow">Use the Python Interpreter in a flow<a href="#use-the-python-interpreter-in-a-flow" class="hash-link" aria-label="Direct link to Use the Python Interpreter in a flow" title="Direct link to Use the Python Interpreter in a flow" translate="no"></a></h2>
<ol>
<li class="">To use this component in a flow, in the <strong>Global Imports</strong> field, add the packages you want to import as a comma-separated list, such as <code>math,pandas</code>.
At least one import is required.</li>
<li class="">In the <strong>Python Code</strong> field, enter the Python code you want to execute. Use <code>print()</code> to see the output.</li>
<li class="">Optional: Enable <strong>Tool Mode</strong>, and then connect the <strong>Python Interpreter</strong> component to an <strong>Agent</strong> component as a tool.
For example, connect a <strong>Python Interpreter</strong> component and a <a class="" href="/calculator"><strong>Calculator</strong> component</a> as tools for an <strong>Agent</strong> component, and then test how it chooses different tools to solve math problems.
<img decoding="async" loading="lazy" alt="Python Interpreter and Calculator components connected to an Agent component" src="/assets/images/component-python-interpreter-1ef9e7dec643a216fd5e83c2139d09c9.png" width="3988" height="2928" class="img_ev3q"></li>
<li class="">Ask the agent an easier math question.
The <strong>Calculator</strong> tool can add, subtract, multiple, divide, or perform exponentiation.
The agent executes the <code>evaluate_expression</code> tool to correctly answer the question.</li>
</ol>
<p>Result:</p>
<div class="ch-codeblock not-prose" data-ch-theme="github-dark"><div class="ch-code-wrapper ch-code" data-ch-measured="false"><code class="ch-code-scroll-parent"><br><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span>Executed evaluate_expression</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span>Input:</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span>{</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span> &quot;expression&quot;: &quot;2+5&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span>}</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span>Output:</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span>{</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span> &quot;result&quot;: &quot;7&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->10</span><div style="display:inline-block;margin-left:16px"><span>}</span></div></div><br></code></div></div>
<ol start="5">
<li class="">Give the agent complete Python code.
This example creates a Pandas DataFrame table with the imported <code>pandas</code> packages, and returns the square root of the mean squares.</li>
</ol>
<div class="ch-codeblock not-prose" data-ch-theme="github-dark"><div class="ch-code-wrapper ch-code" data-ch-measured="false"><code class="ch-code-scroll-parent"><br><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>import pandas as pd</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>import math</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span># Create a simple DataFrame</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>df = pd.DataFrame({</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span> &#x27;numbers&#x27;: [1, 2, 3, 4, 5],</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span> &#x27;squares&#x27;: [x**2 for x in range(1, 6)]</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>})</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span># Calculate the square root of the mean</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>result = math.sqrt(df[&#x27;squares&#x27;].mean())</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>print(f&quot;Square root of mean squares: {result}&quot;)</span></div></div><br></code></div></div>
<p>The agent correctly chooses the <code>run_python_repl</code> tool to solve the problem.</p>
<p>Result:</p>
<div class="ch-codeblock not-prose" data-ch-theme="github-dark"><div class="ch-code-wrapper ch-code" data-ch-measured="false"><code class="ch-code-scroll-parent"><br><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>Executed run_python_repl</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>Input:</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>{</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span> &quot;python_code&quot;: &quot;import pandas as pd\nimport math\n\n# Create a simple DataFrame\ndf = pd.DataFrame({\n &#x27;numbers&#x27;: [1, 2, 3, 4, 5],\n &#x27;squares&#x27;: [x**2 for x in range(1, 6)]\n})\n\n# Calculate the square root of the mean\nresult = math.sqrt(df[&#x27;squares&#x27;].mean())\nprint(f\&quot;Square root of mean squares: {result}\&quot;)&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>}</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>Output:</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>{</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span> &quot;result&quot;: &quot;Square root of mean squares: 3.3166247903554&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->12</span><div style="display:inline-block;margin-left:16px"><span>}</span></div></div><br></code></div></div>
<p>If you don&#x27;t include the package imports in the chat, the agent can still create the table using <code>pd.DataFrame</code>, because the <code>pandas</code> package is imported globally by the <strong>Python Interpreter</strong> component in the <strong>Global Imports</strong> field.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="pass-inputs-to-the-python-interpreter">Pass inputs to the Python Interpreter<a href="#pass-inputs-to-the-python-interpreter" class="hash-link" aria-label="Direct link to Pass inputs to the Python Interpreter" title="Direct link to Pass inputs to the Python Interpreter" translate="no"></a></h2>
<p>To pass inputs to the <strong>Python Interpreter</strong> component, you need to customize the component&#x27;s code to add input fields.
After the input field is added to the component code, the port becomes available for connections.
For example, to connect a <a class="" href="/text-input-and-output"><strong>Text</strong> component</a> and pass a URL value to the <strong>Python Interpreter</strong> component, do the following:</p>
<ol>
<li class="">
<p>Add a <strong>Python Interpreter</strong> component to your flow.</p>
</li>
<li class="">
<p>To modify the <strong>Python Interpreter</strong> component&#x27;s code, click <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code lf-inline-icon" aria-hidden="true" focusable="false" role="presentation"><polyline points="16 18 22 12 16 6"></polyline><polyline points="8 6 2 12 8 18"></polyline></svg> <strong>Edit Code</strong>.</p>
</li>
<li class="">
<p>To pass a URL input to the <strong>Python Interpreter</strong> component, make the following changes to the code:</p>
<p>a. Add the URL input field to the <code>inputs</code> list. This creates the input port that other components can connect to.</p>
<p>b. Update the <code>get_globals</code> method to extract the URL value and add it to the globals dictionary.
This makes the <code>url</code> variable available in the component&#x27;s Python code.</p>
<p>c. Update the default Python code value to use the <code>url</code> variable.</p>
<p>The following example demonstrates these modifications.</p>
<details open="" class="details_lb9f alert alert--info details_b_Ee" data-collapsed="false"><summary>Python code example</summary><div><div class="collapsibleContent_i85q"><div class="ch-codeblock not-prose" data-ch-theme="github-dark"><div class="ch-code-wrapper ch-code" data-ch-measured="false"><code class="ch-code-scroll-parent"><br><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span>import importlib</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span>from langchain_experimental.utilities import PythonREPL</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span>from lfx.custom.custom_component.component import Component</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span>from lfx.io import MultilineInput, Output, StrInput</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span>from lfx.schema.data import Data</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span>from lfx.schema.message import Message # Needed to extract text from Message objects</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span>class PythonREPLComponent(Component):</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> display_name = &quot;Python Interpreter&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> description = &quot;Run Python code with optional imports. Use print() to see the output.&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> documentation: str = &quot;https://docs.langflow.org/python-interpreter&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> icon = &quot;square-terminal&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> inputs = [</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> StrInput(</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> name=&quot;global_imports&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> display_name=&quot;Global Imports&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> info=&quot;A comma-separated list of modules to import globally, e.g. &#x27;math,numpy,pandas&#x27;.&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> value=&quot;math,pandas&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> required=True,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> ),</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> MultilineInput(</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> name=&quot;python_code&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> display_name=&quot;Python Code&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> info=&quot;The Python code to execute. Only modules specified in Global Imports can be used. Use &#x27;url&#x27; variable if URL input is connected.&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> value=&quot;print(f&#x27;URL: {url}&#x27;)&quot;, # Updated to make the URL variable available to the Python code execution</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> input_types=[&quot;Message&quot;],</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> tool_mode=True,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> required=True,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> ),</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> # Add the URL input field to inputs list</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> StrInput(</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> name=&quot;url&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> display_name=&quot;URL&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> info=&quot;URL variable that can be used in Python code. Connect a Text component or enter manually.&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> value=&quot;&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> input_types=[&quot;Text&quot;, &quot;Message&quot;],</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> required=False,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> ),</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> ]</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> outputs = [</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> Output(</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> display_name=&quot;Results&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> name=&quot;results&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> type_=Data,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> method=&quot;run_python_repl&quot;,</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> ),</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> ]</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> def get_globals(self, global_imports: str | list[str]) -&gt; dict:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> &quot;&quot;&quot;Create a globals dictionary with only the specified allowed imports and input variables.&quot;&quot;&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> global_dict = {}</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> try:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> if isinstance(global_imports, str):</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> modules = [module.strip() for module in global_imports.split(&quot;,&quot;)]</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> elif isinstance(global_imports, list):</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> modules = global_imports</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> else:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> msg = &quot;global_imports must be either a string or a list&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> raise TypeError(msg)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> for module in modules:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> try:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> imported_module = importlib.import_module(module)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> global_dict[imported_module.__name__] = imported_module</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> except ImportError as e:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> msg = f&quot;Could not import module {module}: {e!s}&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> raise ImportError(msg) from e</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> # Add the URL variable to the component&#x27;s globals dictionary</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> # Extract from Message object or use the string directly</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> if hasattr(self, &quot;url&quot;) and self.url:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> url_value = self.url.text if isinstance(self.url, Message) else str(self.url)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> if url_value:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> global_dict[&quot;url&quot;] = url_value # Makes &#x27;url&#x27; available in Python code</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> self.log(f&quot;URL variable set: {url_value}&quot;)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> except Exception as e:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> self.log(f&quot;Error in global imports: {e!s}&quot;)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> raise</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> else:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> self.log(f&quot;Successfully imported modules: {list(global_dict.keys())}&quot;)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> return global_dict</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> def run_python_repl(self) -&gt; Data:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> try:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> # Extract Python code text if it&#x27;s a Message object</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> python_code_text = self.python_code</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> if isinstance(python_code_text, Message):</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> python_code_text = python_code_text.text if python_code_text.text else &quot;&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> elif not isinstance(python_code_text, str):</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> python_code_text = str(python_code_text)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> globals_ = self.get_globals(self.global_imports)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> python_repl = PythonREPL(_globals=globals_)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> result = python_repl.run(python_code_text)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> result = result.strip() if result else &quot;&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> self.log(&quot;Code execution completed successfully&quot;)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> return Data(data={&quot;result&quot;: result})</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> except ImportError as e:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> error_message = f&quot;Import Error: {e!s}&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> self.log(error_message)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> return Data(data={&quot;error&quot;: error_message})</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> except SyntaxError as e:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> error_message = f&quot;Syntax Error: {e!s}&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> self.log(error_message)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> return Data(data={&quot;error&quot;: error_message})</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> except (NameError, TypeError, ValueError) as e:</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> error_message = f&quot;Error during execution: {e!s}&quot;</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> self.log(error_message)</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> return Data(data={&quot;error&quot;: error_message})</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span></span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> def build(self):</span></div></div><div><span class="ch-code-line-number">_<!-- -->121</span><div style="display:inline-block;margin-left:16px"><span> return self.run_python_repl</span></div></div><br></code></div></div></div></div></details>
</li>
<li class="">
<p>To save the modifications, click <strong>Check &amp; Save</strong>.</p>
</li>
<li class="">
<p>Add a <strong>Text</strong> component to your flow and set its value, such as <code>google.com</code>.</p>
</li>
<li class="">
<p>Connect the <strong>Text</strong> component&#x27;s output to the new <strong>URL</strong> input field on your customized <strong>Python Interpreter</strong> component.</p>
</li>
</ol>
<p>The <strong>Python Interpreter</strong> component can now use the <code>url</code> variable in the Python code that it executes.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="python-interpreter-parameters">Python Interpreter parameters<a href="#python-interpreter-parameters" class="hash-link" aria-label="Direct link to Python Interpreter parameters" title="Direct link to Python Interpreter parameters" translate="no"></a></h2>
<table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>global_imports</td><td>String</td><td>Input parameter. A comma-separated list of modules to import globally, such as <code>math,pandas,numpy</code>.</td></tr><tr><td>python_code</td><td>Code</td><td>Input parameter. The Python code to execute. Only modules specified in Global Imports can be used.</td></tr><tr><td>results</td><td>JSON</td><td>Output parameter. The output of the executed Python code, including any printed results or errors.</td></tr></tbody></table></div></article><nav class="docusaurus-mt-lg pagination-nav" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href="/next/current-date"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">Current Date</div></a><a class="pagination-nav__link pagination-nav__link--next" href="/next/sql-database"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">SQL Database</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#use-the-python-interpreter-in-a-flow" class="table-of-contents__link toc-highlight">Use the Python Interpreter in a flow</a></li><li><a href="#pass-inputs-to-the-python-interpreter" class="table-of-contents__link toc-highlight">Pass inputs to the Python Interpreter</a></li><li><a href="#python-interpreter-parameters" class="table-of-contents__link toc-highlight">Python Interpreter parameters</a></li></ul></div></div></div></div></main></div></div></div><footer class="theme-layout-footer footer"><div class="container container-fluid"><div class="row footer__links"><div class="theme-layout-footer-column col footer__col"><div class="footer__title"></div><ul class="footer__items clean-list"><li class="footer__item"><div class="footer-links">
<span>© 2026 Langflow</span>
<span id="preferenceCenterContainer"> ·&nbsp; <a href="#" onclick='return"undefined"!=typeof window&&window.truste&&window.truste.eu&&window.truste.eu.clickListener&&window.truste.eu.clickListener(),!1' style="cursor: pointer;">Manage Privacy Choices</a></span>
</div></li></ul></div></div></div></footer><div style="position:fixed;right:21px;bottom:21px;z-index:100;display:flex;align-items:center;gap:10px;cursor:pointer"><div style="background-color:#f6f6f6;border-radius:50%;width:48px;height:48px;display:flex;align-items:center;justify-content:center;box-shadow:0 2px 4px rgba(0,0,0,0.1)"><img src="/img/langflow-icon-black-transparent.svg" style="width:40px" alt="Search"></div></div></div>
</body>
</html>