parthtamu/rag-code-assistant
0
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="importlib.resources.abc – Abstract base classes for resources" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/importlib.resources.abc.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/importlib/resources/abc.py" />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_importlib.resources.abc_c7014bd6.png" />15<meta property="og:image:alt" content="Source code: Lib/importlib/resources/abc.py" />16<meta name="description" content="Source code: Lib/importlib/resources/abc.py" />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>importlib.resources.abc – Abstract base classes for resources — 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="importlib.metadata – Accessing package metadata" href="importlib.metadata.html" />43 <link rel="prev" title="importlib.resources – Package resource reading, opening and access" href="importlib.resources.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/importlib.resources.abc.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="importlib.resources.html"107 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code> – Package resource reading, opening and access</a></p>108 </div>109 <div>110 <h4>Next topic</h4>111 <p class="topless"><a href="importlib.metadata.html"112 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</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/importlib.resources.abc.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/importlib.resources.abc.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="importlib.metadata.html" title="importlib.metadata – Accessing package metadata"157 accesskey="N">next</a> |</li>158 <li class="right" >159 <a href="importlib.resources.html" title="importlib.resources – Package resource reading, opening and access"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> »</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> »173 </li>174 175 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>176 <li class="nav-item nav-item-2"><a href="modules.html" accesskey="U">Importing Modules</a> »</li>177 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code> – Abstract base classes for resources</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-importlib.resources.abc">208<span id="importlib-resources-abc-abstract-base-classes-for-resources"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code> – Abstract base classes for resources<a class="headerlink" href="#module-importlib.resources.abc" 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/importlib/resources/abc.py">Lib/importlib/resources/abc.py</a></p>210<hr class="docutils" />211<div class="versionadded">212<p><span class="versionmodified added">Added in version 3.11.</span></p>213</div>214<dl class="py class">215<dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader">216<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">importlib.resources.abc.</span></span><span class="sig-name descname"><span class="pre">ResourceReader</span></span><a class="headerlink" href="#importlib.resources.abc.ResourceReader" title="Link to this definition">¶</a></dt>217<dd><p><em>Superseded by TraversableResources</em></p>218<p>An <a class="reference internal" href="../glossary.html#term-abstract-base-class"><span class="xref std std-term">abstract base class</span></a> to provide the ability to read219<em>resources</em>.</p>220<p>From the perspective of this ABC, a <em>resource</em> is a binary221artifact that is shipped within a package. Typically this is222something like a data file that lives next to the <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code>223file of the package. The purpose of this class is to help abstract224out the accessing of such data files so that it does not matter if225the package and its data file(s) are stored e.g. in a zip file226versus on the file system.</p>227<p>For any of methods of this class, a <em>resource</em> argument is228expected to be a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> which represents229conceptually just a file name. This means that no subdirectory230paths should be included in the <em>resource</em> argument. This is231because the location of the package the reader is for, acts as the232“directory”. Hence the metaphor for directories and file233names is packages and resources, respectively. This is also why234instances of this class are expected to directly correlate to235a specific package (instead of potentially representing multiple236packages or a module).</p>237<p>Loaders that wish to support resource reading are expected to238provide a method called <code class="docutils literal notranslate"><span class="pre">get_resource_reader(fullname)</span></code> which239returns an object implementing this ABC’s interface. If the module240specified by fullname is not a package, this method should return241<a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>. An object compatible with this ABC should only be242returned when the specified module is a package.</p>243<div class="deprecated">244<p><span class="versionmodified deprecated">Deprecated since version 3.12: </span>Use <a class="reference internal" href="#importlib.resources.abc.TraversableResources" title="importlib.resources.abc.TraversableResources"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.TraversableResources</span></code></a> instead.</p>245</div>246<dl class="py method">247<dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.open_resource">248<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">open_resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.open_resource" title="Link to this definition">¶</a></dt>249<dd><p>Returns an opened, <a class="reference internal" href="../glossary.html#term-file-like-object"><span class="xref std std-term">file-like object</span></a> for binary reading250of the <em>resource</em>.</p>251<p>If the resource cannot be found, <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> is252raised.</p>253</dd></dl>254 255<dl class="py method">256<dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.resource_path">257<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">resource_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.resource_path" title="Link to this definition">¶</a></dt>258<dd><p>Returns the file system path to the <em>resource</em>.</p>259<p>If the resource does not concretely exist on the file system,260raise <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>.</p>261</dd></dl>262 263<dl class="py method">264<dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.is_resource">265<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.is_resource" title="Link to this definition">¶</a></dt>266<dd><p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if the named <em>path</em> is considered a resource.267<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> is raised if <em>path</em> does not exist.</p>268<div class="versionchanged">269<p><span class="versionmodified changed">Changed in version 3.10: </span>The argument <em>name</em> was renamed to <em>path</em>.</p>270</div>271</dd></dl>272 273<dl class="py method">274<dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.contents">275<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">contents</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.contents" title="Link to this definition">¶</a></dt>276<dd><p>Returns an <a class="reference internal" href="../glossary.html#term-iterable"><span class="xref std std-term">iterable</span></a> of strings over the contents of277the package. Do note that it is not required that all names278returned by the iterator be actual resources, e.g. it is279acceptable to return names for which <a class="reference internal" href="#importlib.resources.abc.ResourceReader.is_resource" title="importlib.resources.abc.ResourceReader.is_resource"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_resource()</span></code></a> would280be false.</p>281<p>Allowing non-resource names to be returned is to allow for282situations where how a package and its resources are stored283are known a priori and the non-resource names would be useful.284For instance, returning subdirectory names is allowed so that285when it is known that the package and resources are stored on286the file system then those subdirectory names can be used287directly.</p>288<p>The abstract method returns an iterable of no items.</p>289</dd></dl>290 291</dd></dl>292 293<dl class="py class">294<dt class="sig sig-object py" id="importlib.resources.abc.Traversable">295<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">importlib.resources.abc.</span></span><span class="sig-name descname"><span class="pre">Traversable</span></span><a class="headerlink" href="#importlib.resources.abc.Traversable" title="Link to this definition">¶</a></dt>296<dd><p>An object with a subset of <a class="reference internal" href="pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> methods suitable for297traversing directories and opening files.</p>298<p>For a representation of the object on the file-system, use299<a class="reference internal" href="importlib.resources.html#importlib.resources.as_file" title="importlib.resources.as_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.resources.as_file()</span></code></a>.</p>300<dl class="py attribute">301<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.name">302<span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#importlib.resources.abc.Traversable.name" title="Link to this definition">¶</a></dt>303<dd><p>Abstract. The base name of this object without any parent references.</p>304</dd></dl>305 306<dl class="py method">307<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.iterdir">308<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">iterdir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.iterdir" title="Link to this definition">¶</a></dt>309<dd><p>Yield Traversable objects in self.</p>310</dd></dl>311 312<dl class="py method">313<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.is_dir">314<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_dir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.is_dir" title="Link to this definition">¶</a></dt>315<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if self is a directory.</p>316</dd></dl>317 318<dl class="py method">319<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.is_file">320<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_file</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.is_file" title="Link to this definition">¶</a></dt>321<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if self is a file.</p>322</dd></dl>323 324<dl class="py method">325<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.joinpath">326<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">joinpath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.joinpath" title="Link to this definition">¶</a></dt>327<dd><p>Traverse directories according to <em>pathsegments</em> and return328the result as <code class="xref py py-class docutils literal notranslate"><span class="pre">Traversable</span></code>.</p>329<p>Each <em>pathsegments</em> argument may contain multiple names separated by330forward slashes (<code class="docutils literal notranslate"><span class="pre">/</span></code>, <code class="docutils literal notranslate"><span class="pre">posixpath.sep</span></code> ).331For example, the following are equivalent:</p>332<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">files</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'subdir'</span><span class="p">,</span> <span class="s1">'subsuddir'</span><span class="p">,</span> <span class="s1">'file.txt'</span><span class="p">)</span>333<span class="n">files</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'subdir/subsuddir/file.txt'</span><span class="p">)</span>334</pre></div>335</div>336<p>Note that some <code class="xref py py-class docutils literal notranslate"><span class="pre">Traversable</span></code> implementations337might not be updated to the latest version of the protocol.338For compatibility with such implementations, provide a single argument339without path separators to each call to <code class="docutils literal notranslate"><span class="pre">joinpath</span></code>. For example:</p>340<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">files</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'subdir'</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'subsubdir'</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'file.txt'</span><span class="p">)</span>341</pre></div>342</div>343<div class="versionchanged">344<p><span class="versionmodified changed">Changed in version 3.11: </span><code class="docutils literal notranslate"><span class="pre">joinpath</span></code> accepts multiple <em>pathsegments</em>, and these segments345may contain forward slashes as path separators.346Previously, only a single <em>child</em> argument was accepted.</p>347</div>348</dd></dl>349 350<dl class="py method">351<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.__truediv__">352<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">__truediv__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">child</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.__truediv__" title="Link to this definition">¶</a></dt>353<dd><p>Return Traversable child in self.354Equivalent to <code class="docutils literal notranslate"><span class="pre">joinpath(child)</span></code>.</p>355</dd></dl>356 357<dl class="py method">358<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.open">359<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'r'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.open" title="Link to this definition">¶</a></dt>360<dd><p><em>mode</em> may be ‘r’ or ‘rb’ to open as text or binary. Return a handle361suitable for reading (same as <a class="reference internal" href="pathlib.html#pathlib.Path.open" title="pathlib.Path.open"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pathlib.Path.open</span></code></a>).</p>362<p>When opening as text, accepts encoding parameters such as those363accepted by <a class="reference internal" href="io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOWrapper</span></code></a>.</p>364</dd></dl>365 366<dl class="py method">367<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.read_bytes">368<span class="sig-name descname"><span class="pre">read_bytes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.read_bytes" title="Link to this definition">¶</a></dt>369<dd><p>Read contents of self as bytes.</p>370</dd></dl>371 372<dl class="py method">373<dt class="sig sig-object py" id="importlib.resources.abc.Traversable.read_text">374<span class="sig-name descname"><span class="pre">read_text</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">encoding</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="#importlib.resources.abc.Traversable.read_text" title="Link to this definition">¶</a></dt>375<dd><p>Read contents of self as text.</p>376</dd></dl>377 378</dd></dl>379 380<dl class="py class">381<dt class="sig sig-object py" id="importlib.resources.abc.TraversableResources">382<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">importlib.resources.abc.</span></span><span class="sig-name descname"><span class="pre">TraversableResources</span></span><a class="headerlink" href="#importlib.resources.abc.TraversableResources" title="Link to this definition">¶</a></dt>383<dd><p>An abstract base class for resource readers capable of serving384the <a class="reference internal" href="importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> interface. Subclasses385<a class="reference internal" href="#importlib.resources.abc.ResourceReader" title="importlib.resources.abc.ResourceReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">ResourceReader</span></code></a> and provides386concrete implementations of the <code class="xref py py-class docutils literal notranslate"><span class="pre">ResourceReader</span></code>’s387abstract methods. Therefore, any loader supplying388<code class="xref py py-class docutils literal notranslate"><span class="pre">TraversableResources</span></code> also supplies <code class="xref py py-class docutils literal notranslate"><span class="pre">ResourceReader</span></code>.</p>389<p>Loaders that wish to support resource reading are expected to390implement this interface.</p>391<dl class="py method">392<dt class="sig sig-object py" id="importlib.resources.abc.TraversableResources.files">393<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">files</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.TraversableResources.files" title="Link to this definition">¶</a></dt>394<dd><p>Returns a <a class="reference internal" href="#importlib.resources.abc.Traversable" title="importlib.resources.abc.Traversable"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.Traversable</span></code></a> object for the loaded395package.</p>396</dd></dl>397 398</dd></dl>399 400</section>401 402 403 <div class="clearer"></div>404 </div>405 </div>406 </div>407 <div class="sphinxsidebar" role="navigation" aria-label="Main">408 <div class="sphinxsidebarwrapper">409 <div>410 <h4>Previous topic</h4>411 <p class="topless"><a href="importlib.resources.html"412 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code> – Package resource reading, opening and access</a></p>413 </div>414 <div>415 <h4>Next topic</h4>416 <p class="topless"><a href="importlib.metadata.html"417 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</a></p>418 </div>419 <script>420 document.addEventListener('DOMContentLoaded', () => {421 const title = document.querySelector('meta[property="og:title"]').content;422 const elements = document.querySelectorAll('.improvepage');423 const pageurl = window.location.href.split('?')[0];424 elements.forEach(element => {425 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));426 url.searchParams.set('pagetitle', title);427 url.searchParams.set('pageurl', pageurl);428 url.searchParams.set('pagesource', "library/importlib.resources.abc.rst");429 element.href = url.toString();430 });431 });432 </script>433 <div role="note" aria-label="source link">434 <h3>This page</h3>435 <ul class="this-page-menu">436 <li><a href="../bugs.html">Report a bug</a></li>437 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>438 <li>439 <a href="https://github.com/python/cpython/blob/main/Doc/library/importlib.resources.abc.rst?plain=1"440 rel="nofollow">Show source441 </a>442 </li>443 444 </ul>445 </div>446 </div>447<div id="sidebarbutton" title="Collapse sidebar">448<span>«</span>449</div>450 451 </div>452 <div class="clearer"></div>453 </div> 454 <div class="related" role="navigation" aria-label="Related">455 <h3>Navigation</h3>456 <ul>457 <li class="right" style="margin-right: 10px">458 <a href="../genindex.html" title="General Index"459 >index</a></li>460 <li class="right" >461 <a href="../py-modindex.html" title="Python Module Index"462 >modules</a> |</li>463 <li class="right" >464 <a href="importlib.metadata.html" title="importlib.metadata – Accessing package metadata"465 >next</a> |</li>466 <li class="right" >467 <a href="importlib.resources.html" title="importlib.resources – Package resource reading, opening and access"468 >previous</a> |</li>469 470 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>471 <li><a href="https://www.python.org/">Python</a> »</li>472 <li class="switchers">473 <div class="language_switcher_placeholder"></div>474 <div class="version_switcher_placeholder"></div>475 </li>476 <li>477 478 </li>479 <li id="cpython-language-and-version">480 <a href="../index.html">3.15.0a6 Documentation</a> »481 </li>482 483 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>484 <li class="nav-item nav-item-2"><a href="modules.html" >Importing Modules</a> »</li>485 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code> – Abstract base classes for resources</a></li>486 <li class="right">487 488 489 <div class="inline-search" role="search">490 <form class="inline-search" action="../search.html" method="get">491 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">492 <input type="submit" value="Go">493 </form>494 </div>495 |496 </li>497 <li class="right">498<label class="theme-selector-label">499 Theme500 <select class="theme-selector" oninput="activateTheme(this.value)">501 <option value="auto" selected>Auto</option>502 <option value="light">Light</option>503 <option value="dark">Dark</option>504 </select>505</label> |</li>506 507 </ul>508 </div> 509 <div class="footer">510 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.511 <br>512 This page is licensed under the Python Software Foundation License Version 2.513 <br>514 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.515 <br>516 517 See <a href="/license.html">History and License</a> for more information.<br>518 519 520 <br>521 522 The Python Software Foundation is a non-profit corporation.523<a href="https://www.python.org/psf/donations/">Please donate.</a>524<br>525 <br>526 Last updated on Mar 10, 2026 (08:58 UTC).527 528 <a href="/bugs.html">Found a bug</a>?529 530 <br>531 532 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.533 </div>534 535 </body>536</html>