Note
This documentation is for a development version of IPython. There may be significant differences from the latest stable release (1.2.1).
Display formatters.
Inheritance diagram:
Authors:
Bases: IPython.config.configurable.Configurable
Return a format data dict for an object.
By default all format types will be computed.
The following MIME types are currently implemented:
Parameters: | obj : object
include : list or tuple, optional
exclude : list or tuple, optional
|
---|---|
Returns: | (format_dict, metadata_dict) : tuple of two dicts
|
Return the format types (MIME types) of the active formatters.
Bases: exceptions.UserWarning
Warning class for errors in formatters
Bases: abc._NewBase
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.
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.
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.
Add a format function for a given type.
Parameters: | typ : type or ‘__module__.__name__’ string for a type
func : callable
|
---|---|
Returns: | oldfunc : callable
|
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
type_name : str
func : callable
|
---|---|
Returns: | oldfunc : callable
|
Look up the formatter for a given instance.
Parameters: | obj : object instance |
---|---|
Returns: | f : callable
|
Raises: | KeyError if the type has not been registered. |
Look up the registered formatter for a type.
Parameters: | typ : type or ‘__module__.__name__’ string for a type |
---|---|
Returns: | f : callable
|
Raises: | KeyError if the type has not been registered. |
Pop a formatter for the given type.
Parameters: | typ : type or ‘__module__.__name__’ string for a type default : object
|
---|---|
Returns: | obj : object
|
Raises: | KeyError if the type is not registered and default is not specified. |
Bases: IPython.core.formatters.BaseFormatter
The default pretty-printer.
This uses IPython.lib.pretty to compute the format data of the object. If the object cannot be pretty printed, repr() is used. See the documentation of IPython.lib.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, '])')
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.
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.
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.
Bases: IPython.core.formatters.BaseFormatter
A JPEG formatter.
To define the callables that compute the JPEG representation of your objects, define a _repr_jpeg_() 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 JPEG data, not base64 encoded.
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 another LaTeX equation environment.
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.
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.
Bases: IPython.core.formatters.BaseFormatter
A PDF formatter.
To defined the callables that compute to PDF representation of your objects, define a _repr_pdf_() 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 PDF data, not base64 encoded.
decorator for warning on failed format call
Return a format data dict for an object.
By default all format types will be computed.
The following MIME types are currently implemented:
Parameters: | obj : object
|
---|---|
Returns: | format_dict : dict
include : list or tuple, optional
exclude : list or tuple, optional
|