The context encapsulates one or more Instance's along with information about the current execution environment, such as the current user and time of day. Publishing is performed by iterating over the members of a context.
# Psuedo-codefor plugin in plugins:for instance in context: plugin.process(instance)
Examples
# Creating a context## The context is normally created for you by a user interface or# through convenience functions, but can be helpful to manually# create for debugging purposes.import pyblish.api as pyblishcontext = pyblish.Context()
# Creating instances from a context## Instances can be created directly or through a context. When# created through a context, the context is automatically set# as the parent of the newly created instance.import pyblish.api as pyblishcontext = pyblish.Context()instanceA = context.create_instance(name="MyInstanceA")instanceB = pyblish.Instance(name="MyInstanceB", parent=context)print("The context contains these instances:")for instance in context:print(instance)# MyInstanceA# MyInstanceB
# Setting data on a context# # Both Instance and Context inherit from AbstractEntity which# provides the mechanism for modifying data.import pyblish.api as pyblishcontext = pyblish.Context()data = context.datacontext.data["hostname"]="localhost"assert"hostname"in context.data isTruecontext.data.pop("hostname")assert"hostname"in context.data isFalse