core.formatters — IPython 0.11 documentation

### Navigation

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

# core.formatters

## Module: `core.formatters`

Inheritance diagram for `IPython.core.formatters`:

Display formatters.

Authors:

- Robert Kern
- Brian Granger

## Classes

### `BaseFormatter`

class `IPython.core.formatters.` `BaseFormatter`(**kwargs)

  Bases: `IPython.config.configurable.Configurable`

  A base formatter class that is configurable.

  This formatter should usually be used as the base class of all formatters. It is a traited `Configurable` class and includes an extensible API for users to determine how their objects are formatted. The following logic is used to find a function to format an given object.

  1. The object is introspected to see if it has a method with the name `print_method`. If is does, that object is passed to that method for formatting.
  2. If no print method is found, three internal dictionaries are consulted to find print method: `singleton_printers`, `type_printers` and `deferred_printers`.

  Users should use these dictionaries to register functions that will be used to compute the format data for their objects (if those objects don’t have the special print methods). The easiest way of using these dictionaries is through the `for_type()` and `for_type_by_name()` methods.

  If no function/callable is found to compute the format data, `None` is returned and this format type is not used.

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

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

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

### `DisplayFormatter`

class `IPython.core.formatters.` `DisplayFormatter`(**kwargs)

  Bases: `IPython.config.configurable.Configurable`

  `__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
  `format`(obj, include=None, exclude=None)

    Return a format data dict for an object.

    By default all format types will be computed.

    The following MIME types are currently implemented:

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

    Parameters : | obj : object The Python object whose format data will be computed. include : list or tuple, optional A list of format type strings (MIME types) to include in the format data dict. If this is set only the format types included in this list will be computed. exclude : list or tuple, optional A list of format type string (MIME types) to exclue in the format data dict. If this is set all format types will be computed, except for those included in this argument.
    Returns : | format_dict : dict A dictionary of key/value pairs, one or each format that was generated for the object. The keys are the format types, which will usually be MIME type strings and the values and JSON’able data structure containing the raw data for the representation in that format.

  `format_types`

    Return the format types (MIME types) of the active formatters.

  `formatters`

    An instance of a Python dict.

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

  `plain_text_only`

    A boolean (True, False) trait.

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

### `FormatterABC`

class `IPython.core.formatters.` `FormatterABC`

  Bases: `object`

  Abstract base class for Formatters.

  A formatter is a callable class that is responsible for computing the raw format data for a particular format type (MIME type). For example, an HTML formatter would have a format type of text/html and would return the HTML representation of the object when called.

  `__init__`()

    x.__init__(...) initializes x; see x.__class__.__doc__ for signature

  `enabled` = True
  `format_type` = 'text/plain'

### `HTMLFormatter`

class `IPython.core.formatters.` `HTMLFormatter`(**kwargs)

  Bases: `IPython.core.formatters.BaseFormatter`

  An HTML formatter.

  To define the callables that compute the HTML representation of your objects, define a `_repr_html_()` method or use the `for_type()` or `for_type_by_name()` methods to register functions that handle this.

  The return value of this formatter should be a valid HTML snippet that could be injected into an existing DOM. It should not include the ``<html>` or ``<body>` tags.

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

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

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

### `JSONFormatter`

class `IPython.core.formatters.` `JSONFormatter`(**kwargs)

  Bases: `IPython.core.formatters.BaseFormatter`

  A JSON string formatter.

  To define the callables that compute the JSON string representation of your objects, define a `_repr_json_()` method or use the `for_type()` or `for_type_by_name()` methods to register functions that handle this.

  The return value of this formatter should be a valid JSON string.

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

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

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

### `JavascriptFormatter`

class `IPython.core.formatters.` `JavascriptFormatter`(**kwargs)

  Bases: `IPython.core.formatters.BaseFormatter`

  A Javascript formatter.

  To define the callables that compute the Javascript representation of your objects, define a `_repr_javascript_()` method or use the `for_type()` or `for_type_by_name()` methods to register functions that handle this.

  The return value of this formatter should be valid Javascript code and should not be enclosed in ``<script>`` tags.

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

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

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

### `LatexFormatter`

class `IPython.core.formatters.` `LatexFormatter`(**kwargs)

  Bases: `IPython.core.formatters.BaseFormatter`

  A LaTeX formatter.

  To define the callables that compute the LaTeX representation of your objects, define a `_repr_latex_()` method or use the `for_type()` or `for_type_by_name()` methods to register functions that handle this.

  The return value of this formatter should be a valid LaTeX equation, enclosed in either ``$`` or ``$$``.

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

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

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

### `PNGFormatter`

class `IPython.core.formatters.` `PNGFormatter`(**kwargs)

  Bases: `IPython.core.formatters.BaseFormatter`

  A PNG formatter.

  To define the callables that compute the PNG representation of your objects, define a `_repr_png_()` method or use the `for_type()` or `for_type_by_name()` methods to register functions that handle this.

  The return value of this formatter should be raw PNG data, not base64 encoded.

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

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

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

### `PlainTextFormatter`

class `IPython.core.formatters.` `PlainTextFormatter`(**kwargs)

  Bases: `IPython.core.formatters.BaseFormatter`

  The default pretty-printer.

  This uses `IPython.external.pretty` to compute the format data of the object. If the object cannot be pretty printed, `repr()` is used. See the documentation of `IPython.external.pretty` for details on how to write pretty printers. Here is a simple example:

      def dtype_pprinter(obj, p, cycle):
          if cycle:
              return p.text('dtype(...)')
          if hasattr(obj, 'fields'):
              if obj.fields is None:
                  p.text(repr(obj))
              else:
                  p.begin_group(7, 'dtype([')
                  for i, field in enumerate(obj.descr):
                      if i > 0:
                          p.text(',')
                          p.breakable()
                      p.pretty(field)
                  p.end_group(7, '])')

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `float_format`

    A trait for unicode strings.

  `float_precision`

    A casting version of the unicode trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

  `max_width`

    A integer trait.

  `newline`

    A trait for unicode strings.

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

  `pprint`

    A boolean (True, False) trait.

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

  `verbose`

    A boolean (True, False) trait.

### `SVGFormatter`

class `IPython.core.formatters.` `SVGFormatter`(**kwargs)

  Bases: `IPython.core.formatters.BaseFormatter`

  An SVG formatter.

  To define the callables that compute the SVG representation of your objects, define a `_repr_svg_()` method or use the `for_type()` or `for_type_by_name()` methods to register functions that handle this.

  The return value of this formatter should be valid SVG enclosed in ``<svg>`` tags, that could be injected into an existing DOM. It should not include the ``<html>` or ``<body>` tags.

  `__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
  `deferred_printers`

    An instance of a Python dict.

  `enabled`

    A boolean (True, False) trait.

  `for_type`(typ, func)

    Add a format function for a given type.

    Parameters : | typ : class The class of the object that will be formatted using func. func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `for_type_by_name`(type_module, type_name, func)

    Add a format function for a type specified by the full dotted module and name of the type, rather than the type of the object.

    Parameters : | type_module : str The full dotted name of the module the type is defined in, like `numpy`. type_name : str The name of the type (the class name), like `dtype` func : callable The callable that will be called to compute the format data. The call signature of this function is simple, it must take the object to be formatted and return the raw data for the given format. Subclasses may use a different call signature for the func argument.

  `format_type`

    A trait for unicode strings.

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

  `print_method`

    A string holding a valid object name in this version of Python.

    This does not check that the name exists in any scope.

  `singleton_printers`

    An instance of a Python dict.

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

  `type_printers`

    An instance of a Python dict.

## Function

`IPython.core.formatters.` `format_display_data`(obj, include=None, exclude=None)

  Return a format data dict for an object.

  By default all format types will be computed.

  The following MIME types are currently implemented:

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

  Parameters : | obj : object The Python object whose format data will be computed.
  Returns : | format_dict : dict A dictionary of key/value pairs, one or each format that was generated for the object. The keys are the format types, which will usually be MIME type strings and the values and JSON’able data structure containing the raw data for the representation in that format. include : list or tuple, optional A list of format type strings (MIME types) to include in the format data dict. If this is set only the format types included in this list will be computed. exclude : list or tuple, optional A list of format type string (MIME types) to exclue in the format data dict. If this is set all format types will be computed, except for those included in this argument.

### Navigation

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