Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
netrc.html463 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="netrc — netrc file processing" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/netrc.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/netrc.py The netrc class parses and encapsulates the netrc file format used by the Unix ftp program and other FTP clients. netrc Objects: A netrc instance has the following methods..." />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_netrc_bb171ad9.png" />15<meta property="og:image:alt" content="Source code: Lib/netrc.py The netrc class parses and encapsulates the netrc file format used by the Unix ftp program and other FTP clients. netrc Objects: A netrc instance has the following methods..." />16<meta name="description" content="Source code: Lib/netrc.py The netrc class parses and encapsulates the netrc file format used by the Unix ftp program and other FTP clients. netrc Objects: A netrc instance has the following methods..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>netrc — netrc file processing &#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="plistlib — Generate and parse Apple .plist files" href="plistlib.html" />43    <link rel="prev" title="tomllib — Parse TOML files" href="tomllib.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/netrc.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    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">netrc</span></code> — netrc file processing</a><ul>108<li><a class="reference internal" href="#netrc-objects">netrc Objects</a></li>109</ul>110</li>111</ul>112 113  </div>114  <div>115    <h4>Previous topic</h4>116    <p class="topless"><a href="tomllib.html"117                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code> — Parse TOML files</a></p>118  </div>119  <div>120    <h4>Next topic</h4>121    <p class="topless"><a href="plistlib.html"122                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code> — Generate and parse Apple <code class="docutils literal notranslate"><span class="pre">.plist</span></code> files</a></p>123  </div>124  <script>125    document.addEventListener('DOMContentLoaded', () => {126        const title = document.querySelector('meta[property="og:title"]').content;127        const elements = document.querySelectorAll('.improvepage');128        const pageurl = window.location.href.split('?')[0];129        elements.forEach(element => {130            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));131            url.searchParams.set('pagetitle', title);132            url.searchParams.set('pageurl', pageurl);133            url.searchParams.set('pagesource', "library/netrc.rst");134            element.href = url.toString();135        });136    });137  </script>138  <div role="note" aria-label="source link">139    <h3>This page</h3>140    <ul class="this-page-menu">141      <li><a href="../bugs.html">Report a bug</a></li>142      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>143      <li>144        <a href="https://github.com/python/cpython/blob/main/Doc/library/netrc.rst?plain=1"145            rel="nofollow">Show source146        </a>147      </li>148      149    </ul>150  </div>151        </nav>152    </div>153</div>154 155  156    <div class="related" role="navigation" aria-label="Related">157      <h3>Navigation</h3>158      <ul>159        <li class="right" style="margin-right: 10px">160          <a href="../genindex.html" title="General Index"161             accesskey="I">index</a></li>162        <li class="right" >163          <a href="../py-modindex.html" title="Python Module Index"164             >modules</a> |</li>165        <li class="right" >166          <a href="plistlib.html" title="plistlib — Generate and parse Apple .plist files"167             accesskey="N">next</a> |</li>168        <li class="right" >169          <a href="tomllib.html" title="tomllib — Parse TOML files"170             accesskey="P">previous</a> |</li>171 172          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>173          <li><a href="https://www.python.org/">Python</a> &#187;</li>174          <li class="switchers">175            <div class="language_switcher_placeholder"></div>176            <div class="version_switcher_placeholder"></div>177          </li>178          <li>179              180          </li>181    <li id="cpython-language-and-version">182      <a href="../index.html">3.15.0a6 Documentation</a> &#187;183    </li>184 185          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>186          <li class="nav-item nav-item-2"><a href="fileformats.html" accesskey="U">File Formats</a> &#187;</li>187        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">netrc</span></code> — netrc file processing</a></li>188                <li class="right">189                    190 191    <div class="inline-search" role="search">192        <form class="inline-search" action="../search.html" method="get">193          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">194          <input type="submit" value="Go">195        </form>196    </div>197                     |198                </li>199            <li class="right">200<label class="theme-selector-label">201    Theme202    <select class="theme-selector" oninput="activateTheme(this.value)">203        <option value="auto" selected>Auto</option>204        <option value="light">Light</option>205        <option value="dark">Dark</option>206    </select>207</label> |</li>208            209      </ul>210    </div>    211 212    <div class="document">213      <div class="documentwrapper">214        <div class="bodywrapper">215          <div class="body" role="main">216            217  <section id="module-netrc">218<span id="netrc-netrc-file-processing"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">netrc</span></code> — netrc file processing<a class="headerlink" href="#module-netrc" title="Link to this heading">¶</a></h1>219<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/netrc.py">Lib/netrc.py</a></p>220<hr class="docutils" />221<p>The <a class="reference internal" href="#netrc.netrc" title="netrc.netrc"><code class="xref py py-class docutils literal notranslate"><span class="pre">netrc</span></code></a> class parses and encapsulates the netrc file format used by222the Unix <strong class="program">ftp</strong> program and other FTP clients.</p>223<dl class="py class">224<dt class="sig sig-object py" id="netrc.netrc">225<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">netrc.</span></span><span class="sig-name descname"><span class="pre">netrc</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#netrc.netrc" title="Link to this definition">¶</a></dt>226<dd><p>A <a class="reference internal" href="#netrc.netrc" title="netrc.netrc"><code class="xref py py-class docutils literal notranslate"><span class="pre">netrc</span></code></a> instance or subclass instance encapsulates data from  a netrc227file.  The initialization argument, if present, specifies the file to parse.  If228no argument is given, the file <code class="file docutils literal notranslate"><span class="pre">.netrc</span></code> in the user’s home directory –229as determined by <a class="reference internal" href="os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.expanduser()</span></code></a> – will be read.  Otherwise,230a <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> exception will be raised.231Parse errors will raise <a class="reference internal" href="#netrc.NetrcParseError" title="netrc.NetrcParseError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NetrcParseError</span></code></a> with diagnostic232information including the file name, line number, and terminating token.</p>233<p>If no argument is specified on a POSIX system, the presence of passwords in234the <code class="file docutils literal notranslate"><span class="pre">.netrc</span></code> file will raise a <a class="reference internal" href="#netrc.NetrcParseError" title="netrc.NetrcParseError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NetrcParseError</span></code></a> if the file235ownership or permissions are insecure (owned by a user other than the user236running the process, or accessible for read or write by any other user).237This implements security behavior equivalent to that of ftp and other238programs that use <code class="file docutils literal notranslate"><span class="pre">.netrc</span></code>. Such security checks are not available239on platforms that do not support <a class="reference internal" href="os.html#os.getuid" title="os.getuid"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getuid()</span></code></a>.</p>240<div class="versionchanged">241<p><span class="versionmodified changed">Changed in version 3.4: </span>Added the POSIX permission check.</p>242</div>243<div class="versionchanged">244<p><span class="versionmodified changed">Changed in version 3.7: </span><a class="reference internal" href="os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.expanduser()</span></code></a> is used to find the location of the245<code class="file docutils literal notranslate"><span class="pre">.netrc</span></code> file when <em>file</em> is not passed as argument.</p>246</div>247<div class="versionchanged">248<p><span class="versionmodified changed">Changed in version 3.10: </span><code class="xref py py-class docutils literal notranslate"><span class="pre">netrc</span></code> try UTF-8 encoding before using locale specific249encoding.250The entry in the netrc file no longer needs to contain all tokens.  The missing251tokens’ value default to an empty string.  All the tokens and their values now252can contain arbitrary characters, like whitespace and non-ASCII characters.253If the login name is anonymous, it won’t trigger the security check.</p>254</div>255</dd></dl>256 257<dl class="py exception">258<dt class="sig sig-object py" id="netrc.NetrcParseError">259<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">netrc.</span></span><span class="sig-name descname"><span class="pre">NetrcParseError</span></span><a class="headerlink" href="#netrc.NetrcParseError" title="Link to this definition">¶</a></dt>260<dd><p>Exception raised by the <a class="reference internal" href="#netrc.netrc" title="netrc.netrc"><code class="xref py py-class docutils literal notranslate"><span class="pre">netrc</span></code></a> class when syntactical errors are261encountered in source text.  Instances of this exception provide three262interesting attributes:</p>263<dl class="py attribute">264<dt class="sig sig-object py" id="netrc.NetrcParseError.msg">265<span class="sig-name descname"><span class="pre">msg</span></span><a class="headerlink" href="#netrc.NetrcParseError.msg" title="Link to this definition">¶</a></dt>266<dd><p>Textual explanation of the error.</p>267</dd></dl>268 269<dl class="py attribute">270<dt class="sig sig-object py" id="netrc.NetrcParseError.filename">271<span class="sig-name descname"><span class="pre">filename</span></span><a class="headerlink" href="#netrc.NetrcParseError.filename" title="Link to this definition">¶</a></dt>272<dd><p>The name of the source file.</p>273</dd></dl>274 275<dl class="py attribute">276<dt class="sig sig-object py" id="netrc.NetrcParseError.lineno">277<span class="sig-name descname"><span class="pre">lineno</span></span><a class="headerlink" href="#netrc.NetrcParseError.lineno" title="Link to this definition">¶</a></dt>278<dd><p>The line number on which the error was found.</p>279</dd></dl>280 281</dd></dl>282 283<section id="netrc-objects">284<span id="id1"></span><h2>netrc Objects<a class="headerlink" href="#netrc-objects" title="Link to this heading">¶</a></h2>285<p>A <a class="reference internal" href="#netrc.netrc" title="netrc.netrc"><code class="xref py py-class docutils literal notranslate"><span class="pre">netrc</span></code></a> instance has the following methods:</p>286<dl class="py method">287<dt class="sig sig-object py" id="netrc.netrc.authenticators">288<span class="sig-prename descclassname"><span class="pre">netrc.</span></span><span class="sig-name descname"><span class="pre">authenticators</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#netrc.netrc.authenticators" title="Link to this definition">¶</a></dt>289<dd><p>Return a 3-tuple <code class="docutils literal notranslate"><span class="pre">(login,</span> <span class="pre">account,</span> <span class="pre">password)</span></code> of authenticators for <em>host</em>.290If the netrc file did not contain an entry for the given host, return the tuple291associated with the ‘default’ entry.  If neither matching host nor default entry292is available, return <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>293</dd></dl>294 295<dl class="py method">296<dt class="sig sig-object py" id="netrc.netrc.__repr__">297<span class="sig-prename descclassname"><span class="pre">netrc.</span></span><span class="sig-name descname"><span class="pre">__repr__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#netrc.netrc.__repr__" title="Link to this definition">¶</a></dt>298<dd><p>Dump the class data as a string in the format of a netrc file. (This discards299comments and may reorder the entries.)</p>300</dd></dl>301 302<p>Instances of <a class="reference internal" href="#netrc.netrc" title="netrc.netrc"><code class="xref py py-class docutils literal notranslate"><span class="pre">netrc</span></code></a> have public instance variables:</p>303<dl class="py attribute">304<dt class="sig sig-object py" id="netrc.netrc.hosts">305<span class="sig-prename descclassname"><span class="pre">netrc.</span></span><span class="sig-name descname"><span class="pre">hosts</span></span><a class="headerlink" href="#netrc.netrc.hosts" title="Link to this definition">¶</a></dt>306<dd><p>Dictionary mapping host names to <code class="docutils literal notranslate"><span class="pre">(login,</span> <span class="pre">account,</span> <span class="pre">password)</span></code> tuples.  The307‘default’ entry, if any, is represented as a pseudo-host by that name.</p>308</dd></dl>309 310<dl class="py attribute">311<dt class="sig sig-object py" id="netrc.netrc.macros">312<span class="sig-prename descclassname"><span class="pre">netrc.</span></span><span class="sig-name descname"><span class="pre">macros</span></span><a class="headerlink" href="#netrc.netrc.macros" title="Link to this definition">¶</a></dt>313<dd><p>Dictionary mapping macro names to string lists.</p>314</dd></dl>315 316</section>317</section>318 319 320            <div class="clearer"></div>321          </div>322        </div>323      </div>324      <div class="sphinxsidebar" role="navigation" aria-label="Main">325        <div class="sphinxsidebarwrapper">326  <div>327    <h3><a href="../contents.html">Table of Contents</a></h3>328    <ul>329<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">netrc</span></code> — netrc file processing</a><ul>330<li><a class="reference internal" href="#netrc-objects">netrc Objects</a></li>331</ul>332</li>333</ul>334 335  </div>336  <div>337    <h4>Previous topic</h4>338    <p class="topless"><a href="tomllib.html"339                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code> — Parse TOML files</a></p>340  </div>341  <div>342    <h4>Next topic</h4>343    <p class="topless"><a href="plistlib.html"344                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code> — Generate and parse Apple <code class="docutils literal notranslate"><span class="pre">.plist</span></code> files</a></p>345  </div>346  <script>347    document.addEventListener('DOMContentLoaded', () => {348        const title = document.querySelector('meta[property="og:title"]').content;349        const elements = document.querySelectorAll('.improvepage');350        const pageurl = window.location.href.split('?')[0];351        elements.forEach(element => {352            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));353            url.searchParams.set('pagetitle', title);354            url.searchParams.set('pageurl', pageurl);355            url.searchParams.set('pagesource', "library/netrc.rst");356            element.href = url.toString();357        });358    });359  </script>360  <div role="note" aria-label="source link">361    <h3>This page</h3>362    <ul class="this-page-menu">363      <li><a href="../bugs.html">Report a bug</a></li>364      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>365      <li>366        <a href="https://github.com/python/cpython/blob/main/Doc/library/netrc.rst?plain=1"367            rel="nofollow">Show source368        </a>369      </li>370      371    </ul>372  </div>373        </div>374<div id="sidebarbutton" title="Collapse sidebar">375<span>«</span>376</div>377 378      </div>379      <div class="clearer"></div>380    </div>  381    <div class="related" role="navigation" aria-label="Related">382      <h3>Navigation</h3>383      <ul>384        <li class="right" style="margin-right: 10px">385          <a href="../genindex.html" title="General Index"386             >index</a></li>387        <li class="right" >388          <a href="../py-modindex.html" title="Python Module Index"389             >modules</a> |</li>390        <li class="right" >391          <a href="plistlib.html" title="plistlib — Generate and parse Apple .plist files"392             >next</a> |</li>393        <li class="right" >394          <a href="tomllib.html" title="tomllib — Parse TOML files"395             >previous</a> |</li>396 397          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>398          <li><a href="https://www.python.org/">Python</a> &#187;</li>399          <li class="switchers">400            <div class="language_switcher_placeholder"></div>401            <div class="version_switcher_placeholder"></div>402          </li>403          <li>404              405          </li>406    <li id="cpython-language-and-version">407      <a href="../index.html">3.15.0a6 Documentation</a> &#187;408    </li>409 410          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>411          <li class="nav-item nav-item-2"><a href="fileformats.html" >File Formats</a> &#187;</li>412        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">netrc</span></code> — netrc file processing</a></li>413                <li class="right">414                    415 416    <div class="inline-search" role="search">417        <form class="inline-search" action="../search.html" method="get">418          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">419          <input type="submit" value="Go">420        </form>421    </div>422                     |423                </li>424            <li class="right">425<label class="theme-selector-label">426    Theme427    <select class="theme-selector" oninput="activateTheme(this.value)">428        <option value="auto" selected>Auto</option>429        <option value="light">Light</option>430        <option value="dark">Dark</option>431    </select>432</label> |</li>433            434      </ul>435    </div>  436    <div class="footer">437    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.438    <br>439    This page is licensed under the Python Software Foundation License Version 2.440    <br>441    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.442    <br>443    444      See <a href="/license.html">History and License</a> for more information.<br>445    446    447    <br>448 449    The Python Software Foundation is a non-profit corporation.450<a href="https://www.python.org/psf/donations/">Please donate.</a>451<br>452    <br>453      Last updated on Mar 10, 2026 (08:58 UTC).454    455      <a href="/bugs.html">Found a bug</a>?456    457    <br>458 459    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.460    </div>461 462  </body>463</html>