Api.deregister_all_paths() / api.deregister_all_plugins()

When i’m using pyblish.api.register_plugin_path(r"path_to_plugins") plugins woking and exists in GUI, but when i’m tring to get plugins by pyblish.api.registered_plugins() it returns empty list. I’ve found method pyblish.api.discover(), that returns and register plugins but pyblish.api.registered_plugins() is sill empty list. pyblish.api.deregister_all_plugins() also doesn’t work for me, only pyblish.api.deregister_all_paths() do.
I`m trying to load my plugins then filter them and use only a few.
Here is my try:

pyblish.api.register_plugin_path(r"path_to_plugins")
plugins = pyblish.api.discover()
plugins_to_use = pyblish.api.plugins_by_family(plugins, 'model')
pyblish.api.deregister_all_plugins()
for plugin in plugins_to_use:
    pyblish.api.register_plugin(plugin)

Also when i put plugins from pyblish.api.plugins_by_family() to pyblish.api.register_plugin() it returns an error:
# TypeError: Plug-in must be callable returning an instance of a class #

I guees i`m using api not in a right way = )

EDIT :
I have found one way to do it:

import pyblish.api
def init_proj_plugins(proj):
    pyblish.api.register_plugin_path(r"path_to_plugins")
    all_plugins = pyblish.api.discover()
    pyblish.api.deregister_all_plugins()
    pyblish.api.deregister_all_paths()
    for plugin in all_plugins:
        if proj in plugin.families:
            pyblish.api.register_plugin(plugin)
init_proj_plugins('rig')

Hi @sega,

pyblish.api.registered_plugins() is for getting only plug-ins that you’ve registered.

from pyblish import api


class MyPlugin(api.ContextPlugin):
  pass

api.register_plugin(MyPlugin)
api.registered_plugins()
# [MyPlugin]

pyblish.api.deregister_all_plugins() is for de-registering plug-ins that you’ve previously registered.

I think the confusion here is between plug-ins discovered by path, and plug-ins discovered by registration. Plug-ins discovered from paths you register different. You can get to the paths via pyblish.api.registered_paths(), and finally discover() will return plug-ins from both sources.

Make sure you glance at the introductory material at learn.pyblish.com

1 Like

Thank you @marcus. That was really helpful.
Just one more thing.
What about this error:

Code example:

plugins = pyblish.api.discover()
plugins_to_use = pyblish.api.plugins_by_family(plugins, 'model')
for plugin in plugins_to_use:
    pyblish.api.register_plugin(plugin)

Note that your code example seems rather “double”. The plug-ins retrieved with pyblish.api.discover() can already be found so there’s technically no need to register them explicitly. Or what’s your intended use case?

If you intend to “customize” what plug-ins are to be run than you wouldn’t need to register them but just pass them on yourself to the next methods that process the plug-ins. For example:

plugins = pyblish.api.discover()
plugins_to_use = pyblish.api.plugins_by_family(plugins, 'model')
pyblish.util.publish(plugins=plugins_to_use)

This way you take full control over how publishing is done (and with which plug-ins).


Regarding the error it describes that you should not be passing initialized classes, but instead the class type itself. So, in code that is not Plugin() but Plugin. Though the example code you posted is not giving errors on my end, because discover() should return them as the class itself.

What happens when you print plugins_to_use?

1 Like

Thank you. Your code is what i needed = )
The result of plugins_by_family was the same as dicover:

# Result: [<class 'pyblish.plugin.ModelExtractor'>,
 <class 'pyblish.plugin.ModelValidator'>,
 <class 'pyblish.plugin.IntegrateModel'>] #