{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Display formatters."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This module defines the base instances in order to implement custom formatters/mimetypes got objects:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As we want to see internal IPython working we are going to use the following function to diaply objects instead of the normal print or display method:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip = get_ipython()\n>>> ip.display_formatter.format(...)\n({'text/plain': 'Ellipsis'}, {})",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This return a tuple with the mimebumdle for the current object, and the associated metadata."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We can now define our own formatter and register it:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from IPython.core.formatters import BaseFormatter, FormatterABC",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> class LLMFormatter(BaseFormatter):\n...\n...     format_type = 'x-vendor/llm'\n...     print_method = '_repr_llm_'\n...     _return_type = (dict, str)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> llm_formatter = LLMFormatter(parent=ip.display_formatter)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip.display_formatter.formatters[LLMFormatter.format_type] = llm_formatter",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Now any class that define "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "_repr_llm_",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " will return a x-vendor/llm as part of it's display data:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> class A:\n...\n...     def _repr_llm_(self, *kwargs):\n...         return 'This a A'\n...",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip.display_formatter.format(A())\n({'text/plain': '<IPython.core.formatters.A at ...>', 'x-vendor/llm': 'This a A'}, {})",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As usual, you can register methods for third party types (see "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "third_party_formatting",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> def llm_int(obj):\n...      return 'This is the integer %s, in between %s and %s'%(obj, obj-1, obj+1)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> llm_formatter.for_type(int, llm_int)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip.display_formatter.format(42)\n({'text/plain': '42', 'x-vendor/llm': 'This is the integer 42, in between 41 and 43'}, {})",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Inheritance diagram:"
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/IPython/core/formatters.py",
  "item_line": 0,
  "item_type": "module",
  "aliases": [
    "IPython.core.formatters"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "IPython.core.formatters",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Display formatters."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This module defines the base instances in order to implement custom formatters/mimetypes got objects:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As we want to see internal IPython working we are going to use the following function to diaply objects instead of the normal print or display method:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip = get_ipython()\n>>> ip.display_formatter.format(...)\n({'text/plain': 'Ellipsis'}, {})",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This return a tuple with the mimebumdle for the current object, and the associated metadata."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We can now define our own formatter and register it:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from IPython.core.formatters import BaseFormatter, FormatterABC",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> class LLMFormatter(BaseFormatter):\n...\n...     format_type = 'x-vendor/llm'\n...     print_method = '_repr_llm_'\n...     _return_type = (dict, str)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> llm_formatter = LLMFormatter(parent=ip.display_formatter)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip.display_formatter.formatters[LLMFormatter.format_type] = llm_formatter",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Now any class that define "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "_repr_llm_",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " will return a x-vendor/llm as part of it's display data:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> class A:\n...\n...     def _repr_llm_(self, *kwargs):\n...         return 'This a A'\n...",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip.display_formatter.format(A())\n({'text/plain': '<IPython.core.formatters.A at ...>', 'x-vendor/llm': 'This a A'}, {})",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As usual, you can register methods for third party types (see "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "third_party_formatting",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> def llm_int(obj):\n...      return 'This is the integer %s, in between %s and %s'%(obj, obj-1, obj+1)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> llm_formatter.for_type(int, llm_int)",
              "execution_status": null,
              "out": ""
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> ip.display_formatter.format(42)\n({'text/plain': '42', 'x-vendor/llm': 'This is the integer 42, in between 41 and 43'}, {})",
              "execution_status": null,
              "out": ""
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Inheritance diagram:"
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    }
  ],
  "local_refs": []
}