### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »

# core.extensions

## Module: `core.extensions`

Inheritance diagram for `IPython.core.extensions`:

A class for managing IPython extensions.

Authors:

- Brian Granger

## `ExtensionManager`

class `IPython.core.extensions.``ExtensionManager`(shell=None, config=None)

  Bases: `IPython.config.configurable.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.

  The `load_ipython_extension()` will be called again is you load or reload the extension again. It is up to the extension author to add code to manage that.

  You can put your extension modules anywhere you want, as long as they can be imported by Python’s standard import mechanism. However, to make it easy to write extensions, you can also put your extensions in `os.path.join(self.ipython_dir, 'extensions')`. This directory is added to `sys.path` automatically.

  `__init__`(shell=None, config=None)
  classmethod `class_config_section`()

    Get the config class config section

  classmethod `class_get_help`()

    Get the help string for this class in ReST format.

  classmethod `class_get_trait_help`(trait)

    Get the help string for a single trait.

  classmethod `class_print_help`()

    Get the help string for a single trait and print it.

  classmethod `class_trait_names`(**metadata)

    Get a list of all the names of this classes traits.

    This method is just like the `trait_names()` method, but is unbound.

  classmethod `class_traits`(**metadata)

    Get a list of all the traits of this class.

    This method is just like the `traits()` method, but is unbound.

    The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

    This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

  `config`

    A trait whose value must be an instance of a specified class.

    The value can also be an instance of a subclass of the specified class.

  `created` = None
  `ipython_extension_dir`
  `load_extension`(module_str)

    Load an IPython extension by its module name.

    If `load_ipython_extension()` returns anything, this function will return that object.

  `on_trait_change`(handler, name=None, remove=False)

    Setup a handler to be called when a trait changes.

    This is used to setup dynamic notifications of trait changes.

    Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).

    Parameters :

    handler : callable

    > A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new) or handler(name, old, new).

    name : list, str, None

    > If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.

    remove : bool

    > If False (the default), then install the handler. If True then unintall it.

  `reload_extension`(module_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.

  `shell`

    A trait whose value must be an instance of a specified class.

    The value can also be an instance of a subclass of the specified class.

  `trait_metadata`(traitname, key)

    Get metadata values for trait by key.

  `trait_names`(**metadata)

    Get a list of all the names of this classes traits.

  `traits`(**metadata)

    Get a list of all the traits of this class.

    The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

    This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

  `unload_extension`(module_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)`.

### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »