Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
getpass.html411 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="getpass — Portable password input" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/getpass.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/getpass.py Availability: not WASI. This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information. The getpass module provides two fun..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_getpass_2dad7e0d.png" />15<meta property="og:image:alt" content="Source code: Lib/getpass.py Availability: not WASI. This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information. The getpass module provides two fun..." />16<meta name="description" content="Source code: Lib/getpass.py Availability: not WASI. This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information. The getpass module provides two fun..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>getpass — Portable password input &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="fileinput — Iterate over lines from multiple input streams" href="fileinput.html" />43    <link rel="prev" title="optparse — Parser for command line options" href="optparse.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/getpass.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h4>Previous topic</h4>106    <p class="topless"><a href="optparse.html"107                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code> — Parser for command line options</a></p>108  </div>109  <div>110    <h4>Next topic</h4>111    <p class="topless"><a href="fileinput.html"112                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fileinput</span></code> — Iterate over lines from multiple input streams</a></p>113  </div>114  <script>115    document.addEventListener('DOMContentLoaded', () => {116        const title = document.querySelector('meta[property="og:title"]').content;117        const elements = document.querySelectorAll('.improvepage');118        const pageurl = window.location.href.split('?')[0];119        elements.forEach(element => {120            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));121            url.searchParams.set('pagetitle', title);122            url.searchParams.set('pageurl', pageurl);123            url.searchParams.set('pagesource', "library/getpass.rst");124            element.href = url.toString();125        });126    });127  </script>128  <div role="note" aria-label="source link">129    <h3>This page</h3>130    <ul class="this-page-menu">131      <li><a href="../bugs.html">Report a bug</a></li>132      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>133      <li>134        <a href="https://github.com/python/cpython/blob/main/Doc/library/getpass.rst?plain=1"135            rel="nofollow">Show source136        </a>137      </li>138      139    </ul>140  </div>141        </nav>142    </div>143</div>144 145  146    <div class="related" role="navigation" aria-label="Related">147      <h3>Navigation</h3>148      <ul>149        <li class="right" style="margin-right: 10px">150          <a href="../genindex.html" title="General Index"151             accesskey="I">index</a></li>152        <li class="right" >153          <a href="../py-modindex.html" title="Python Module Index"154             >modules</a> |</li>155        <li class="right" >156          <a href="fileinput.html" title="fileinput — Iterate over lines from multiple input streams"157             accesskey="N">next</a> |</li>158        <li class="right" >159          <a href="optparse.html" title="optparse — Parser for command line options"160             accesskey="P">previous</a> |</li>161 162          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>163          <li><a href="https://www.python.org/">Python</a> &#187;</li>164          <li class="switchers">165            <div class="language_switcher_placeholder"></div>166            <div class="version_switcher_placeholder"></div>167          </li>168          <li>169              170          </li>171    <li id="cpython-language-and-version">172      <a href="../index.html">3.15.0a6 Documentation</a> &#187;173    </li>174 175          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>176          <li class="nav-item nav-item-2"><a href="cmdlinelibs.html" accesskey="U">Command-line interface libraries</a> &#187;</li>177        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">getpass</span></code> — Portable password input</a></li>178                <li class="right">179                    180 181    <div class="inline-search" role="search">182        <form class="inline-search" action="../search.html" method="get">183          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">184          <input type="submit" value="Go">185        </form>186    </div>187                     |188                </li>189            <li class="right">190<label class="theme-selector-label">191    Theme192    <select class="theme-selector" oninput="activateTheme(this.value)">193        <option value="auto" selected>Auto</option>194        <option value="light">Light</option>195        <option value="dark">Dark</option>196    </select>197</label> |</li>198            199      </ul>200    </div>    201 202    <div class="document">203      <div class="documentwrapper">204        <div class="bodywrapper">205          <div class="body" role="main">206            207  <section id="module-getpass">208<span id="getpass-portable-password-input"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">getpass</span></code> — Portable password input<a class="headerlink" href="#module-getpass" title="Link to this heading">¶</a></h1>209<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/getpass.py">Lib/getpass.py</a></p>210<hr class="docutils" />211<div class="availability docutils container">212<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI.</p>213<p>This module does not work or is not available on WebAssembly. See214<a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>215</div>216<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">getpass</span></code> module provides two functions:</p>217<dl class="py function">218<dt class="sig sig-object py" id="getpass.getpass">219<span class="sig-prename descclassname"><span class="pre">getpass.</span></span><span class="sig-name descname"><span class="pre">getpass</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">prompt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'Password:</span> <span class="pre">'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stream</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">echo_char</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#getpass.getpass" title="Link to this definition">¶</a></dt>220<dd><p>Prompt the user for a password without echoing.  The user is prompted using221the string <em>prompt</em>, which defaults to <code class="docutils literal notranslate"><span class="pre">'Password:</span> <span class="pre">'</span></code>.  On Unix, the222prompt is written to the file-like object <em>stream</em> using the replace error223handler if needed.  <em>stream</em> defaults to the controlling terminal224(<code class="file docutils literal notranslate"><span class="pre">/dev/tty</span></code>) or if that is unavailable to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> (this225argument is ignored on Windows).</p>226<p>The <em>echo_char</em> argument controls how user input is displayed while typing.227If <em>echo_char</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code> (default), input remains hidden. Otherwise,228<em>echo_char</em> must be a single printable ASCII character and each229typed character is replaced by it. For example, <code class="docutils literal notranslate"><span class="pre">echo_char='*'</span></code> will230display asterisks instead of the actual input.</p>231<p>If echo free input is unavailable getpass() falls back to printing232a warning message to <em>stream</em> and reading from <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code> and233issuing a <a class="reference internal" href="#getpass.GetPassWarning" title="getpass.GetPassWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">GetPassWarning</span></code></a>.</p>234<div class="admonition note">235<p class="admonition-title">Note</p>236<p>If you call getpass from within IDLE, the input may be done in the237terminal you launched IDLE from rather than the idle window itself.</p>238</div>239<div class="admonition note">240<p class="admonition-title">Note</p>241<p>On Unix systems, when <em>echo_char</em> is set, the terminal will be242configured to operate in243<em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/termios(3)#Canonical_and_noncanonical_mode">noncanonical mode</a></em>.244In particular, this means that line editing shortcuts such as245<kbd class="kbd docutils literal notranslate">Ctrl</kbd>+<kbd class="kbd docutils literal notranslate">U</kbd> will not work and may insert unexpected characters into246the input.</p>247</div>248<div class="versionchanged">249<p><span class="versionmodified changed">Changed in version 3.14: </span>Added the <em>echo_char</em> parameter for keyboard feedback.</p>250</div>251</dd></dl>252 253<dl class="py exception">254<dt class="sig sig-object py" id="getpass.GetPassWarning">255<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">getpass.</span></span><span class="sig-name descname"><span class="pre">GetPassWarning</span></span><a class="headerlink" href="#getpass.GetPassWarning" title="Link to this definition">¶</a></dt>256<dd><p>A <a class="reference internal" href="exceptions.html#UserWarning" title="UserWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UserWarning</span></code></a> subclass issued when password input may be echoed.</p>257</dd></dl>258 259<dl class="py function">260<dt class="sig sig-object py" id="getpass.getuser">261<span class="sig-prename descclassname"><span class="pre">getpass.</span></span><span class="sig-name descname"><span class="pre">getuser</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#getpass.getuser" title="Link to this definition">¶</a></dt>262<dd><p>Return the “login name” of the user.</p>263<p>This function checks the environment variables <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">LOGNAME</span></code>,264<span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">USER</span></code>, <code class="xref std std-envvar docutils literal notranslate"><span class="pre">LNAME</span></code> and <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">USERNAME</span></code>, in order, and265returns the value of the first one which is set to a non-empty string.  If266none are set, the login name from the password database is returned on267systems which support the <a class="reference internal" href="pwd.html#module-pwd" title="pwd: The password database (getpwnam() and friends)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pwd</span></code></a> module, otherwise, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>268is raised.</p>269<p>In general, this function should be preferred over <a class="reference internal" href="os.html#os.getlogin" title="os.getlogin"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getlogin()</span></code></a>.</p>270<div class="versionchanged">271<p><span class="versionmodified changed">Changed in version 3.13: </span>Previously, various exceptions beyond just <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> were raised.</p>272</div>273</dd></dl>274 275</section>276 277 278            <div class="clearer"></div>279          </div>280        </div>281      </div>282      <div class="sphinxsidebar" role="navigation" aria-label="Main">283        <div class="sphinxsidebarwrapper">284  <div>285    <h4>Previous topic</h4>286    <p class="topless"><a href="optparse.html"287                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code> — Parser for command line options</a></p>288  </div>289  <div>290    <h4>Next topic</h4>291    <p class="topless"><a href="fileinput.html"292                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fileinput</span></code> — Iterate over lines from multiple input streams</a></p>293  </div>294  <script>295    document.addEventListener('DOMContentLoaded', () => {296        const title = document.querySelector('meta[property="og:title"]').content;297        const elements = document.querySelectorAll('.improvepage');298        const pageurl = window.location.href.split('?')[0];299        elements.forEach(element => {300            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));301            url.searchParams.set('pagetitle', title);302            url.searchParams.set('pageurl', pageurl);303            url.searchParams.set('pagesource', "library/getpass.rst");304            element.href = url.toString();305        });306    });307  </script>308  <div role="note" aria-label="source link">309    <h3>This page</h3>310    <ul class="this-page-menu">311      <li><a href="../bugs.html">Report a bug</a></li>312      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>313      <li>314        <a href="https://github.com/python/cpython/blob/main/Doc/library/getpass.rst?plain=1"315            rel="nofollow">Show source316        </a>317      </li>318      319    </ul>320  </div>321        </div>322<div id="sidebarbutton" title="Collapse sidebar">323<span>«</span>324</div>325 326      </div>327      <div class="clearer"></div>328    </div>  329    <div class="related" role="navigation" aria-label="Related">330      <h3>Navigation</h3>331      <ul>332        <li class="right" style="margin-right: 10px">333          <a href="../genindex.html" title="General Index"334             >index</a></li>335        <li class="right" >336          <a href="../py-modindex.html" title="Python Module Index"337             >modules</a> |</li>338        <li class="right" >339          <a href="fileinput.html" title="fileinput — Iterate over lines from multiple input streams"340             >next</a> |</li>341        <li class="right" >342          <a href="optparse.html" title="optparse — Parser for command line options"343             >previous</a> |</li>344 345          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>346          <li><a href="https://www.python.org/">Python</a> &#187;</li>347          <li class="switchers">348            <div class="language_switcher_placeholder"></div>349            <div class="version_switcher_placeholder"></div>350          </li>351          <li>352              353          </li>354    <li id="cpython-language-and-version">355      <a href="../index.html">3.15.0a6 Documentation</a> &#187;356    </li>357 358          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>359          <li class="nav-item nav-item-2"><a href="cmdlinelibs.html" >Command-line interface libraries</a> &#187;</li>360        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">getpass</span></code> — Portable password input</a></li>361                <li class="right">362                    363 364    <div class="inline-search" role="search">365        <form class="inline-search" action="../search.html" method="get">366          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">367          <input type="submit" value="Go">368        </form>369    </div>370                     |371                </li>372            <li class="right">373<label class="theme-selector-label">374    Theme375    <select class="theme-selector" oninput="activateTheme(this.value)">376        <option value="auto" selected>Auto</option>377        <option value="light">Light</option>378        <option value="dark">Dark</option>379    </select>380</label> |</li>381            382      </ul>383    </div>  384    <div class="footer">385    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.386    <br>387    This page is licensed under the Python Software Foundation License Version 2.388    <br>389    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.390    <br>391    392      See <a href="/license.html">History and License</a> for more information.<br>393    394    395    <br>396 397    The Python Software Foundation is a non-profit corporation.398<a href="https://www.python.org/psf/donations/">Please donate.</a>399<br>400    <br>401      Last updated on Mar 10, 2026 (08:58 UTC).402    403      <a href="/bugs.html">Found a bug</a>?404    405    <br>406 407    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.408    </div>409 410  </body>411</html>