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.

A good place to see this call in action is in the tk-multi-publish app's primary_publish hook. Here's what the code looks 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, the hook is calling tank.util.register_publish() to create and return the PublishedFile entity entry in Shotgun.




Please sign in to leave a comment.