{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "user_guide:plugins",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The plugin infrastructure of "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "skimage.io"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " is deprecated since version 0.25 and will be removed in version 0.27. Please use "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "imageio"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " or other I/O packages directly."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A plugin consists of two files, the source and the descriptor "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".ini"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  Let's say we'd like to provide a plugin for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "imshow"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "matplotlib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  We'll call our plugin "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "mpl"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "skimage/io/_plugins/mpl.py\nskimage/io/_plugins/mpl.ini",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The name of the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".py"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".ini"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " files must correspond.  Inside the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": ".ini"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " file, we give the plugin meta-data    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "[mpl] <-- name of the plugin, may be anything\ndescription = Matplotlib image I/O plugin\nprovides = imshow <-- a comma-separated list, one or more of\n                      imshow, imsave, imread, _app_show",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The \"provides\"-line lists all the functions provided by the plugin.  Since our plugin provides "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "imshow"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", we have to define it inside "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "mpl.py"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "# This is mpl.py\n\nimport matplotlib.pyplot as plt\n\ndef imshow(img):\n    plt.imshow(img)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that, by default, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "imshow"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is non-blocking, so a special function "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_app_show"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " must be provided to block the GUI.  We can modify our plugin to provide it as follows    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "[mpl]\nprovides = imshow, _app_show",
          "execution_status": null
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "# This is mpl.py\n\nimport matplotlib.pyplot as plt\n\ndef imshow(img):\n    plt.imshow(img)\n\ndef _app_show():\n    plt.show()",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Any plugin in the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_plugins"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " directory is automatically examined by "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "skimage.io"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " upon import.  You may list all the plugins on your system    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> import skimage as ski\n>>> ski.io.find_available_plugins()\n{'gtk': ['imshow'],\n 'matplotlib': ['imshow', 'imread', 'imread_collection'],\n 'pil': ['imread', 'imsave', 'imread_collection'],\n 'test': ['imsave', 'imshow', 'imread', 'imread_collection'],}",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "or only those already loaded    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> ski.io.find_available_plugins(loaded=True)\n{'matplotlib': ['imshow', 'imread', 'imread_collection'],\n 'pil': ['imread', 'imsave', 'imread_collection']}",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A plugin is loaded using the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "use_plugin"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " command    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> ski.io.use_plugin('pil') # Use all capabilities provided by PIL",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "or"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> ski.io.use_plugin('pil', 'imread') # Use only the imread capability of PIL",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that, if more than one plugin provides certain functionality, the last plugin loaded is used."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To query a plugin's capabilities, use "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "plugin_info"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> ski.io.plugin_info('pil')\n>>>\n{'description': 'Image reading via the Python Imaging Library',\n 'provides': 'imread, imsave'}",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "I/O Plugin Infrastructure"
        }
      ],
      "level": 0,
      "target": null
    }
  ],
  "local_refs": []
}