{
  "__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": "A decorator-based method of constructing IPython magics with "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "argparse",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "argparse",
                "version": "*",
                "kind": "api",
                "path": "argparse"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " option handling."
            }
          ]
        }
      ],
      "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": "New magic functions can be defined like so      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "from IPython.core.magic_arguments import (argument, magic_arguments,\n    parse_argstring)\n\n@magic_arguments()\n@argument('-o', '--option', help='An optional argument.')\n@argument('arg', type=int, help='An integer positional argument.')\ndef magic_cool(self, arg):\n    \"\"\" A really cool magic command.\n\n\"\"\"\n    args = parse_argstring(magic_cool, arg)\n    ...",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@magic_arguments",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " decorator marks the function as having argparse arguments. The "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@argument",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " decorator adds an argument using the same syntax as argparse's "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "add_argument()",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method. More sophisticated uses may also require the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@argument_group",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@kwds",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " decorator to customize the formatting and the parsing."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Help text for the magic is automatically generated from the docstring and the arguments      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "In[1]: %cool?\n    %cool [-o OPTION] arg\n\n    A really cool magic command.\n\n    positional arguments:\n      arg                   An integer positional argument.\n\n    optional arguments:\n      -o OPTION, --option OPTION\n                            An optional argument.",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here is an elaborated example that uses default parameters in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "argument",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "IPython.core.magic_arguments:argument"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and calls the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "args",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in the cell magic      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "from IPython.core.magic import register_cell_magic\nfrom IPython.core.magic_arguments import (argument, magic_arguments,\n                                        parse_argstring)\n\n@magic_arguments()\n@argument(\n    \"--option\",\n    \"-o\",\n    help=(\"Add an option here\"),\n)\n@argument(\n    \"--style\",\n    \"-s\",\n    default=\"foo\",\n    help=(\"Add some style arguments\"),\n)\n@register_cell_magic\ndef my_cell_magic(line, cell):\n    args = parse_argstring(my_cell_magic, line)\n    print(f\"{args.option=}\")\n    print(f\"{args.style=}\")\n    print(f\"{cell=}\")",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In a jupyter notebook, this cell magic can be executed like this      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "%%my_cell_magic -o Hello\nprint(\"bar\")\ni = 42",
          "execution_status": null
        },
        {
          "__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/magic_arguments.py",
  "item_line": 0,
  "item_type": "module",
  "aliases": [
    "IPython.core.magic_arguments"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "IPython.core.magic_arguments",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A decorator-based method of constructing IPython magics with "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "argparse",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "argparse",
                "version": "*",
                "kind": "api",
                "path": "argparse"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " option handling."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "New magic functions can be defined like so      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "from IPython.core.magic_arguments import (argument, magic_arguments,\n    parse_argstring)\n\n@magic_arguments()\n@argument('-o', '--option', help='An optional argument.')\n@argument('arg', type=int, help='An integer positional argument.')\ndef magic_cool(self, arg):\n    \"\"\" A really cool magic command.\n\n\"\"\"\n    args = parse_argstring(magic_cool, arg)\n    ...",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@magic_arguments",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " decorator marks the function as having argparse arguments. The "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@argument",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " decorator adds an argument using the same syntax as argparse's "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "add_argument()",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method. More sophisticated uses may also require the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@argument_group",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "@kwds",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " decorator to customize the formatting and the parsing."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Help text for the magic is automatically generated from the docstring and the arguments      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "In[1]: %cool?\n    %cool [-o OPTION] arg\n\n    A really cool magic command.\n\n    positional arguments:\n      arg                   An integer positional argument.\n\n    optional arguments:\n      -o OPTION, --option OPTION\n                            An optional argument.",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here is an elaborated example that uses default parameters in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "argument",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "IPython.core.magic_arguments:argument"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and calls the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "args",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in the cell magic      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "from IPython.core.magic import register_cell_magic\nfrom IPython.core.magic_arguments import (argument, magic_arguments,\n                                        parse_argstring)\n\n\n@magic_arguments()\n@argument(\n    \"--option\",\n    \"-o\",\n    help=(\"Add an option here\"),\n)\n@argument(\n    \"--style\",\n    \"-s\",\n    default=\"foo\",\n    help=(\"Add some style arguments\"),\n)\n@register_cell_magic\ndef my_cell_magic(line, cell):\n    args = parse_argstring(my_cell_magic, line)\n    print(f\"{args.option=}\")\n    print(f\"{args.style=}\")\n    print(f\"{cell=}\")",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In a jupyter notebook, this cell magic can be executed like this      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "%%my_cell_magic -o Hello\nprint(\"bar\")\ni = 42",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Inheritance diagram:"
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    }
  ],
  "local_refs": []
}