gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

695 satır
52KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="importlib.metadata – Accessing package metadata" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/importlib.metadata.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/importlib/metadata/__init__.py importlib.metadata is a library that provides access to the metadata of an installed Distribution Package, such as its entry points or its top-level ..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/importlib/metadata/__init__.py importlib.metadata is a library that provides access to the metadata of an installed Distribution Package, such as its entry points or its top-level ..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>importlib.metadata – Accessing package metadata &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="The initialization of the sys.path module search path" href="sys_path_init.html" />
  33. <link rel="prev" title="importlib.resources.abc – Abstract base classes for resources" href="importlib.resources.abc.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/importlib.metadata.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <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>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</a><ul>
  86. <li><a class="reference internal" href="#overview">Overview</a></li>
  87. <li><a class="reference internal" href="#functional-api">Functional API</a><ul>
  88. <li><a class="reference internal" href="#entry-points">Entry points</a></li>
  89. <li><a class="reference internal" href="#distribution-metadata">Distribution metadata</a></li>
  90. <li><a class="reference internal" href="#distribution-versions">Distribution versions</a></li>
  91. <li><a class="reference internal" href="#distribution-files">Distribution files</a></li>
  92. <li><a class="reference internal" href="#distribution-requirements">Distribution requirements</a></li>
  93. <li><a class="reference internal" href="#mapping-import-to-distribution-packages">Mapping import to distribution packages</a></li>
  94. </ul>
  95. </li>
  96. <li><a class="reference internal" href="#distributions">Distributions</a></li>
  97. <li><a class="reference internal" href="#distribution-discovery">Distribution Discovery</a></li>
  98. <li><a class="reference internal" href="#extending-the-search-algorithm">Extending the search algorithm</a></li>
  99. </ul>
  100. </li>
  101. </ul>
  102. </div>
  103. <div>
  104. <h4>Previous topic</h4>
  105. <p class="topless"><a href="importlib.resources.abc.html"
  106. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code> – Abstract base classes for resources</a></p>
  107. </div>
  108. <div>
  109. <h4>Next topic</h4>
  110. <p class="topless"><a href="sys_path_init.html"
  111. title="next chapter">The initialization of the <code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code> module search path</a></p>
  112. </div>
  113. <div role="note" aria-label="source link">
  114. <h3>This Page</h3>
  115. <ul class="this-page-menu">
  116. <li><a href="../bugs.html">Report a Bug</a></li>
  117. <li>
  118. <a href="https://github.com/python/cpython/blob/main/Doc/library/importlib.metadata.rst"
  119. rel="nofollow">Show Source
  120. </a>
  121. </li>
  122. </ul>
  123. </div>
  124. </nav>
  125. </div>
  126. </div>
  127. <div class="related" role="navigation" aria-label="related navigation">
  128. <h3>Navigation</h3>
  129. <ul>
  130. <li class="right" style="margin-right: 10px">
  131. <a href="../genindex.html" title="General Index"
  132. accesskey="I">index</a></li>
  133. <li class="right" >
  134. <a href="../py-modindex.html" title="Python Module Index"
  135. >modules</a> |</li>
  136. <li class="right" >
  137. <a href="sys_path_init.html" title="The initialization of the sys.path module search path"
  138. accesskey="N">next</a> |</li>
  139. <li class="right" >
  140. <a href="importlib.resources.abc.html" title="importlib.resources.abc – Abstract base classes for resources"
  141. accesskey="P">previous</a> |</li>
  142. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  143. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  144. <li class="switchers">
  145. <div class="language_switcher_placeholder"></div>
  146. <div class="version_switcher_placeholder"></div>
  147. </li>
  148. <li>
  149. </li>
  150. <li id="cpython-language-and-version">
  151. <a href="../index.html">3.12.3 Documentation</a> &#187;
  152. </li>
  153. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  154. <li class="nav-item nav-item-2"><a href="modules.html" accesskey="U">Importing Modules</a> &#187;</li>
  155. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</a></li>
  156. <li class="right">
  157. <div class="inline-search" role="search">
  158. <form class="inline-search" action="../search.html" method="get">
  159. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  160. <input type="submit" value="Go" />
  161. </form>
  162. </div>
  163. |
  164. </li>
  165. <li class="right">
  166. <label class="theme-selector-label">
  167. Theme
  168. <select class="theme-selector" oninput="activateTheme(this.value)">
  169. <option value="auto" selected>Auto</option>
  170. <option value="light">Light</option>
  171. <option value="dark">Dark</option>
  172. </select>
  173. </label> |</li>
  174. </ul>
  175. </div>
  176. <div class="document">
  177. <div class="documentwrapper">
  178. <div class="bodywrapper">
  179. <div class="body" role="main">
  180. <section id="module-importlib.metadata">
  181. <span id="importlib-metadata-accessing-package-metadata"></span><span id="using"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata<a class="headerlink" href="#module-importlib.metadata" title="Link to this heading">¶</a></h1>
  182. <div class="versionadded">
  183. <p><span class="versionmodified added">New in version 3.8.</span></p>
  184. </div>
  185. <div class="versionchanged">
  186. <p><span class="versionmodified changed">Changed in version 3.10: </span><code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> is no longer provisional.</p>
  187. </div>
  188. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/importlib/metadata/__init__.py">Lib/importlib/metadata/__init__.py</a></p>
  189. <p><code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> is a library that provides access to
  190. the metadata of an installed <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a>,
  191. such as its entry points
  192. or its top-level names (<a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Import-Package">Import Package</a>s, modules, if any).
  193. Built in part on Python’s import system, this library
  194. intends to replace similar functionality in the <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points">entry point
  195. API</a> and <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/pkg_resources.html#metadata-api">metadata API</a> of <code class="docutils literal notranslate"><span class="pre">pkg_resources</span></code>. Along with
  196. <a class="reference internal" href="importlib.resources.html#module-importlib.resources" title="importlib.resources: Package resource reading, opening, and access"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code></a>,
  197. this package can eliminate the need to use the older and less efficient
  198. <code class="docutils literal notranslate"><span class="pre">pkg_resources</span></code> package.</p>
  199. <p><code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> operates on third-party <em>distribution packages</em>
  200. installed into Python’s <code class="docutils literal notranslate"><span class="pre">site-packages</span></code> directory via tools such as
  201. <a class="reference external" href="https://pypi.org/project/pip/">pip</a>.
  202. Specifically, it works with distributions with discoverable
  203. <code class="docutils literal notranslate"><span class="pre">dist-info</span></code> or <code class="docutils literal notranslate"><span class="pre">egg-info</span></code> directories,
  204. and metadata defined by the <a class="reference external" href="https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata">Core metadata specifications</a>.</p>
  205. <div class="admonition important">
  206. <p class="admonition-title">Important</p>
  207. <p>These are <em>not</em> necessarily equivalent to or correspond 1:1 with
  208. the top-level <em>import package</em> names
  209. that can be imported inside Python code.
  210. One <em>distribution package</em> can contain multiple <em>import packages</em>
  211. (and single modules),
  212. and one top-level <em>import package</em>
  213. may map to multiple <em>distribution packages</em>
  214. if it is a namespace package.
  215. You can use <a class="reference internal" href="#package-distributions"><span class="std std-ref">package_distributions()</span></a>
  216. to get a mapping between them.</p>
  217. </div>
  218. <p>By default, distribution metadata can live on the file system
  219. or in zip archives on
  220. <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>. Through an extension mechanism, the metadata can live almost
  221. anywhere.</p>
  222. <div class="admonition seealso">
  223. <p class="admonition-title">See also</p>
  224. <dl class="simple">
  225. <dt><a class="reference external" href="https://importlib-metadata.readthedocs.io/">https://importlib-metadata.readthedocs.io/</a></dt><dd><p>The documentation for <code class="docutils literal notranslate"><span class="pre">importlib_metadata</span></code>, which supplies a
  226. backport of <code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code>.
  227. This includes an <a class="reference external" href="https://importlib-metadata.readthedocs.io/en/latest/api.html">API reference</a>
  228. for this module’s classes and functions,
  229. as well as a <a class="reference external" href="https://importlib-metadata.readthedocs.io/en/latest/migration.html">migration guide</a>
  230. for existing users of <code class="docutils literal notranslate"><span class="pre">pkg_resources</span></code>.</p>
  231. </dd>
  232. </dl>
  233. </div>
  234. <section id="overview">
  235. <h2>Overview<a class="headerlink" href="#overview" title="Link to this heading">¶</a></h2>
  236. <p>Let’s say you wanted to get the version string for a
  237. <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a> you’ve installed
  238. using <code class="docutils literal notranslate"><span class="pre">pip</span></code>. We start by creating a virtual environment and installing
  239. something into it:</p>
  240. <div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>venv<span class="w"> </span>example
  241. <span class="gp">$ </span><span class="nb">source</span><span class="w"> </span>example/bin/activate
  242. <span class="gp gp-VirtualEnv">(example)</span> <span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>wheel
  243. </pre></div>
  244. </div>
  245. <p>You can get the version string for <code class="docutils literal notranslate"><span class="pre">wheel</span></code> by running the following:</p>
  246. <div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="go">(example) $ python</span>
  247. <span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">importlib.metadata</span> <span class="kn">import</span> <span class="n">version</span>
  248. <span class="gp">&gt;&gt;&gt; </span><span class="n">version</span><span class="p">(</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span>
  249. <span class="go">&#39;0.32.3&#39;</span>
  250. </pre></div>
  251. </div>
  252. <p>You can also get a collection of entry points selectable by properties of the EntryPoint (typically ‘group’ or ‘name’), such as
  253. <code class="docutils literal notranslate"><span class="pre">console_scripts</span></code>, <code class="docutils literal notranslate"><span class="pre">distutils.commands</span></code> and others. Each group contains a
  254. collection of <a class="reference internal" href="#entry-points"><span class="std std-ref">EntryPoint</span></a> objects.</p>
  255. <p>You can get the <a class="reference internal" href="#metadata"><span class="std std-ref">metadata for a distribution</span></a>:</p>
  256. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">metadata</span><span class="p">(</span><span class="s1">&#39;wheel&#39;</span><span class="p">))</span>
  257. <span class="go">[&#39;Metadata-Version&#39;, &#39;Name&#39;, &#39;Version&#39;, &#39;Summary&#39;, &#39;Home-page&#39;, &#39;Author&#39;, &#39;Author-email&#39;, &#39;Maintainer&#39;, &#39;Maintainer-email&#39;, &#39;License&#39;, &#39;Project-URL&#39;, &#39;Project-URL&#39;, &#39;Project-URL&#39;, &#39;Keywords&#39;, &#39;Platform&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Classifier&#39;, &#39;Requires-Python&#39;, &#39;Provides-Extra&#39;, &#39;Requires-Dist&#39;, &#39;Requires-Dist&#39;]</span>
  258. </pre></div>
  259. </div>
  260. <p>You can also get a <a class="reference internal" href="#version"><span class="std std-ref">distribution’s version number</span></a>, list its
  261. <a class="reference internal" href="#files"><span class="std std-ref">constituent files</span></a>, and get a list of the distribution’s
  262. <a class="reference internal" href="#requirements"><span class="std std-ref">Distribution requirements</span></a>.</p>
  263. </section>
  264. <section id="functional-api">
  265. <h2>Functional API<a class="headerlink" href="#functional-api" title="Link to this heading">¶</a></h2>
  266. <p>This package provides the following functionality via its public API.</p>
  267. <section id="entry-points">
  268. <span id="id2"></span><h3>Entry points<a class="headerlink" href="#entry-points" title="Link to this heading">¶</a></h3>
  269. <p>The <code class="docutils literal notranslate"><span class="pre">entry_points()</span></code> function returns a collection of entry points.
  270. Entry points are represented by <code class="docutils literal notranslate"><span class="pre">EntryPoint</span></code> instances;
  271. each <code class="docutils literal notranslate"><span class="pre">EntryPoint</span></code> has a <code class="docutils literal notranslate"><span class="pre">.name</span></code>, <code class="docutils literal notranslate"><span class="pre">.group</span></code>, and <code class="docutils literal notranslate"><span class="pre">.value</span></code> attributes and
  272. a <code class="docutils literal notranslate"><span class="pre">.load()</span></code> method to resolve the value. There are also <code class="docutils literal notranslate"><span class="pre">.module</span></code>,
  273. <code class="docutils literal notranslate"><span class="pre">.attr</span></code>, and <code class="docutils literal notranslate"><span class="pre">.extras</span></code> attributes for getting the components of the
  274. <code class="docutils literal notranslate"><span class="pre">.value</span></code> attribute.</p>
  275. <p>Query all entry points:</p>
  276. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eps</span> <span class="o">=</span> <span class="n">entry_points</span><span class="p">()</span>
  277. </pre></div>
  278. </div>
  279. <p>The <code class="docutils literal notranslate"><span class="pre">entry_points()</span></code> function returns an <code class="docutils literal notranslate"><span class="pre">EntryPoints</span></code> object,
  280. a collection of all <code class="docutils literal notranslate"><span class="pre">EntryPoint</span></code> objects with <code class="docutils literal notranslate"><span class="pre">names</span></code> and <code class="docutils literal notranslate"><span class="pre">groups</span></code>
  281. attributes for convenience:</p>
  282. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">sorted</span><span class="p">(</span><span class="n">eps</span><span class="o">.</span><span class="n">groups</span><span class="p">)</span>
  283. <span class="go">[&#39;console_scripts&#39;, &#39;distutils.commands&#39;, &#39;distutils.setup_keywords&#39;, &#39;egg_info.writers&#39;, &#39;setuptools.installation&#39;]</span>
  284. </pre></div>
  285. </div>
  286. <p><code class="docutils literal notranslate"><span class="pre">EntryPoints</span></code> has a <code class="docutils literal notranslate"><span class="pre">select</span></code> method to select entry points
  287. matching specific properties. Select entry points in the
  288. <code class="docutils literal notranslate"><span class="pre">console_scripts</span></code> group:</p>
  289. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">scripts</span> <span class="o">=</span> <span class="n">eps</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">group</span><span class="o">=</span><span class="s1">&#39;console_scripts&#39;</span><span class="p">)</span>
  290. </pre></div>
  291. </div>
  292. <p>Equivalently, since <code class="docutils literal notranslate"><span class="pre">entry_points</span></code> passes keyword arguments
  293. through to select:</p>
  294. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">scripts</span> <span class="o">=</span> <span class="n">entry_points</span><span class="p">(</span><span class="n">group</span><span class="o">=</span><span class="s1">&#39;console_scripts&#39;</span><span class="p">)</span>
  295. </pre></div>
  296. </div>
  297. <p>Pick out a specific script named “wheel” (found in the wheel project):</p>
  298. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;wheel&#39;</span> <span class="ow">in</span> <span class="n">scripts</span><span class="o">.</span><span class="n">names</span>
  299. <span class="go">True</span>
  300. <span class="gp">&gt;&gt;&gt; </span><span class="n">wheel</span> <span class="o">=</span> <span class="n">scripts</span><span class="p">[</span><span class="s1">&#39;wheel&#39;</span><span class="p">]</span>
  301. </pre></div>
  302. </div>
  303. <p>Equivalently, query for that entry point during selection:</p>
  304. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">wheel</span><span class="p">,)</span> <span class="o">=</span> <span class="n">entry_points</span><span class="p">(</span><span class="n">group</span><span class="o">=</span><span class="s1">&#39;console_scripts&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span>
  305. <span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">wheel</span><span class="p">,)</span> <span class="o">=</span> <span class="n">entry_points</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">group</span><span class="o">=</span><span class="s1">&#39;console_scripts&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span>
  306. </pre></div>
  307. </div>
  308. <p>Inspect the resolved entry point:</p>
  309. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">wheel</span>
  310. <span class="go">EntryPoint(name=&#39;wheel&#39;, value=&#39;wheel.cli:main&#39;, group=&#39;console_scripts&#39;)</span>
  311. <span class="gp">&gt;&gt;&gt; </span><span class="n">wheel</span><span class="o">.</span><span class="n">module</span>
  312. <span class="go">&#39;wheel.cli&#39;</span>
  313. <span class="gp">&gt;&gt;&gt; </span><span class="n">wheel</span><span class="o">.</span><span class="n">attr</span>
  314. <span class="go">&#39;main&#39;</span>
  315. <span class="gp">&gt;&gt;&gt; </span><span class="n">wheel</span><span class="o">.</span><span class="n">extras</span>
  316. <span class="go">[]</span>
  317. <span class="gp">&gt;&gt;&gt; </span><span class="n">main</span> <span class="o">=</span> <span class="n">wheel</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
  318. <span class="gp">&gt;&gt;&gt; </span><span class="n">main</span>
  319. <span class="go">&lt;function main at 0x103528488&gt;</span>
  320. </pre></div>
  321. </div>
  322. <p>The <code class="docutils literal notranslate"><span class="pre">group</span></code> and <code class="docutils literal notranslate"><span class="pre">name</span></code> are arbitrary values defined by the package author
  323. and usually a client will wish to resolve all entry points for a particular
  324. group. Read <a class="reference external" href="https://setuptools.pypa.io/en/latest/userguide/entry_point.html">the setuptools docs</a>
  325. for more information on entry points, their definition, and usage.</p>
  326. <p><em>Compatibility Note</em></p>
  327. <p>The “selectable” entry points were introduced in <code class="docutils literal notranslate"><span class="pre">importlib_metadata</span></code>
  328. 3.6 and Python 3.10. Prior to those changes, <code class="docutils literal notranslate"><span class="pre">entry_points</span></code> accepted
  329. no parameters and always returned a dictionary of entry points, keyed
  330. by group. With <code class="docutils literal notranslate"><span class="pre">importlib_metadata</span></code> 5.0 and Python 3.12,
  331. <code class="docutils literal notranslate"><span class="pre">entry_points</span></code> always returns an <code class="docutils literal notranslate"><span class="pre">EntryPoints</span></code> object. See
  332. <a class="reference external" href="https://pypi.org/project/backports.entry-points-selectable">backports.entry_points_selectable</a>
  333. for compatibility options.</p>
  334. </section>
  335. <section id="distribution-metadata">
  336. <span id="metadata"></span><h3>Distribution metadata<a class="headerlink" href="#distribution-metadata" title="Link to this heading">¶</a></h3>
  337. <p>Every <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a> includes some metadata,
  338. which you can extract using the
  339. <code class="docutils literal notranslate"><span class="pre">metadata()</span></code> function:</p>
  340. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">wheel_metadata</span> <span class="o">=</span> <span class="n">metadata</span><span class="p">(</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span>
  341. </pre></div>
  342. </div>
  343. <p>The keys of the returned data structure, a <code class="docutils literal notranslate"><span class="pre">PackageMetadata</span></code>,
  344. name the metadata keywords, and
  345. the values are returned unparsed from the distribution metadata:</p>
  346. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">wheel_metadata</span><span class="p">[</span><span class="s1">&#39;Requires-Python&#39;</span><span class="p">]</span>
  347. <span class="go">&#39;&gt;=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*&#39;</span>
  348. </pre></div>
  349. </div>
  350. <p><code class="docutils literal notranslate"><span class="pre">PackageMetadata</span></code> also presents a <code class="docutils literal notranslate"><span class="pre">json</span></code> attribute that returns
  351. all the metadata in a JSON-compatible form per <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0566/"><strong>PEP 566</strong></a>:</p>
  352. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">wheel_metadata</span><span class="o">.</span><span class="n">json</span><span class="p">[</span><span class="s1">&#39;requires_python&#39;</span><span class="p">]</span>
  353. <span class="go">&#39;&gt;=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*&#39;</span>
  354. </pre></div>
  355. </div>
  356. <div class="admonition note">
  357. <p class="admonition-title">Note</p>
  358. <p>The actual type of the object returned by <code class="docutils literal notranslate"><span class="pre">metadata()</span></code> is an
  359. implementation detail and should be accessed only through the interface
  360. described by the
  361. <a class="reference external" href="https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.PackageMetadata">PackageMetadata protocol</a>.</p>
  362. </div>
  363. <div class="versionchanged">
  364. <p><span class="versionmodified changed">Changed in version 3.10: </span>The <code class="docutils literal notranslate"><span class="pre">Description</span></code> is now included in the metadata when presented
  365. through the payload. Line continuation characters have been removed.</p>
  366. <p>The <code class="docutils literal notranslate"><span class="pre">json</span></code> attribute was added.</p>
  367. </div>
  368. </section>
  369. <section id="distribution-versions">
  370. <span id="version"></span><h3>Distribution versions<a class="headerlink" href="#distribution-versions" title="Link to this heading">¶</a></h3>
  371. <p>The <code class="docutils literal notranslate"><span class="pre">version()</span></code> function is the quickest way to get a
  372. <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a>’s version
  373. number, as a string:</p>
  374. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">version</span><span class="p">(</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span>
  375. <span class="go">&#39;0.32.3&#39;</span>
  376. </pre></div>
  377. </div>
  378. </section>
  379. <section id="distribution-files">
  380. <span id="files"></span><h3>Distribution files<a class="headerlink" href="#distribution-files" title="Link to this heading">¶</a></h3>
  381. <p>You can also get the full set of files contained within a distribution. The
  382. <code class="docutils literal notranslate"><span class="pre">files()</span></code> function takes a <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a> name
  383. and returns all of the
  384. files installed by this distribution. Each file object returned is a
  385. <code class="docutils literal notranslate"><span class="pre">PackagePath</span></code>, a <a class="reference internal" href="pathlib.html#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.PurePath</span></code></a> derived object with additional <code class="docutils literal notranslate"><span class="pre">dist</span></code>,
  386. <code class="docutils literal notranslate"><span class="pre">size</span></code>, and <code class="docutils literal notranslate"><span class="pre">hash</span></code> properties as indicated by the metadata. For example:</p>
  387. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">util</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">files</span><span class="p">(</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span> <span class="k">if</span> <span class="s1">&#39;util.py&#39;</span> <span class="ow">in</span> <span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)][</span><span class="mi">0</span><span class="p">]</span>
  388. <span class="gp">&gt;&gt;&gt; </span><span class="n">util</span>
  389. <span class="go">PackagePath(&#39;wheel/util.py&#39;)</span>
  390. <span class="gp">&gt;&gt;&gt; </span><span class="n">util</span><span class="o">.</span><span class="n">size</span>
  391. <span class="go">859</span>
  392. <span class="gp">&gt;&gt;&gt; </span><span class="n">util</span><span class="o">.</span><span class="n">dist</span>
  393. <span class="go">&lt;importlib.metadata._hooks.PathDistribution object at 0x101e0cef0&gt;</span>
  394. <span class="gp">&gt;&gt;&gt; </span><span class="n">util</span><span class="o">.</span><span class="n">hash</span>
  395. <span class="go">&lt;FileHash mode: sha256 value: bYkw5oMccfazVCoYQwKkkemoVyMAFoR34mmKBx8R1NI&gt;</span>
  396. </pre></div>
  397. </div>
  398. <p>Once you have the file, you can also read its contents:</p>
  399. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">util</span><span class="o">.</span><span class="n">read_text</span><span class="p">())</span>
  400. <span class="go">import base64</span>
  401. <span class="go">import sys</span>
  402. <span class="go">...</span>
  403. <span class="go">def as_bytes(s):</span>
  404. <span class="go"> if isinstance(s, text_type):</span>
  405. <span class="go"> return s.encode(&#39;utf-8&#39;)</span>
  406. <span class="go"> return s</span>
  407. </pre></div>
  408. </div>
  409. <p>You can also use the <code class="docutils literal notranslate"><span class="pre">locate</span></code> method to get a the absolute path to the
  410. file:</p>
  411. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">util</span><span class="o">.</span><span class="n">locate</span><span class="p">()</span>
  412. <span class="go">PosixPath(&#39;/home/gustav/example/lib/site-packages/wheel/util.py&#39;)</span>
  413. </pre></div>
  414. </div>
  415. <p>In the case where the metadata file listing files
  416. (RECORD or SOURCES.txt) is missing, <code class="docutils literal notranslate"><span class="pre">files()</span></code> will
  417. return <code class="docutils literal notranslate"><span class="pre">None</span></code>. The caller may wish to wrap calls to
  418. <code class="docutils literal notranslate"><span class="pre">files()</span></code> in <a class="reference external" href="https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.always_iterable">always_iterable</a>
  419. or otherwise guard against this condition if the target
  420. distribution is not known to have the metadata present.</p>
  421. </section>
  422. <section id="distribution-requirements">
  423. <span id="requirements"></span><h3>Distribution requirements<a class="headerlink" href="#distribution-requirements" title="Link to this heading">¶</a></h3>
  424. <p>To get the full set of requirements for a <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a>,
  425. use the <code class="docutils literal notranslate"><span class="pre">requires()</span></code>
  426. function:</p>
  427. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">requires</span><span class="p">(</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span>
  428. <span class="go">[&quot;pytest (&gt;=3.0.0) ; extra == &#39;test&#39;&quot;, &quot;pytest-cov ; extra == &#39;test&#39;&quot;]</span>
  429. </pre></div>
  430. </div>
  431. </section>
  432. <section id="mapping-import-to-distribution-packages">
  433. <span id="import-distribution-package-mapping"></span><span id="package-distributions"></span><h3>Mapping import to distribution packages<a class="headerlink" href="#mapping-import-to-distribution-packages" title="Link to this heading">¶</a></h3>
  434. <p>A convenience method to resolve the <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a>
  435. name (or names, in the case of a namespace package)
  436. that provide each importable top-level
  437. Python module or <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Import-Package">Import Package</a>:</p>
  438. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">packages_distributions</span><span class="p">()</span>
  439. <span class="go">{&#39;importlib_metadata&#39;: [&#39;importlib-metadata&#39;], &#39;yaml&#39;: [&#39;PyYAML&#39;], &#39;jaraco&#39;: [&#39;jaraco.classes&#39;, &#39;jaraco.functools&#39;], ...}</span>
  440. </pre></div>
  441. </div>
  442. <p>Some editable installs, <a class="reference external" href="https://github.com/pypa/packaging-problems/issues/609">do not supply top-level names</a>, and thus this
  443. function is not reliable with such installs.</p>
  444. <div class="versionadded">
  445. <p><span class="versionmodified added">New in version 3.10.</span></p>
  446. </div>
  447. </section>
  448. </section>
  449. <section id="distributions">
  450. <span id="id9"></span><h2>Distributions<a class="headerlink" href="#distributions" title="Link to this heading">¶</a></h2>
  451. <p>While the above API is the most common and convenient usage, you can get all
  452. of that information from the <code class="docutils literal notranslate"><span class="pre">Distribution</span></code> class. A <code class="docutils literal notranslate"><span class="pre">Distribution</span></code> is an
  453. abstract object that represents the metadata for
  454. a Python <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a>. You can
  455. get the <code class="docutils literal notranslate"><span class="pre">Distribution</span></code> instance:</p>
  456. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">importlib.metadata</span> <span class="kn">import</span> <span class="n">distribution</span>
  457. <span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span> <span class="o">=</span> <span class="n">distribution</span><span class="p">(</span><span class="s1">&#39;wheel&#39;</span><span class="p">)</span>
  458. </pre></div>
  459. </div>
  460. <p>Thus, an alternative way to get the version number is through the
  461. <code class="docutils literal notranslate"><span class="pre">Distribution</span></code> instance:</p>
  462. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span><span class="o">.</span><span class="n">version</span>
  463. <span class="go">&#39;0.32.3&#39;</span>
  464. </pre></div>
  465. </div>
  466. <p>There are all kinds of additional metadata available on the <code class="docutils literal notranslate"><span class="pre">Distribution</span></code>
  467. instance:</p>
  468. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span><span class="o">.</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;Requires-Python&#39;</span><span class="p">]</span>
  469. <span class="go">&#39;&gt;=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*&#39;</span>
  470. <span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span><span class="o">.</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;License&#39;</span><span class="p">]</span>
  471. <span class="go">&#39;MIT&#39;</span>
  472. </pre></div>
  473. </div>
  474. <p>The full set of available metadata is not described here.
  475. See the <a class="reference external" href="https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata">Core metadata specifications</a> for additional details.</p>
  476. </section>
  477. <section id="distribution-discovery">
  478. <h2>Distribution Discovery<a class="headerlink" href="#distribution-discovery" title="Link to this heading">¶</a></h2>
  479. <p>By default, this package provides built-in support for discovery of metadata
  480. for file system and zip file <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a>s.
  481. This metadata finder search defaults to <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>, but varies slightly in how it interprets those values from how other import machinery does. In particular:</p>
  482. <ul class="simple">
  483. <li><p><code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> does not honor <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> objects on <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>.</p></li>
  484. <li><p><code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> will incidentally honor <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> objects on <code class="docutils literal notranslate"><span class="pre">sys.path</span></code> even though such values will be ignored for imports.</p></li>
  485. </ul>
  486. </section>
  487. <section id="extending-the-search-algorithm">
  488. <h2>Extending the search algorithm<a class="headerlink" href="#extending-the-search-algorithm" title="Link to this heading">¶</a></h2>
  489. <p>Because <a class="reference external" href="https://packaging.python.org/en/latest/glossary/#term-Distribution-Package">Distribution Package</a> metadata
  490. is not available through <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> searches, or
  491. package loaders directly,
  492. the metadata for a distribution is found through import
  493. system <a class="reference internal" href="../reference/import.html#finders-and-loaders"><span class="std std-ref">finders</span></a>. To find a distribution package’s metadata,
  494. <code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> queries the list of <a class="reference internal" href="../glossary.html#term-meta-path-finder"><span class="xref std std-term">meta path finders</span></a> on
  495. <a class="reference internal" href="sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a>.</p>
  496. <p>By default <code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> installs a finder for distribution packages
  497. found on the file system.
  498. This finder doesn’t actually find any <em>distributions</em>,
  499. but it can find their metadata.</p>
  500. <p>The abstract class <a class="reference internal" href="importlib.html#importlib.abc.MetaPathFinder" title="importlib.abc.MetaPathFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder</span></code></a> defines the
  501. interface expected of finders by Python’s import system.
  502. <code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> extends this protocol by looking for an optional
  503. <code class="docutils literal notranslate"><span class="pre">find_distributions</span></code> callable on the finders from
  504. <a class="reference internal" href="sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a> and presents this extended interface as the
  505. <code class="docutils literal notranslate"><span class="pre">DistributionFinder</span></code> abstract base class, which defines this abstract
  506. method:</p>
  507. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
  508. <span class="k">def</span> <span class="nf">find_distributions</span><span class="p">(</span><span class="n">context</span><span class="o">=</span><span class="n">DistributionFinder</span><span class="o">.</span><span class="n">Context</span><span class="p">()):</span>
  509. <span class="w"> </span><span class="sd">&quot;&quot;&quot;Return an iterable of all Distribution instances capable of</span>
  510. <span class="sd"> loading the metadata for packages for the indicated ``context``.</span>
  511. <span class="sd"> &quot;&quot;&quot;</span>
  512. </pre></div>
  513. </div>
  514. <p>The <code class="docutils literal notranslate"><span class="pre">DistributionFinder.Context</span></code> object provides <code class="docutils literal notranslate"><span class="pre">.path</span></code> and <code class="docutils literal notranslate"><span class="pre">.name</span></code>
  515. properties indicating the path to search and name to match and may
  516. supply other relevant context.</p>
  517. <p>What this means in practice is that to support finding distribution package
  518. metadata in locations other than the file system, subclass
  519. <code class="docutils literal notranslate"><span class="pre">Distribution</span></code> and implement the abstract methods. Then from
  520. a custom finder, return instances of this derived <code class="docutils literal notranslate"><span class="pre">Distribution</span></code> in the
  521. <code class="docutils literal notranslate"><span class="pre">find_distributions()</span></code> method.</p>
  522. </section>
  523. </section>
  524. <div class="clearer"></div>
  525. </div>
  526. </div>
  527. </div>
  528. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  529. <div class="sphinxsidebarwrapper">
  530. <div>
  531. <h3><a href="../contents.html">Table of Contents</a></h3>
  532. <ul>
  533. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</a><ul>
  534. <li><a class="reference internal" href="#overview">Overview</a></li>
  535. <li><a class="reference internal" href="#functional-api">Functional API</a><ul>
  536. <li><a class="reference internal" href="#entry-points">Entry points</a></li>
  537. <li><a class="reference internal" href="#distribution-metadata">Distribution metadata</a></li>
  538. <li><a class="reference internal" href="#distribution-versions">Distribution versions</a></li>
  539. <li><a class="reference internal" href="#distribution-files">Distribution files</a></li>
  540. <li><a class="reference internal" href="#distribution-requirements">Distribution requirements</a></li>
  541. <li><a class="reference internal" href="#mapping-import-to-distribution-packages">Mapping import to distribution packages</a></li>
  542. </ul>
  543. </li>
  544. <li><a class="reference internal" href="#distributions">Distributions</a></li>
  545. <li><a class="reference internal" href="#distribution-discovery">Distribution Discovery</a></li>
  546. <li><a class="reference internal" href="#extending-the-search-algorithm">Extending the search algorithm</a></li>
  547. </ul>
  548. </li>
  549. </ul>
  550. </div>
  551. <div>
  552. <h4>Previous topic</h4>
  553. <p class="topless"><a href="importlib.resources.abc.html"
  554. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code> – Abstract base classes for resources</a></p>
  555. </div>
  556. <div>
  557. <h4>Next topic</h4>
  558. <p class="topless"><a href="sys_path_init.html"
  559. title="next chapter">The initialization of the <code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code> module search path</a></p>
  560. </div>
  561. <div role="note" aria-label="source link">
  562. <h3>This Page</h3>
  563. <ul class="this-page-menu">
  564. <li><a href="../bugs.html">Report a Bug</a></li>
  565. <li>
  566. <a href="https://github.com/python/cpython/blob/main/Doc/library/importlib.metadata.rst"
  567. rel="nofollow">Show Source
  568. </a>
  569. </li>
  570. </ul>
  571. </div>
  572. </div>
  573. <div id="sidebarbutton" title="Collapse sidebar">
  574. <span>«</span>
  575. </div>
  576. </div>
  577. <div class="clearer"></div>
  578. </div>
  579. <div class="related" role="navigation" aria-label="related navigation">
  580. <h3>Navigation</h3>
  581. <ul>
  582. <li class="right" style="margin-right: 10px">
  583. <a href="../genindex.html" title="General Index"
  584. >index</a></li>
  585. <li class="right" >
  586. <a href="../py-modindex.html" title="Python Module Index"
  587. >modules</a> |</li>
  588. <li class="right" >
  589. <a href="sys_path_init.html" title="The initialization of the sys.path module search path"
  590. >next</a> |</li>
  591. <li class="right" >
  592. <a href="importlib.resources.abc.html" title="importlib.resources.abc – Abstract base classes for resources"
  593. >previous</a> |</li>
  594. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  595. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  596. <li class="switchers">
  597. <div class="language_switcher_placeholder"></div>
  598. <div class="version_switcher_placeholder"></div>
  599. </li>
  600. <li>
  601. </li>
  602. <li id="cpython-language-and-version">
  603. <a href="../index.html">3.12.3 Documentation</a> &#187;
  604. </li>
  605. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  606. <li class="nav-item nav-item-2"><a href="modules.html" >Importing Modules</a> &#187;</li>
  607. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</a></li>
  608. <li class="right">
  609. <div class="inline-search" role="search">
  610. <form class="inline-search" action="../search.html" method="get">
  611. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  612. <input type="submit" value="Go" />
  613. </form>
  614. </div>
  615. |
  616. </li>
  617. <li class="right">
  618. <label class="theme-selector-label">
  619. Theme
  620. <select class="theme-selector" oninput="activateTheme(this.value)">
  621. <option value="auto" selected>Auto</option>
  622. <option value="light">Light</option>
  623. <option value="dark">Dark</option>
  624. </select>
  625. </label> |</li>
  626. </ul>
  627. </div>
  628. <div class="footer">
  629. &copy;
  630. <a href="../copyright.html">
  631. Copyright
  632. </a>
  633. 2001-2024, Python Software Foundation.
  634. <br />
  635. This page is licensed under the Python Software Foundation License Version 2.
  636. <br />
  637. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  638. <br />
  639. See <a href="/license.html">History and License</a> for more information.<br />
  640. <br />
  641. The Python Software Foundation is a non-profit corporation.
  642. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  643. <br />
  644. <br />
  645. Last updated on Apr 09, 2024 (13:47 UTC).
  646. <a href="/bugs.html">Found a bug</a>?
  647. <br />
  648. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  649. </div>
  650. </body>
  651. </html>
上海开阖软件有限公司 沪ICP备12045867号-1