__init__.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """.. sidebar:: Further reading ..
  3. - :ref:`plugins admin`
  4. - :ref:`SearXNG settings <settings plugins>`
  5. - :ref:`builtin plugins`
  6. Plugins can extend or replace functionality of various components of SearXNG.
  7. Here is an example of a very simple plugin that adds a "Hello" into the answer
  8. area:
  9. .. code:: python
  10. from flask_babel import gettext as _
  11. from searx.plugins import Plugin
  12. from searx.result_types import Answer
  13. class MyPlugin(Plugin):
  14. id = "self_info"
  15. default_on = True
  16. def __init__(self):
  17. super().__init__()
  18. info = PluginInfo(id=self.id, name=_("Hello"), description=_("demo plugin"))
  19. def post_search(self, request, search):
  20. return [ Answer(answer="Hello") ]
  21. Entry points (hooks) define when a plugin runs. Right now only three hooks are
  22. implemented. So feel free to implement a hook if it fits the behaviour of your
  23. plugin / a plugin doesn't need to implement all the hooks.
  24. - pre search: :py:obj:`Plugin.pre_search`
  25. - post search: :py:obj:`Plugin.post_search`
  26. - on each result item: :py:obj:`Plugin.on_result`
  27. For a coding example have a look at :ref:`self_info plugin`.
  28. ----
  29. .. autoclass:: Plugin
  30. :members:
  31. .. autoclass:: PluginInfo
  32. :members:
  33. .. autoclass:: PluginStorage
  34. :members:
  35. .. autoclass:: searx.plugins._core.ModulePlugin
  36. :members:
  37. :show-inheritance:
  38. """
  39. from __future__ import annotations
  40. __all__ = ["PluginInfo", "Plugin", "PluginStorage"]
  41. from ._core import PluginInfo, Plugin, PluginStorage
  42. STORAGE: PluginStorage = PluginStorage()
  43. def initialize(app):
  44. STORAGE.load_builtins()
  45. STORAGE.init(app)