# Find bpy function in source code

What is the best way to locate a function from the bpy module in Blender's source code? I've downloaded the source code and I'm aware you can also browse through it online.

As an example, I would like to inspect bpy.ops.render.render().

Get the idname like:

bpy.ops.render.render.idname()
# 'RENDER_OT_render'


(or simply take render.render and replace the . by _OT_)

Search that operator in the source code, and find it here:

blender\source\blender\editors\render\render_internal.c


/* contextual render, using current scene, view3d? */
void RENDER_OT_render(wmOperatorType *ot)
{
PropertyRNA *prop;

/* identifiers */
ot->name = "Render";
ot->description = "Render active scene";
ot->idname = "RENDER_OT_render";

/* api callbacks */
ot->invoke = screen_render_invoke;
ot->modal = screen_render_modal;
ot->cancel = screen_render_cancel;
ot->exec = screen_render_exec;


You'll likely wanna look for the exec function code (screen_render_exec) and see what it does.

• How can I find classes that have no idname() like bpy.types.Scene in the code? Sep 5 '17 at 9:05
• I would search the folder structure and by filename for those. Regarding the Scene type, check blenkernel, makesrna and makesdna: developer.blender.org/diffusion/B/browse/master/source/blender/… / developer.blender.org/diffusion/B/browse/master/source/blender/… / developer.blender.org/diffusion/B/browse/master/source/blender/… / developer.blender.org/diffusion/B/browse/master/source/blender/… Sep 5 '17 at 9:42
• Thanks, but I am searching for the python definition of the normal bpy.types.Scene() class Sep 5 '17 at 9:56
• To my knowledge, it is only defined in the C code in rna_scene.c. Are you looking for the glue code that exposes the properties and methods to Python? Sep 5 '17 at 10:32
• I assume this is the most relevant part: intern/bpy.c:285 goo.gl/RUkrYc (shortened URL because SO breaks Phabricator deep links). The Scene type is not exposed explicitly anywhere as far as I can tell, because it is part of the DNA/RNA system and all types are exposed my generic code to make the properties and functions defined in the C code available in the bpy python interface. If you need more information, I suggest to contact the Blender developers via IRC. Sep 5 '17 at 11:03

Python offers a module for live inspection. If the function is a python function located in a .py file, you can use these functions.

For example,

import bpy
import inspect

#get sourcefile of a panel
inspect.getfile(bpy.types.VIEW3D_PT_transform_orientations)
#...blender-2.69-windows64\blender-2.69-windows64\2.69\scripts\startup\bl_ui\space_view3d.py

bpy.data.texts.new('source').write(
inspect.getsource(bpy.types.VIEW3D_PT_transform_orientations)
)


(for the difference between .getfile and .getsourcefile see this post on stackoverflow)

• Why does inspect.getfile(bpy.ops.render.render) not work? I get a TypeError error saying it is not a module, class, method, function, traceback, frame, or code object. Feb 9 '14 at 22:42
• pink vertex's example shows inspect.getfile() using a bpy.types class. So the proper call for an operator is inspect.getfile(getattr(bpy.types, bpy.ops.render.render.idname())), which will raise a TypeError: <RNA_Types object at 0x0000000003A875A0> is a built-in class. You need search it in the C code (see my answer where to find it). Feb 9 '14 at 22:55