1
1
.. _using :
2
2
3
3
==========================
4
- Using importlib_metadata
4
+ Using importlib.metadata
5
5
==========================
6
6
7
- ``importlib_metadata `` is a library that provides for access to installed
7
+ ``importlib.metadata `` is a library that provides for access to installed
8
8
package metadata. Built in part on Python's import system, this library
9
9
intends to replace similar functionality in the `entry point
10
10
API `_ and `metadata API `_ of ``pkg_resources ``. Along with
@@ -37,15 +37,18 @@ Let's say you wanted to get the version string for a package you've installed
37
37
using ``pip ``. We start by creating a virtual environment and installing
38
38
something into it::
39
39
40
+ .. highlight :: none
41
+
40
42
$ python3 -m venv example
41
43
$ source example/bin/activate
42
- (example) $ pip install importlib_metadata
43
44
(example) $ pip install wheel
44
45
45
46
You can get the version string for ``wheel `` by running the following::
46
47
48
+ .. highlight :: none
49
+
47
50
(example) $ python
48
- >>> from importlib_metadata import version
51
+ >>> from importlib.metadata import version
49
52
>>> version(' wheel' )
50
53
'0.32.3'
51
54
@@ -143,7 +146,7 @@ files installed by this distribution. Each file object returned is a
143
146
>>> util.size
144
147
859
145
148
>>> util.dist
146
- <importlib_metadata ._hooks.PathDistribution object at 0x101e0cef0>
149
+ <importlib.metadata ._hooks.PathDistribution object at 0x101e0cef0>
147
150
>>> util.hash
148
151
<FileHash mode: sha256 value: bYkw5oMccfazVCoYQwKkkemoVyMAFoR34mmKBx8R1NI>
149
152
@@ -179,7 +182,7 @@ of that information from the ``Distribution`` class. A ``Distribution`` is an
179
182
abstract object that represents the metadata for a Python package. You can
180
183
get the ``Distribution `` instance::
181
184
182
- >>> from importlib_metadata import distribution
185
+ >>> from importlib.metadata import distribution
183
186
>>> dist = distribution('wheel')
184
187
185
188
Thus, an alternative way to get the version number is through the
@@ -206,16 +209,16 @@ Extending the search algorithm
206
209
Because package metadata is not available through ``sys.path `` searches, or
207
210
package loaders directly, the metadata for a package is found through import
208
211
system `finders `_. To find a distribution package's metadata,
209
- ``importlib_metadata `` queries the list of `meta path finders `_ on
212
+ ``importlib.metadata `` queries the list of `meta path finders `_ on
210
213
`sys.meta_path `_.
211
214
212
- By default ``importlib_metadata `` installs a finder for distribution packages
215
+ By default ``importlib.metadata `` installs a finder for distribution packages
213
216
found on the file system. This finder doesn't actually find any *packages *,
214
217
but it can find the packages' metadata.
215
218
216
219
The abstract class :py:class: `importlib.abc.MetaPathFinder ` defines the
217
220
interface expected of finders by Python's import system.
218
- ``importlib_metadata `` extends this protocol by looking for an optional
221
+ ``importlib.metadata `` extends this protocol by looking for an optional
219
222
``find_distributions `` callable on the finders from
220
223
``sys.meta_path ``. If the finder has this method, it must return
221
224
an iterator over instances of the ``Distribution `` abstract class. This
0 commit comments