### Navigation

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

# core.displaypub

## Module: `core.displaypub`

Inheritance diagram for `IPython.core.displaypub`:

An interface for publishing rich data to frontends.

There are two components of the display system:

- Display formatters, which take a Python object and compute the representation of the object in various formats (text, HTML, SVg, etc.).
- The display publisher that is used to send the representation data to the various frontends.

This module defines the logic display publishing. The display publisher uses the `display_data` message type that is defined in the IPython messaging spec.

Authors:

- Brian Granger

## `DisplayPublisher`

class `IPython.core.displaypub.``DisplayPublisher`(**kwargs)

  Bases: `IPython.config.configurable.Configurable`

  A traited class that publishes display data to frontends.

  Instances of this class are created by the main IPython object and should be accessed there.

  `__init__`(**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.

    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)
                # Then any other code you need to finish initialization.

    This ensures that instances will be configured properly.

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

  `publish`(source, data, metadata=None)

    Publish data and metadata to all frontends.

    See the `display_data` message in the messaging documentation for more details about this message type.

    The following MIME types are currently implemented:

    - text/plain
    - text/html
    - text/latex
    - application/json
    - image/png
    - immage/svg+xml

    Parameters : | source : str A string that give the function or method that created the data, such as ‘IPython.core.page’. data : dict A dictionary having keys that are valid MIME types (like ‘text/plain’ or ‘image/svg+xml’) and values that are the data for that MIME type. The data itself must be a JSON’able data structure. Minimally all data should have the ‘text/plain’ data, which can be displayed by all frontends. If more than the plain text is given, it is up to the frontend to decide which representation to use. metadata : dict A dictionary for metadata related to the data. This can contain arbitrary key, value pairs that frontends can use to interpret the data.

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

`IPython.core.displaypub.``publish_display_data`(self, source, data, metadata=None)

  Publish data and metadata to all frontends.

  See the `display_data` message in the messaging documentation for more details about this message type.

  The following MIME types are currently implemented:

  - text/plain
  - text/html
  - text/latex
  - application/json
  - image/png
  - immage/svg+xml

  Parameters : | source : str A string that give the function or method that created the data, such as ‘IPython.core.page’. data : dict A dictionary having keys that are valid MIME types (like ‘text/plain’ or ‘image/svg+xml’) and values that are the data for that MIME type. The data itself must be a JSON’able data structure. Minimally all data should have the ‘text/plain’ data, which can be displayed by all frontends. If more than the plain text is given, it is up to the frontend to decide which representation to use. metadata : dict A dictionary for metadata related to the data. This can contain arbitrary key, value pairs that frontends can use to interpret the data.

### Navigation

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