A Tale of Three APIs

In Pyblish, there are three conceptual APIs of interest while developing plug-ins.

  • Library -> Plug-in
  • Plug-in -> Library
  • Plug-in -> Plug-in

Library to Plug-in


The Pyblish library itself carries an interface that is exposed to plug-ins.

This is the interface you gain access to from within your plug-in during development and includes helper functions exposed globally, such as format_filename.

# Library API
>>> import pyblish.api
>>> pyblish.api.format_filename(r"str%*ange_fil£&en*ame.mb")
>>> pyblish.api.discover()
[..all discovered plug-ins..]

Plug-in to Library


Each plug-in also exposes attributes to the library. Primarily, attributes used to identifying the plug-in such its family support and processing methods.

import pyblish.api as pyblish

class ValidateInstance(pyblish.InstancePlugin):
    order = pyblish.ValidatorOrder # Run during validation

    families = ["myFamily"]  # Signals to the library that instances
                             # of family "myFamily" should be processed.
    hosts = ["maya"]  # This plug-in should run within Autodesk Maya

     def process(self, instance):
         # The library will call upon this method at the opportune time.
         instance.set_data("send_to_extraction", ["Some Data"])

This pattern is known as Inversion-of-Control.

Plug-in to Plug-in


Plug-ins may coordinate with each other by passing data.

import pyblish.api as pyblish

class ValidateInstance(pyblish.InstancePlugin):
   order = pyblish.ValidatorOrder

   def process(self, instance):
       instance.set_data("message", "Hello")

class ExtractInstance(pyblish.InstancePlugin):
    order = pyblish.ExtractorOrder

    def process(self, instance):
        if "message" in instance.data:
            # ...

It does this via the data member. Each stage, selection, validation, extraction and conform, may pass data from one to the next.

Other data includes switches within the instance itself. For example, a review family may include options for output resolution in pixels, or format such as whether to write a Quicktime file or a plain png sequence.

instance.data["output"] = "png"

results matching ""

    No results matching ""