Skip to content

Triggering Plugin methods

Flow Launcher can call custom methods created by your plugin as well. To do so simply register the method with your plugin.

You can register any function by using the on_method decorator or by using the add_method method from Plugin.

Returning results

Methods decorated with @plugin.on_method support several return styles — the framework normalizes all of them automatically:

# yield a single result
@plugin.on_method
def query(query: str):
    yield Result(title="Hello!")

# yield multiple results
@plugin.on_method
def query(query: str):
    for item in data:
        yield Result(title=item)

# return a list of results
@plugin.on_method
def query(query: str):
    return [Result(title="a"), Result(title="b")]

# return a single result
@plugin.on_method
def query(query: str):
    return Result(title="Hello!")

Example 1

from pyflowlauncher import Plugin, Result

plugin = Plugin()


@plugin.on_method
def query(query: str):
    yield Result(
        title="This is a title!",
        subtitle="This is the subtitle!",
        json_rpc_action={"Method": "action", "Parameters": []}
    )


@plugin.on_method
def action(params: list[str]):
    pass
    # Do stuff here
    # ...


plugin.run()

Alternatively you can register and add the Method to a Result in one line by using the action method.

Example 2

from pyflowlauncher import Plugin, Result

plugin = Plugin()


@plugin.on_method
def query(query: str):
    r = Result(
        title="This is a title!",
        subtitle="This is the subtitle!",
    )
    r.add_action(action, ["stuff"])
    yield r


def action(params: list[str]):
    pass
    # Do stuff here
    # ...


plugin.run()