Python API documentation?

Is there an API documentation for the Python interface of Slicer? I haven’t found it.

What I’ve found is the C++ documentation, and I use this when I try to do Python. I guess the Python interface is generated from C++ in some way. I don’t need well-commented documentation, but I’m looking for all types and functions in Slicer’s Python interface, instead of using Tab in the Python Interactor. The documentation for Qt’s Python API is a nice example of how Python documentation can be done.

Good point - we discussed this at the developer hangout and there isn’t a great universal solution given how many libraries slicer builds on an integrates. Here’s a very old page that lists and links back to the various pieces.

We also noticed that while Qt’s Python documentation is good, it’s not perfect either. For example this python documentation just lists the method type, while the corresponding C++ documentation includes useful text.

It would be great if someone wants to build a better doc infrastructure, but for now I suggest looking at the source code. And of course you can use help in the python interactor.

Hope that helps

1 Like

At this point I would be very satisfied by just listing the method and types like in the Qt’s Python API documentation. It’s so much easier to program when you can browse the API. I didn’t know about help() - thank you, I’m still learning Python.

A short question

I want to set “Modify other segments” to “Allow overlap” in my .slicerrc file:

ne = getNode( 'SegmentEditor' ) # singleton, type: vtkSlicerSegmentationsModuleMRMLPython.vtkMRMLSegmentEditorNode, according to Python Interactor
ne.SetOverwriteMode( 2 ) # magic number, see

How do I replace the magic number with a Python equivalent to C++'s vtkMRMLSegmentEditorNode::OverwriteNone? It looks like I can use ne.OverwriteNone, but that is not a static value. And vtkMRMLSegmentEditorNode.OverwriteNone is not defined, Python Interactor says.

slicer.vtkMRMLSegmentEditorNode.OverwriteNone will work

1 Like