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).

Module: core.extensions

A class for managing IPython extensions.

1 Class

class IPython.core.extensions.ExtensionManager(**kwargs: Any)

Bases: Configurable

A class to manage IPython extensions.

An IPython extension is an importable Python module that has a function with the signature:

def load_ipython_extension(ipython):
    # Do things with ipython

This function is called after your extension is imported and the currently active InteractiveShell instance is passed as the only argument. You can do anything you want with IPython at that point, including defining new magic and aliases, adding new components, etc.

You can also optionally define an unload_ipython_extension(ipython)() function, which will be called if the user unloads or reloads the extension. The extension manager will only call load_ipython_extension() again if the extension is reloaded.

You can put your extension modules anywhere you want, as long as they can be imported by Python’s standard import mechanism.

__init__(shell=None, **kwargs)

Create a configurable given a config config.

Parameters:
  • config (Config) – If this is empty, default values are used. If config is a Config instance, it will be used to configure the instance.

  • parent (Configurable instance, optional) – The parent Configurable instance of this object.

Notes

Subclasses of Configurable must call the __init__() method of Configurable before doing anything else and using super():

class MyConfigurable(Configurable):
    def __init__(self, config=None):
        super(MyConfigurable, self).__init__(config=config)
        # Then any other code you need to finish initialization.

This ensures that instances will be configured properly.

load_extension(module_str: str)

Load an IPython extension by its module name.

Returns the string “already loaded” if the extension is already loaded, “no load function” if the module doesn’t have a load_ipython_extension function, or None if it succeeded.

reload_extension(module_str: str)

Reload an IPython extension by calling reload.

If the module has not been loaded before, InteractiveShell.load_extension() is called. Otherwise reload() is called and then the load_ipython_extension() function of the module, if it exists is called.

unload_extension(module_str: str)

Unload an IPython extension by its module name.

This function looks up the extension’s name in sys.modules and simply calls mod.unload_ipython_extension(self).

Returns the string “no unload function” if the extension doesn’t define a function to unload itself, “not loaded” if the extension isn’t loaded, otherwise None.