bundles / IPython 9.15.0 / IPython / core / magic / MagicsManager / register_function
function
IPython.core.magic:MagicsManager.register_function
Signature
def register_function(self, func: Callable[..., Any], magic_kind: _MagicSpec = line, magic_name: str | None = None) → NoneSummary
Expose a standalone function as magic function for IPython.
Extended Summary
This will create an IPython magic (line, cell or both) from a standalone function. The functions should have the following signatures:
For line magics:
def f(line)For cell magics:
def f(line, cell)For a function that does both:
def f(line, cell=None)
In the latter case, the function will be called with cell==None when invoked as %f, and with cell as a string when invoked as %%f.
Parameters
func: callableFunction to be registered as a magic.
magic_kind: strKind of magic, one of 'line', 'cell' or 'line_cell'
magic_name: optional strIf given, the name the magic will have in the IPython namespace. By default, the name of the function itself is used.
Aliases
IPython.InteractiveShell.register_magic_functionIPython.core.magic.MagicsManager.register_function