Important

This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

IPython

IPython: tools for interactive and parallel computing in Python.

https://ipython.org

4 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.InteractiveShellEmbed instance 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:
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.

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 traitlets Config object (see Running IPython from Python), allowing configuration of the kernel (see IPython kernel options). 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 by embed().

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 traitlets Config object (see Running IPython from Python), allowing configuration of the instance (see Terminal IPython options).

IPython.start_kernel(argv=None, **kwargs)

Launch a normal IPython kernel instance (as opposed to embedded)

IPython.embed_kernel() puts a shell in a particular calling scope, such as a function or method for debugging purposes, which is often not desirable.

start_kernel() does full, regular IPython initialization, including loading startup files, configuration, etc. much of which is skipped by embed_kernel().

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 traitlets Config object (see Running IPython from Python), allowing configuration of the kernel (see IPython kernel options).