Nuke as a Python Module

Since 8.0 Nuke can be used as a Python module.

This means you can now use Python to do many of the complex things in your VFX pipeline that you couldn’t otherwise do, easily, and is essentially a production level, incredibly powerful replacement for most 2D, 3D and video-editing Python modules.

Built against the version of Python Nuke ships with you can now comp programmatically having full access to the Nuke Python-API but from within a native Python interpreter instead of Nuke. This means you can do things like quickly re-grade 2000 shots, or change the timings of a set of fades based on a selection sheet all in a simple 5 or 6 line script, the Pythonic way. You can connect Nuke more easily to your infrastructure back-ends, integrate it into your pipelines and even put Nuke into other applications.

To use Nuke as Python module you should use the interpreter shipped with Nuke (the module should work with other interpreters but the one Nuke ships with is the only one we officially support).

As with standard Python, you can either use the interpreter interactively or via a script.

So, for example a basic interactive example would be:

<Nuke8.0-install-path>$ python.exe
>>> import nuke
>>> r = nuke.nodes.Read(file='shot-90123-a.exr')
>>> g = nuke.nodes.Grade( inputs=[r] )
>>> g['black'].setValue( 0.05 )
>>> w = nuke.nodes.Write(file='shot-90123-a-graded-up.exr', inputs=[g])
>>> nuke.execute( w, 1, 1 )

Or you could put the code into a script like this:

#gradeShots.py
import nuke
shot = sys.argv[0]
r = nuke.nodes.Read(file=sys.argv[0])
g = nuke.nodes.Grade( inputs=[r] )
g['black'].setValue( 0.05 )
outName = '%s-a-grade-up.mov'%(os.path.split(shot)[0])
w = nuke.nodes.Write(file=outName, inputs=[g])
nuke.execute( w, 1, 1 )

Which you would then run like:

<Nuke8.0-install-path>/python.exe gradeShots.py shot-90123-a.exr

Licensing

If you wish to import Nuke using an interactive license you will need to set the environment variable NUKE_INTERACTIVE to any non-zero integer.

e.g.

<Nuke8.0-install-path>$ python.exe >>> import os >>> os.environ[ “NUKE_INTERACTIVE” ] = “1” >>> import nuke >>> ... >>> ...

There are a million and one things you could do with Nuke’s Python module and we would love to hear what you have done with it.

Written by: Frank Harrison.

Table Of Contents

Previous topic

Getting Started

Next topic

Animation