Blocking Magic Commands#
There are two ways to configure how both line and cell magic commands (e.g. %%time) are blocked or allowed.
allowed_magics- Takes a list of magic names. If this option is set, only magics in this list can be usedblocked_magics- Takes a list of magic names. If this option is set, all magics specified are blocked. Ifallowed_magicsis set,blocked_magicswill be ignored.
Example of using allowed_magics:
ipython_config.py#
# In ipython_config.py
c = get_config()
c.ExamKernel.allowed_magics = ["time"]
Example of trying to use a magic that is not in the allowed magics#
%timeit my_fun()
---------------------------------------------------------------------------
ValueError: No magic named timeit or timeit blocked by kernel.
Allowed magics are: [time]
Example of using blocked_magics:
ipython_config.py#
# In ipython_config.py
c = get_config()
c.ExamKernel.blocked_magics = ["time"]
Example of trying to use a magic that is in the blocked magics#
%%time
---------------------------------------------------------------------------
ValueError: No magic named time or time blocked by kernel.
The following magics are blocked: [time]