Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
pwd.html430 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="pwd — The password database" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/pwd.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="This module provides access to the Unix user account and password database. It is available on all Unix versions. Availability: Unix, not WASI, not iOS. Password database entries are reported as a ..." />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_pwd_cae8a86a.png" />15<meta property="og:image:alt" content="This module provides access to the Unix user account and password database. It is available on all Unix versions. Availability: Unix, not WASI, not iOS. Password database entries are reported as a ..." />16<meta name="description" content="This module provides access to the Unix user account and password database. It is available on all Unix versions. Availability: Unix, not WASI, not iOS. Password database entries are reported as a ..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>pwd — The password database &#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="grp — The group database" href="grp.html" />43    <link rel="prev" title="posix — The most common POSIX system calls" href="posix.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/pwd.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="posix.html"107                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code> — The most common POSIX system calls</a></p>108  </div>109  <div>110    <h4>Next topic</h4>111    <p class="topless"><a href="grp.html"112                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">grp</span></code> — The group database</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/pwd.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/pwd.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="grp.html" title="grp — The group database"157             accesskey="N">next</a> |</li>158        <li class="right" >159          <a href="posix.html" title="posix — The most common POSIX system calls"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="unix.html" accesskey="U">Unix-specific services</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">pwd</span></code> — The password database</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-pwd">208<span id="pwd-the-password-database"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">pwd</span></code> — The password database<a class="headerlink" href="#module-pwd" title="Link to this heading">¶</a></h1>209<hr class="docutils" />210<p>This module provides access to the Unix user account and password database.  It211is available on all Unix versions.</p>212<div class="availability docutils container">213<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not iOS.</p>214</div>215<p>Password database entries are reported as a tuple-like object, whose attributes216correspond to the members of the <code class="docutils literal notranslate"><span class="pre">passwd</span></code> structure (Attribute field below,217see <code class="docutils literal notranslate"><span class="pre">&lt;pwd.h&gt;</span></code>):</p>218<table class="docutils align-default">219<thead>220<tr class="row-odd"><th class="head"><p>Index</p></th>221<th class="head"><p>Attribute</p></th>222<th class="head"><p>Meaning</p></th>223</tr>224</thead>225<tbody>226<tr class="row-even"><td><p>0</p></td>227<td><p><code class="docutils literal notranslate"><span class="pre">pw_name</span></code></p></td>228<td><p>Login name</p></td>229</tr>230<tr class="row-odd"><td><p>1</p></td>231<td><p><code class="docutils literal notranslate"><span class="pre">pw_passwd</span></code></p></td>232<td><p>Optional encrypted password</p></td>233</tr>234<tr class="row-even"><td><p>2</p></td>235<td><p><code class="docutils literal notranslate"><span class="pre">pw_uid</span></code></p></td>236<td><p>Numerical user ID</p></td>237</tr>238<tr class="row-odd"><td><p>3</p></td>239<td><p><code class="docutils literal notranslate"><span class="pre">pw_gid</span></code></p></td>240<td><p>Numerical group ID</p></td>241</tr>242<tr class="row-even"><td><p>4</p></td>243<td><p><code class="docutils literal notranslate"><span class="pre">pw_gecos</span></code></p></td>244<td><p>User name or comment field</p></td>245</tr>246<tr class="row-odd"><td><p>5</p></td>247<td><p><code class="docutils literal notranslate"><span class="pre">pw_dir</span></code></p></td>248<td><p>User home directory</p></td>249</tr>250<tr class="row-even"><td><p>6</p></td>251<td><p><code class="docutils literal notranslate"><span class="pre">pw_shell</span></code></p></td>252<td><p>User command interpreter</p></td>253</tr>254</tbody>255</table>256<p>The uid and gid items are integers, all others are strings. <a class="reference internal" href="exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> is257raised if the entry asked for cannot be found.</p>258<div class="admonition note">259<p class="admonition-title">Note</p>260<p>In traditional Unix the field <code class="docutils literal notranslate"><span class="pre">pw_passwd</span></code> usually contains a password261encrypted with a DES derived algorithm.  However most262modern unices  use a so-called <em>shadow password</em> system.  On those unices the263<em>pw_passwd</em> field only contains an asterisk (<code class="docutils literal notranslate"><span class="pre">'*'</span></code>) or the  letter <code class="docutils literal notranslate"><span class="pre">'x'</span></code>264where the encrypted password is stored in a file <code class="file docutils literal notranslate"><span class="pre">/etc/shadow</span></code> which is265not world readable.  Whether the <em>pw_passwd</em> field contains anything useful is266system-dependent.</p>267</div>268<p>It defines the following items:</p>269<dl class="py function">270<dt class="sig sig-object py" id="pwd.getpwuid">271<span class="sig-prename descclassname"><span class="pre">pwd.</span></span><span class="sig-name descname"><span class="pre">getpwuid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">uid</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pwd.getpwuid" title="Link to this definition">¶</a></dt>272<dd><p>Return the password database entry for the given numeric user ID.</p>273</dd></dl>274 275<dl class="py function">276<dt class="sig sig-object py" id="pwd.getpwnam">277<span class="sig-prename descclassname"><span class="pre">pwd.</span></span><span class="sig-name descname"><span class="pre">getpwnam</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pwd.getpwnam" title="Link to this definition">¶</a></dt>278<dd><p>Return the password database entry for the given user name.</p>279</dd></dl>280 281<dl class="py function">282<dt class="sig sig-object py" id="pwd.getpwall">283<span class="sig-prename descclassname"><span class="pre">pwd.</span></span><span class="sig-name descname"><span class="pre">getpwall</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pwd.getpwall" title="Link to this definition">¶</a></dt>284<dd><p>Return a list of all available password database entries, in arbitrary order.</p>285</dd></dl>286 287<div class="admonition seealso">288<p class="admonition-title">See also</p>289<dl class="simple">290<dt>Module <a class="reference internal" href="grp.html#module-grp" title="grp: The group database (getgrnam() and friends)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">grp</span></code></a></dt><dd><p>An interface to the group database, similar to this.</p>291</dd>292</dl>293</div>294</section>295 296 297            <div class="clearer"></div>298          </div>299        </div>300      </div>301      <div class="sphinxsidebar" role="navigation" aria-label="Main">302        <div class="sphinxsidebarwrapper">303  <div>304    <h4>Previous topic</h4>305    <p class="topless"><a href="posix.html"306                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code> — The most common POSIX system calls</a></p>307  </div>308  <div>309    <h4>Next topic</h4>310    <p class="topless"><a href="grp.html"311                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">grp</span></code> — The group database</a></p>312  </div>313  <script>314    document.addEventListener('DOMContentLoaded', () => {315        const title = document.querySelector('meta[property="og:title"]').content;316        const elements = document.querySelectorAll('.improvepage');317        const pageurl = window.location.href.split('?')[0];318        elements.forEach(element => {319            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));320            url.searchParams.set('pagetitle', title);321            url.searchParams.set('pageurl', pageurl);322            url.searchParams.set('pagesource', "library/pwd.rst");323            element.href = url.toString();324        });325    });326  </script>327  <div role="note" aria-label="source link">328    <h3>This page</h3>329    <ul class="this-page-menu">330      <li><a href="../bugs.html">Report a bug</a></li>331      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>332      <li>333        <a href="https://github.com/python/cpython/blob/main/Doc/library/pwd.rst?plain=1"334            rel="nofollow">Show source335        </a>336      </li>337      338    </ul>339  </div>340        </div>341<div id="sidebarbutton" title="Collapse sidebar">342<span>«</span>343</div>344 345      </div>346      <div class="clearer"></div>347    </div>  348    <div class="related" role="navigation" aria-label="Related">349      <h3>Navigation</h3>350      <ul>351        <li class="right" style="margin-right: 10px">352          <a href="../genindex.html" title="General Index"353             >index</a></li>354        <li class="right" >355          <a href="../py-modindex.html" title="Python Module Index"356             >modules</a> |</li>357        <li class="right" >358          <a href="grp.html" title="grp — The group database"359             >next</a> |</li>360        <li class="right" >361          <a href="posix.html" title="posix — The most common POSIX system calls"362             >previous</a> |</li>363 364          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>365          <li><a href="https://www.python.org/">Python</a> &#187;</li>366          <li class="switchers">367            <div class="language_switcher_placeholder"></div>368            <div class="version_switcher_placeholder"></div>369          </li>370          <li>371              372          </li>373    <li id="cpython-language-and-version">374      <a href="../index.html">3.15.0a6 Documentation</a> &#187;375    </li>376 377          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>378          <li class="nav-item nav-item-2"><a href="unix.html" >Unix-specific services</a> &#187;</li>379        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pwd</span></code> — The password database</a></li>380                <li class="right">381                    382 383    <div class="inline-search" role="search">384        <form class="inline-search" action="../search.html" method="get">385          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">386          <input type="submit" value="Go">387        </form>388    </div>389                     |390                </li>391            <li class="right">392<label class="theme-selector-label">393    Theme394    <select class="theme-selector" oninput="activateTheme(this.value)">395        <option value="auto" selected>Auto</option>396        <option value="light">Light</option>397        <option value="dark">Dark</option>398    </select>399</label> |</li>400            401      </ul>402    </div>  403    <div class="footer">404    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.405    <br>406    This page is licensed under the Python Software Foundation License Version 2.407    <br>408    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.409    <br>410    411      See <a href="/license.html">History and License</a> for more information.<br>412    413    414    <br>415 416    The Python Software Foundation is a non-profit corporation.417<a href="https://www.python.org/psf/donations/">Please donate.</a>418<br>419    <br>420      Last updated on Mar 10, 2026 (08:58 UTC).421    422      <a href="/bugs.html">Found a bug</a>?423    424    <br>425 426    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.427    </div>428 429  </body>430</html>