How do I publish with the Toolkit API?

Publishing files with the Toolkit API is simple and easy to do. There is a single method you can call to register a file or sequence of files as a PublishedFile in Shotgun. The method is called register_publish() and its documentation can be found here.

Here's what the code might look like:

args = {
  "tk": self.parent.tank,
  "context": self.parent.context,
  "comment": comment,
  "path": path,
  "name": name,
  "version_number": publish_version,
  "thumbnail_path": thumbnail_path,
  "task": sg_task,
  "dependency_paths": dependency_paths,

self.parent.log_debug("Register publish in shotgun: %s" % str(args))

# register publish;
sg_data = tank.util.register_publish(**args)

As you can see, we are calling tank.util.register_publish() to create and return the PublishedFile entity entry in Shotgun.

A good place to see this call in action is in the tk-multi-publish2 app's publish_file hook.

To learn more about advanced publishing functionality, see the Publisher API Reference Documentation.





Please sign in to leave a comment.