11.. _using :
22
3- ==========================
4- Using importlib_metadata
5- ==========================
3+ =================================
4+ Using :mod: ` !importlib.metadata `
5+ =================================
66
77``importlib_metadata `` is a library that provides for access to installed
88package metadata. Built in part on Python's import system, this library
99intends to replace similar functionality in the `entry point
1010API `_ and `metadata API `_ of ``pkg_resources ``. Along with
11- `` importlib.resources `` in ` Python 3.7
12- and newer `_ (backported as `importlib_resources `_ for older versions of
11+ :mod: ` importlib.resources ` in Python 3.7
12+ and newer (backported as :doc: `importlib_resources < importlib_resources:index >` for older versions of
1313Python), this can eliminate the need to use the older and less efficient
1414``pkg_resources `` package.
1515
1616By "installed package" we generally mean a third-party package installed into
1717Python's ``site-packages `` directory via tools such as `pip
1818<https://pypi.org/project/pip/> `_. Specifically,
1919it means a package with either a discoverable ``dist-info `` or ``egg-info ``
20- directory, and metadata defined by ` PEP 566 `_ or its older specifications.
20+ directory, and metadata defined by :pep: ` 566 ` or its older specifications.
2121By default, package metadata can live on the file system or in zip archives on
22- `` sys.path ` `. Through an extension mechanism, the metadata can live almost
22+ :data: ` sys.path `. Through an extension mechanism, the metadata can live almost
2323anywhere.
2424
2525
@@ -127,7 +127,7 @@ Distribution files
127127You can also get the full set of files contained within a distribution. The
128128``files() `` function takes a distribution package name and returns all of the
129129files installed by this distribution. Each file object returned is a
130- ``PackagePath ``, a `pathlib.Path `_ derived object with additional ``dist ``,
130+ ``PackagePath ``, a :class: `pathlib.Path ` derived object with additional ``dist ``,
131131``size ``, and ``hash `` properties as indicated by the metadata. For example::
132132
133133 >>> util = [p for p in files('wheel') if 'util.py' in str(p)][0]
@@ -196,18 +196,18 @@ instance::
196196 >>> d.metadata['License']
197197 'MIT'
198198
199- The full set of available metadata is not described here. See ` PEP 566
200- <https://www.python.org/dev/peps/pep-0566/> `_ for additional details.
199+ The full set of available metadata is not described here. See :pep: ` 566 `
200+ for additional details.
201201
202202
203203Extending the search algorithm
204204==============================
205205
206- Because package metadata is not available through `` sys.path ` ` searches, or
206+ Because package metadata is not available through :data: ` sys.path ` searches, or
207207package loaders directly, the metadata for a package is found through import
208208system `finders `_. To find a distribution package's metadata,
209- ``importlib_metadata `` queries the list of `meta path finders `_ on
210- `sys.meta_path `_ .
209+ ``importlib.metadata `` queries the list of :term: `meta path finders <meta path finder> ` on
210+ :data: `sys.meta_path `.
211211
212212By default ``importlib_metadata `` installs a finder for distribution packages
213213found on the file system. This finder doesn't actually find any *packages *,
@@ -217,7 +217,7 @@ The abstract class :py:class:`importlib.abc.MetaPathFinder` defines the
217217interface expected of finders by Python's import system.
218218``importlib_metadata `` extends this protocol by looking for an optional
219219``find_distributions `` callable on the finders from
220- `` sys.meta_path ` ` and presents this extended interface as the
220+ :data: ` sys.meta_path ` and presents this extended interface as the
221221``DistributionFinder `` abstract base class, which defines this abstract
222222method::
223223
@@ -240,20 +240,13 @@ a custom finder, return instances of this derived ``Distribution`` in the
240240
241241.. _`entry point API` : https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
242242.. _`metadata API` : https://setuptools.readthedocs.io/en/latest/pkg_resources.html#metadata-api
243- .. _`Python 3.7 and newer` : https://docs.python.org/3/library/importlib.html#module-importlib.resources
244- .. _`importlib_resources` : https://importlib-resources.readthedocs.io/en/latest/index.html
245- .. _`PEP 566` : https://www.python.org/dev/peps/pep-0566/
246243.. _`finders` : https://docs.python.org/3/reference/import.html#finders-and-loaders
247- .. _`meta path finders` : https://docs.python.org/3/glossary.html#term-meta-path-finder
248- .. _`sys.meta_path` : https://docs.python.org/3/library/sys.html#sys.meta_path
249- .. _`pathlib.Path` : https://docs.python.org/3/library/pathlib.html#pathlib.Path
250244
251245
252246.. rubric :: Footnotes
253247
254248.. [#f1 ] Technically, the returned distribution metadata object is an
255- `email.message.Message
256- <https://docs.python.org/3/library/email.message.html#email.message.EmailMessage> `_
249+ :class: `email.message.EmailMessage `
257250 instance, but this is an implementation detail, and not part of the
258251 stable API. You should only use dictionary-like methods and syntax
259252 to access the metadata contents.
0 commit comments