I don't recommend doing this. ipython/ipython#2981 aims to eliminate the cost of registering unused display formats,
so you shouldn't need to be checking whether you are in an IPython kernel here.

IPython doesn't have an official way to check whether you are 'in a kernel' or not, but sniffing this sort of private API that is not likely to be stable is probably not the way to do it. Our goal is to avoid the need to know this at all (especially since ultimately all IPython sessions will be kernels).  Since this will be the default state going forward, if you really must check, I would check for the Terminal case, and default to the Kernel behavior rather than the other way around.  Checking the Terminal case is less likely to change, and misidentifying it has a lower cost (it's never wrong in previously released IPython, and there should be no cost after 1.0 release).