Skip to content

Mention alternatives to discover plugins via entry_points #870

Description

@ashwinvis

In "Creating and discovering plugins" guide, the recommendation is to use pkg_resources.iter_entry_points. In https://github.com/takluyver/entrypoints it is noted that:

The pkg_resources module distributed with setuptools provides a way to discover entrypoints as well, but it contains other functionality unrelated to entrypoint discovery, and it does a lot of work at import time. Merely importing pkg_resources causes it to scan the files of all installed packages. Thus, in environments where a large number of packages are installed, importing pkg_resources can be very slow (several seconds).

I agree with this observation too. Now with the standard library importlib.metadata feature landing in Python 3.10+ and its backport, this recommendation can be updated with more lighter:

import sys
if sys.version_info[:2] < (3, 10):
    from backports.entry_points_selectable import entry_points
else:
    from importlib.metadata import entry_points

...
entry_points(group='myapp.plugins')

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions