Utilities for plugin loading and selection


class EntryPointAlike(obj, name=None)[source]

A dummy EntryPoint substitute to be used with selectEntryPoints() for wrapping arbitrary objects and imitate the name and load() API of a pkg_resources.EntryPoint instance.

Pass an object and optionally a name to the constructor to get the wrapped EntryPointAlike instance. The repr of the object is used as the name if name arg is not provided.

(more info)


selectEntryPoints(group=None, include=('.*',), exclude=())[source]

Selects and prioritizes entry points from an entry point group.

The entry points are selected using their name.

The selection is done by regex matching on the names: first the entry points whose name matches any of the patterns in excluded are discarded; then each pattern in included is used to select from the names of the remaining entry points (from highest to lowest priority).

In this way, the entry points are selected in the order dictated by the included pattern list. If a pattern matches several names, these will be sorted alphabetically. If a name is matched by several patterns, it is only selected by the first pattern.

For example, if there are the following registered entry point names: [‘foo1’, ‘foo2’, ‘baz1’, ‘baz2’, ‘bar1’, ‘bar2’] And we use exclude=(“foo2”,) and include=(“bar2”, “b.*1”, “f.*”) , then the selection will be: [“bar2”,”bar1”,”baz1”,”foo1”]

Note: apart from regex patterns (strings or compiled) the include list can also contain pkg_resources`EntryPoint-like instances (more specifically, an object having .name and .load() members), in which case they are added directly to the selected list. If a member is something other than a pattern or an EntryPoint-like object, it will be wrapped in an EntryPointAlike instance and also included in the selection.

  • group (str) – entry point group name from which the entry points are obtained.

  • include (tuple) – The members of the tuple can either be patterns (both in the form of strings or of re.Pattern objects), which will be matched against registered names in group; or EntryPoint-like objects which will be included as they are; or an arbitrary object which will be wrapped as an EntryPoint-like object before being included. Default is (“.*”,), which matches all registered names in group and the sort is purely alphabetical.

  • exclude (tuple) – Regexp patterns (either str or re.Pattern objects) matching names to be excluded. Default is (), so no entry point is excluded.


the selected entry points.

Return type:

list of pkg_resources.EntryPoint