|
2 | 2 | Package Discovery and Resource Access using ``pkg_resources`` |
3 | 3 | ============================================================= |
4 | 4 |
|
5 | | -The ``pkg_resources`` module distributed with ``setuptools`` provides an API |
| 5 | +.. attention:: **This documentation is retained solely for historical purposes** |
| 6 | + |
| 7 | + ``pkg_resources`` has long been **discouraged** due to architectural |
| 8 | + limitations that led to persistent performance issues. |
| 9 | + These limitations were inherent to its design (e.g. importing on startup, |
| 10 | + scanning the entire environment for metadata, and eager, global |
| 11 | + working‑set management) and could not be corrected. |
| 12 | + |
| 13 | + .. version-deprecated:: v67.5.0 |
| 14 | + ``pkg_resources`` issued official deprecation warnings as early as |
| 15 | + ``setuptools`` **v67.5.0**. |
| 16 | + |
| 17 | + .. version-removed:: v82.0.0 |
| 18 | + ``pkg_resources`` is no longer maintained, no longer used internally by |
| 19 | + ``setuptools``, and is no longer included in current |
| 20 | + distributions/installations as of ``setuptools`` **v82.0.0**. |
| 21 | + |
| 22 | + Projects must migrate away from ``pkg_resources``. The recommended |
| 23 | + replacements are: |
| 24 | + |
| 25 | + * Resource access: use :mod:`importlib.resources` |
| 26 | + (or its backport :pypi:`importlib_resources`). |
| 27 | + * Distribution metadata & entry points: use :mod:`importlib.metadata` |
| 28 | + (or its backport :pypi:`importlib_metadata`). |
| 29 | + * Requirement and version parsing: use :pypi:`packaging`. |
| 30 | + This includes parsing and evaluating ``extras`` and markers via |
| 31 | + ``packaging.requirements.Requirement`` and ``packaging.markers.Marker``. |
| 32 | + Note that automatic installation or detection of extras is not provided; |
| 33 | + projects requiring that behaviour must implement it themselves using |
| 34 | + a combination of ``packaging``, ``importlib.metadata`` and other tools |
| 35 | + as building blocks. |
| 36 | + * Coexistence of multiple versions of a package: please consider using a different |
| 37 | + approach, as this functionality is not supported by Python itself. |
| 38 | + Alternatives include isolated environments and orchestration tools |
| 39 | + (:mod:`venv`, :pypi:`tox`, :pypi:`nox`, etc.). |
| 40 | + * Handling of ``.egg`` distributions: please consider using a different |
| 41 | + approach, as the ``.egg`` and ``easy_install`` mechanisms have also been |
| 42 | + discontinued. |
| 43 | + Please use currently supported packaging formats |
| 44 | + (see :external+PyPUG:`specifications/section-distribution-formats`) |
| 45 | + and build/installation workflows (see :pep:`517`). |
| 46 | + |
| 47 | + **Note:** The following documentation may no longer accurately describe the |
| 48 | + behaviour of the distributed package and has been frozen at the last |
| 49 | + ``setuptools`` release that still contained ``pkg_resources``. |
| 50 | + |
| 51 | + |
| 52 | +The ``pkg_resources`` module provides an API |
6 | 53 | for Python libraries to access their resource files, and for extensible |
7 | 54 | applications and frameworks to automatically discover plugins. It also |
8 | 55 | provides runtime support for using C extensions that are inside zipfile-format |
9 | 56 | eggs, support for merging packages that have separately-distributed modules or |
10 | 57 | subpackages, and APIs for managing Python's current "working set" of active |
11 | 58 | packages. |
12 | 59 |
|
13 | | -.. attention:: |
14 | | - Use of ``pkg_resources`` is deprecated in favor of |
15 | | - :mod:`importlib.resources`, :mod:`importlib.metadata` |
16 | | - and their backports (:pypi:`importlib_resources`, :pypi:`importlib_metadata`). |
17 | | - Some useful APIs are also provided by :pypi:`packaging` (e.g. requirements |
18 | | - and version parsing). |
19 | | - Users should refrain from new usage of ``pkg_resources`` and |
20 | | - should work to port to importlib-based solutions. |
21 | | - |
22 | 60 |
|
23 | 61 | -------- |
24 | 62 | Overview |
|
0 commit comments