IPython
IPython: tools for interactive and parallel computing in Python.
3 Functions
- IPython.embed(*, header='', compile_flags=None, **kwargs)
Call this to embed IPython at the current point in your program.
The first invocation of this will create a
terminal.embed.InteractiveShellEmbedinstance and then call it. Consecutive calls just call the already created instance.If you don’t want the kernel to initialize the namespace from the scope of the surrounding function, and/or you want to load full IPython configuration, you probably want
IPython.start_ipython()instead.Here is a simple example:
from IPython import embed a = 10 b = 20 embed(header='First time') c = 30 d = 40 embed()
- Parameters:
header (str) – Optional header string to print at startup.
compile_flags – Passed to the
compile_flagsparameter ofterminal.embed.InteractiveShellEmbed.mainloop(), which is called when theterminal.embed.InteractiveShellEmbedinstance is called.**kwargs (various, optional) – Any other kwargs will be passed to the
terminal.embed.InteractiveShellEmbedconstructor. Full customization can be done by passing a traitletsConfigin as theconfigargument (see Running IPython from Python and Terminal options).
- IPython.embed_kernel(module=None, local_ns=None, **kwargs)
Embed and start an IPython kernel in a given scope.
If you don’t want the kernel to initialize the namespace from the scope of the surrounding function, and/or you want to load full IPython configuration, you probably want
IPython.start_kernel()instead.This is a deprecated alias for
ipykernel.embed.embed_kernel(), to be removed in the future. You should import directly fromipykernel.embed; this wrapper fails anyway if you don’t haveipykernelpackage installed.- Parameters:
module (types.ModuleType, optional) – The module to load into IPython globals (default: caller)
local_ns (dict, optional) – The namespace to load into IPython user namespace (default: caller)
**kwargs (various, optional) – Further keyword args are relayed to the IPKernelApp constructor, such as
config, a traitletsConfigobject (see Running IPython from Python), allowing configuration of the kernel. Will only have an effect on the first embed_kernel call for a given process.
- IPython.start_ipython(argv=None, **kwargs)
Launch a normal IPython instance (as opposed to embedded)
IPython.embed()puts a shell in a particular calling scope, such as a function or method for debugging purposes, which is often not desirable.start_ipython()does full, regular IPython initialization, including loading startup files, configuration, etc. much of which is skipped byembed().This is a public API method, and will survive implementation changes.
- Parameters:
argv (list or None, optional) – If unspecified or None, IPython will parse command-line options from sys.argv. To prevent any command-line parsing, pass an empty list:
argv=[].user_ns (dict, optional) – specify this dictionary to initialize the IPython user namespace with particular values.
**kwargs (various, optional) – Any other kwargs will be passed to the Application constructor, such as
config, a traitletsConfigobject (see Running IPython from Python), allowing configuration of the instance (see Terminal options).