API Reference¶
The following section outlines the API of flogin.
Plugins¶
- @event
- deffetch_flow_settings
- defregister_event
- defregister_search_handler
- defregister_search_handlers
- defrun
- @search
- asyncstart
- class flogin.plugin.Plugin(**options)[source]¶
This class represents your plugin.
This class implements a generic for a custom
Settingsclass for typechecking purposes.- Parameters:
settings_no_update (Optional[
bool]) – Whether or not to let flow update flogin’s version of the settings. This can be useful when using a custom settings menu. Defaults toFalseignore_cancellation_requests (Optional[
bool]) – Whether or not to ignore cancellation requests sent from flow. Defaults toFalse
- api¶
An easy way to acess Flow Launcher’s API
- Type:
- event(callback)[source]¶
A decorator that registers an event to listen for. This decorator can be used with a plugin instance or as a classmethod.
All events must be a coroutine.
Changed in version 1.1.0: The decorator can now be used as a classmethod
Note
See the event reference to see what valid events there are.
Example
With a plugin instance:
@plugin.event async def on_initialization(): print('Ready!')
As a classmethod:
class MyPlugin(Plugin): @Plugin.event async def on_initialization(self): print('Ready!')
- fetch_flow_settings()[source]¶
Fetches flow’s settings from flow’s config file
- Returns:
FlowSettings– A dataclass containing all of flow’s settings
- flow_application_dir¶
flow’s application directory from environment variables.
Added in version 1.0.1.
- flow_program_dir¶
flow’s application program from environment variables.
Added in version 1.0.1.
- flow_version¶
the flow version from environment variables.
Added in version 1.0.1.
- property last_query¶
The last query request that flow sent. This is
Noneif no query request has been sent yet.- Type:
Query|None
- property metadata¶
Returns the plugin’s metadata.
- Raises:
PluginNotInitialized – This gets raised if the plugin hasn’t been initialized yet
- register_event(callback, name=None)[source]¶
Registers an event to listen for. See the
event()decorator for another method of registering events.All events must be a coroutine.
Note
See the event reference to see what valid events there are.
- register_search_handler(handler)[source]¶
Register a new search handler
See the search handler section for more information about using search handlers.
- Parameters:
handler (
SearchHandler) – The search handler to be registered
- register_search_handlers(*handlers)[source]¶
Register new search handlers
See the search handler section for more information about using search handlers.
- Parameters:
*handlers (list[
SearchHandler]) – The search handlers to be registered
- run(*, setup_default_log_handler=True)[source]¶
The default runner. This runs the
start()coroutine, and setups up logging.- Parameters:
setup_default_log_handler (
bool) – Whether to setup the default log handler or not, defaults to True.
- search(condition=None, *, text=..., pattern=..., keyword=..., allowed_keywords=..., disallowed_keywords=...)[source]¶
A decorator that registers a search handler.
All search handlers must be a coroutine. See the search handler section for more information about using search handlers.
- Parameters:
condition (Optional[condition]) – The condition to determine which queries this handler should run on. If given, this should be the only argument given.
text (Optional[
str]) – A kwarg to quickly add aPlainTextCondition. If given, this should be the only argument given.pattern (Optional[
re.Pattern|str]) – A kwarg to quickly add aRegexCondition. If given, this should be the only argument given.keyword (Optional[
str]) – A kwarg to quickly set the condition to aKeywordConditioncondition with thekeywordkwarg being the only allowed keyword.allowed_keywords (Optional[Iterable[
str]]) – A kwarg to quickly set the condition to aKeywordConditioncondition with the kwarg being the list of allowed keywords.disallowed_keywords (Optional[Iterable[
str]]) – A kwarg to quickly set the condition to aKeywordConditioncondition with the kwarg being the list of disallowed keywords.
Example
@plugin.on_search() async def example_search_handler(data: Query): return "This is a result!"
Models¶
Settings¶
- class flogin.settings.Settings(data, *, no_update=False)[source]¶
This class represents the settings that you user has chosen.
If a setting is not found,
Noneis returned instead.- x['setting name']
Get a setting by key similiar to a dictionary
- x['setting name', 'default']
Get a setting by key similiar to a dictionary, with a custom default.
- x['setting name'] = "new value"
Change a settings value like a dictionary
- x.setting_name
Get a setting by name like an attribute
- x.setting_name = "new value"
Change a settings value like an attribute
Query¶
- asyncupdate
- asyncupdate_results
- class flogin.query.Query(data, plugin)[source]¶
This class represents the query data sent from flow launcher
This class implements a generic for the
condition_dataattribute, which will be used for typechecking purposes.- x == y
Compare the keywords, text, and is_query values of two query objects.
- hash(x)
Gets the hash of the query’s raw text
- property condition_data¶
If used in a
SearchHandler, this attribute will return any extra data that the condition gave.- Type:
Any | None
- await update(*, text, keyword=..., requery=False)[source]¶
This function is a coroutine.
Applies updates to the query with flow, and to this object.
This method provides quick acess to
flogin.flow.api.FlowLauncherAPI.change_query()- Parameters:
text (
str) – The text that will be used with the query.keyword (
str) – The keyword that will be used with the query. Defaults to the pre-existing value ofQuery.keyword. Set this toNoneor “*” for no keyword to be used.requery (
bool) – Whether or not to re-send a query request in the event that the new query is the same as the current query
- Returns:
None
- await update_results(results)[source]¶
This function is a coroutine.
Tells flow to change the results shown to the user, using the query from this query object.
This method provides quick acess to
flogin.flow.api.FlowLauncherAPI.update_results(). Because of that, this method will only take affect if the user has not changed the query.- Parameters:
results (list[
Result]) – The new results- Returns:
None
JSON RPC¶
Results¶
- clsResult.create_with_partial
- clsResult.from_dict
- asynccallback
- asynccontext_menu
- asyncon_context_menu_error
- asyncon_error
- defto_dict
- class flogin.jsonrpc.results.Result(title=None, sub=None, icon=None, title_highlight_data=None, title_tooltip=None, sub_tooltip=None, copy_text=None, score=None, auto_complete_text=None, preview=None, progress_bar=None, rounded_icon=None, glyph=None)[source]¶
This represents a result that would be returned as a result for a query or context menu.
For simple useage: create instances of this class as-is.
For advanced useage (handling clicks and custom context menus), it is recommended to subclass the result object to create your own subclass.
This class implements a generic for the
pluginattribute, which will be used for typechecking purposes.Subclassing¶
Subclassing lets you override the following methods:
callback()andcontext_menu(). It also lets you create “universal” result properties (eg: same icon). Example:class MyResult(Result): def __init__(self, title: str) -> None: super().__init__(self, title, icon="Images/app.png") async def callback(self): # handle what happens when the result gets clicked async def context_menu(self): # add context menu options to this result's context menu
- icon¶
A path to the icon to be shown with the result. If this and
glyphare passed, the user’sUse Segoe Fluent Iconssetting will determine which is used.- Type:
Optional[
str]
- title_highlight_data¶
The highlight data for the title. See the FAQ section on highlights for more info.
- Type:
Optional[Iterable[
int]]
- title_tooltip¶
The text to be displayed when the user hovers over the result’s title
- Type:
Optional[
str]
- sub_tooltip¶
The text to be displayed when the user hovers over the result’s subtitle
- Type:
Optional[
str]
- copy_text¶
This is the text that will be copied when the user does
CTRL+Con the result. If the text is a file/directory path, flow will copy the actual file/folder instead of just the path text.- Type:
Optional[
str]
- plugin¶
Your plugin instance. This is filled before
callback()orcontext_menu()are triggered.- Type:
Plugin| None
- preview¶
Customize the preview that is shown for the result. By default, the preview shows the result’s title, subtitle, and icon
- Type:
Optional[
ResultPreview]
- progress_bar¶
The progress bar that could be shown in the place of the title
- Type:
Optional[
ProgressBar]
- auto_complete_text¶
The text that will replace the
raw_textin the flow menu when the autocomplete hotkey is used on the result. Defaults to the result’s title.- Type:
Optional[
str]
- glyph¶
The
Glyphobject that will serve as the result’s icon. If this andiconare passed, the user’sUse Segoe Fluent Iconssetting will determine which is used.- Type:
Optional[
Glyph]
- await callback()[source]¶
This function is a coroutine.
Override this function to add a callback behavior to your result. This method will run when the user clicks on your result.
- Returns:
ExecuteResponse– A response to flow determining whether or not to hide flow’s menu
This function is a coroutine.
Override this function to add a context menu behavior to your result. This method will run when the user gets the context menu to your result.
This method can return/yield almost anything, and flogin will convert it into a list of
Resultobjects before sending it to flow.
- classmethod create_with_partial(partial_callback, **kwargs)[source]¶
A quick and easy way to create a result with a callback without subclassing.
Note
This is meant to be used with
FlowLauncherAPImethodsExample
result = Result.create_with_partial( functools.partial( plugin.api.show_notification, "notification title", "notification content" ), title="Result title", sub="Result subtitle" )
- Parameters:
partial_callback (partial coroutine) – The callback wrapped in
functools.partialkwargs (See allowed kwargs here:
Result) – The args that will be passed to theResultconstructor
- classmethod from_dict(data)[source]¶
Creates a Result from a dictionary
Note
This method does NOT fill the
callback()orcontext_menu()attributes.
This function is a coroutine.
Override this function to add an error response behavior to this result’s context menu callback.
- If the error was handled:
You can return/yield almost anything, and flogin will convert it into a list of
Resultobjects before sending it to flow.- If the error was not handled:
Return a
ErrorResponseobject
- Parameters:
error (
Exception) – The error that occured- Returns:
ErrorResponse| list[Result] |Result| str | Any – A list of results, an results, or something that can be converted into a list of results.- Yields:
Result| str | Any – A result object or something that can be converted into a result object.
- class flogin.jsonrpc.results.ResultPreview(image_path, *, description=None, is_media=True)[source]¶
Represents a result’s preview.
Note
Previews are finicky, and may not work 100% of the time
- class flogin.jsonrpc.results.ProgressBar(percentage, color=...)[source]¶
This represents the progress bar than can be shown on a result.
Note
Visually, the progress bar takes the same spot as the title
Responses¶
- class flogin.jsonrpc.responses.ErrorResponse(code, message, data=None)[source]¶
This represents an error sent to or from flow.
- data¶
Any extra data
- Type:
Optional[Any]
- class flogin.jsonrpc.responses.QueryResponse(results, settings_changes=None, debug_message=...)[source]¶
This response represents the response from search handler’s callbacks and context menus. See the search handler section for more information about using search handlers.
Search Handlers¶
- class flogin.search_handler.SearchHandler(condition=None, *, text=..., pattern=..., keyword=..., allowed_keywords=..., disallowed_keywords=...)[source]¶
This represents a search handler.
When creating this on your own, the
register_search_handler()method can be used to register it.See the search handler section for more information about using search handlers.
There is a provided decorator to easily create search handlers:
search()This class implements a generic for the
pluginattribute, which will be used for typechecking purposes.The keywords in the constructor can also be passed into the subclassed init, like so:
class MyHandler(SearchHandler, text="text"): ... # is equal to class MyHandler(SearchHandler): def __init__(self): super().__init__(text="text")
- Parameters:
condition (Optional[condition]) – The condition to determine which queries this handler should run on. If given, this should be the only argument given.
text (Optional[
str]) – A kwarg to quickly add aPlainTextCondition. If given, this should be the only argument given.pattern (Optional[
re.Pattern|str]) – A kwarg to quickly add aRegexCondition. If given, this should be the only argument given.keyword (Optional[
str]) – A kwarg to quickly set the condition to aKeywordConditioncondition with thekeywordkwarg being the only allowed keyword.allowed_keywords (Optional[Iterable[
str]]) – A kwarg to quickly set the condition to aKeywordConditioncondition with the kwarg being the list of allowed keywords.disallowed_keywords (Optional[Iterable[
str]]) – A kwarg to quickly set the condition to aKeywordConditioncondition with the kwarg being the list of disallowed keywords.
- plugin¶
Your plugin instance. This is filled before
callback()is triggered.- Type:
Plugin| None
- await callback(query)[source]¶
This function is a coroutine.
Override this function to add the search handler behavior you want for the set condition.
This method can return/yield almost anything, and flogin will convert it into a list of
Resultobjects before sending it to flow.
- condition(query)[source]¶
A function that determines whether or not to fire off this search handler for a given query
- error(func)[source]¶
A decorator that registers a error handler for this search handler.
For more information see
on_errorExample
@plugin.search() async def my_hander(query): .. @my_handler.error async def my_error_handler(query, error): ...
- await on_error(query, error)[source]¶
This function is a coroutine.
Override this function to add an error response behavior to this handler’s callback.
- If the error was handled:
You can return/yield almost anything, and flogin will convert it into a list of
Resultobjects before sending it to flow.- If the error was not handled:
Return a
ErrorResponseobject
- Parameters:
- Returns:
ErrorResponse| list[Result] |Result| str | Any – A list of results, an results, or something that can be converted into a list of results.- Yields:
Result| str | Any – A result object or something that can be converted into a result object.
Builtin Search Conditions¶
- class flogin.conditions.PlainTextCondition(text)[source]¶
A builtin search condition to check plain text.
This condition will only run if the query’s text is the same as the text given to this condition. See the search handler section for more information about using search handlers and conditions.
- class flogin.conditions.RegexCondition(pattern)[source]¶
A builtin search condition to check a regex pattern.
This condition will only run if the query’s text is a match to the regex pattern given to this condition. See the search handler section for more information about using search handlers and conditions.
Note
This condition will set the query’s
condition_dataattribute to there.Matchobject.- pattern¶
The pattern to check the queries against.
- Type:
- class flogin.conditions.KeywordCondition(*, allowed_keywords=None, disallowed_keywords=None)[source]¶
A builtin search condition to check what keyword was used with the query.
If the
allowed_keywordsattribute is given, the handler will only run if the query’s keyword is in the list of allowed keywords. If thedisallowed_keywordsattribute is given, the handler will only run if the query’s keyword is not in the list of allowed keywords.See the search handler section for more information about using search handlers and conditions.
- class flogin.conditions.AllCondition(*conditions)[source]¶
This builtin search condition acts similiarly to the builtin
allfunction. It only returnsTrueif all of the given conditions also returnTrue.ConditionData¶
This condition will set
flogin.query.Query.condition_datato a dictionary containing the conditions, where the keys are the conditions, and the values are the condition data that they gave.
- class flogin.conditions.AnyCondition(*conditions)[source]¶
This builtin search condition acts similiarly to the builtin
anyfunction. It only returnsTrueif any one of the given conditions returnTrue.ConditionData¶
This condition will set
flogin.query.Query.condition_datato a tuple containing two values. The first value will be the condition that returned true, and the second will be the condition data that the condition gave.(condition, query.condition_data)
Flow¶
API¶
- asyncadd_keyword
- asyncchange_query
- asynccheck_for_updates
- asyncfuzzy_search
- asyncget_all_plugins
- asynchide_main_window
- asyncis_main_window_visible
- asyncopen_directory
- asyncopen_settings_menu
- asyncopen_url
- asyncreload_all_plugin_data
- asyncremove_keyword
- asyncrestart_flow_launcher
- asyncrun_shell_cmd
- asyncsave_all_app_settings
- asyncsave_plugin_settings
- asyncshow_error_message
- asyncshow_main_window
- asyncshow_notification
- asyncupdate_results
- class flogin.flow.api.FlowLauncherAPI(jsonrpc)[source]¶
This class is a wrapper around Flow’s API to make it easy to make requests and receive results.
- await add_keyword(plugin_id, keyword)[source]¶
This function is a coroutine.
Registers a new keyword for a plugin with flow launcher.
- await change_query(new_query, requery=False)[source]¶
This function is a coroutine.
Change the query in flow launcher’s menu.
- await check_for_updates()[source]¶
This function is a coroutine.
This tells flow launcher to check for updates to flow launcher
Note
This tells flow launcher to check for updates to flow launcher, not your plugin
- Returns:
None
- await fuzzy_search(text, text_to_compare_it_to)[source]¶
This function is a coroutine.
Asks flow how similiar two strings are.
- Parameters:
- Returns:
- await get_all_plugins()[source]¶
This function is a coroutine.
Get the metadata of all plugins that the user has installed
- Returns:
list[
PluginMetadata]
- await hide_main_window()[source]¶
This function is a coroutine.
This method tells flow to hide the main window
- Returns:
None
- await is_main_window_visible()[source]¶
This function is a coroutine.
This method asks flow if the main window is visible or not
- Returns:
- await open_directory(directory, file=None)[source]¶
This function is a coroutine.
Opens up a folder in file explorer. If a file is provided, the file will be pre-selected.
This function is a coroutine.
This method tells flow to open up the settings menu.
- Returns:
None
- await open_url(url, in_private=False)[source]¶
This function is a coroutine.
Open up a url in the user’s preferred browser, which was set in their Flow Launcher settings.
- await reload_all_plugin_data()[source]¶
This function is a coroutine.
This method tells flow to trigger a reload of all plugins.
- Returns:
None
- await remove_keyword(plugin_id, keyword)[source]¶
This function is a coroutine.
Unregisters a keyword for a plugin with flow launcher.
- await restart_flow_launcher()[source]¶
This function is a coroutine.
This method tells flow launcher to initiate a restart of flow launcher.
Warning
Expect this method to never finish, so clean up and prepare for the plugin to be shut down before calling this.
- await run_shell_cmd(cmd, filename='cmd.exe')[source]¶
This function is a coroutine.
Tell flow to run a shell command
- await save_all_app_settings()[source]¶
This function is a coroutine.
This method tells flow to save all app settings.
- Returns:
None
- await save_plugin_settings()[source]¶
This function is a coroutine.
This method tells flow to save plugin settings
- Returns:
None
- await show_error_message(title, text)[source]¶
This function is a coroutine.
Triggers an error message in the form of a windows notification
- await show_main_window()[source]¶
This function is a coroutine.
This method tells flow to show the main window
- Returns:
None
- await show_notification(title, content, icon='', use_main_window_as_owner=True)[source]¶
This function is a coroutine.
Creates a notification window in the bottom right hand of the user’s screen
- Parameters:
- Returns:
None
- class flogin.flow.fuzzy_search.FuzzySearchResult(data)[source]¶
A class which represents the result given from flow launcher to a fuzzy search request
Note
This is not intended to be a class that you create yourself, use
fuzzy_search()instead.
- asyncadd_keyword
- asyncremove_keyword
- class flogin.flow.plugin_metadata.PluginMetadata(data, flow_api)[source]¶
This class represents a plugin’s metadata
- language¶
The language that the plugin is written in. Possible values: “csharp”, “executable”, “fsharp”, “python”, “javascript”, “typescript”, “python_v2”, “executable_v2”, “javascript_v2”, “typescript_v2”.
- Type:
- add_keyword(keyword)[source]¶
This function is a coroutine.
Registers a new keyword with flow for the plugin.
This is a shortcut to
add_keyword()- Parameters:
keyword (
str) – The keyword to be added- Returns:
None
- property executable¶
The path to the plugin’s executable file
- Type:
- property icon¶
The path to the plugin’s icon file
- Type:
- remove_keyword(keyword)[source]¶
This function is a coroutine.
Removes a keyword from the plugin.
This is a shortcut to
remove_keyword()- Parameters:
keyword (
str) – The keyword to be removed- Returns:
None
Settings¶
- activate_times
- always_preview
- always_start_en
- animation_speed
- auto_updates
- autocomplete_hotkey
- autocomplete_hotkey_2
- color_scheme
- custom_animation_length
- custom_browser_index
- custom_browser_list
- custom_explorer_index
- custom_explorer_list
- custom_plugin_hotkeys
- custom_screen_number
- custom_shortcuts
- custom_window_left
- custom_window_top
- cycle_history_down_hotkey
- cycle_history_up_hotkey
- date_format
- dont_prompt_update_msg
- enable_update_log
- first_launch
- hide_notify_icon
- hide_on_startup
- hide_when_deactivated
- hotkey
- ignore_hotkeys_on_fullscreen
- item_height_size
- keep_max_results
- language
- last_query_mode
- leave_cmd_open
- max_results_to_show
- open_context_menu_hotkey
- open_result_modifiers
- plugin_settings
- preview_hotkey
- proxy
- query_box_font
- query_box_font_size
- query_box_font_stretch
- query_box_font_style
- query_box_font_weight
- query_search_precision
- result_font
- result_font_stretch
- result_font_style
- result_font_weight
- result_item_font_size
- result_sub_font
- result_sub_font_stretch
- result_sub_font_style
- result_sub_font_weight
- result_sub_item_font_size
- search_window_align
- search_window_screen
- select_next_item_hotkey
- select_next_item_hotkey_2
- select_next_page_hotkey
- select_previous_item_hotkey
- select_previous_item_hotkey_2
- select_previous_page_hotkey
- setting_window_height
- setting_window_hotkey
- setting_window_left
- setting_window_state
- setting_window_top
- setting_window_width
- should_use_pinyin
- show_open_result_gotkey
- sound_volume
- start_flow_launcher_on_system_startup
- theme
- time_format
- use_animation
- use_clock
- use_date
- use_drop_shadow_effect
- use_glyph_icons
- use_sound
- window_height_size
- window_left
- window_size
- window_top
- class flogin.flow.settings.FlowSettings(data)[source]¶
This is a class which represents the settings that flow launcher saves in config files.
- Type:
- custom_explorer_list¶
- Type:
list[
CustomFileManager]
- custom_browser_list¶
- Type:
list[
CustomBrowser]
- query_search_precision¶
- Type:
- custom_plugin_hotkeys¶
- Type:
list[
CustomPluginHotkey]
- custom_shortcuts¶
- Type:
list[
CustomQueryShortcut]
- search_window_screen¶
- Type:
- search_window_align¶
- Type:
- last_query_mode¶
- Type:
- animation_speed¶
- Type:
- plugin_settings¶
- Type:
- class flogin.flow.settings.CustomQueryShortcut(data)[source]¶
This is a replica of the
CustomShortcutModeldataclass in flow.This represents a custom shortcut in flow’s config file.
- class flogin.flow.settings.CustomFileManager(data)[source]¶
This is a replica of the
CustomExplorerViewModeldataclass in flow.This is an entry for a custom file manager, which is under the
Default File Manageroption in flow’s ui settings.
- class flogin.flow.settings.CustomBrowser(data)[source]¶
This is a replica of the
CustomBrowserViewModeldataclass in flow.This represents an entry for a custom browser, which is under the
Default Web Browseroption in flow’s ui settings.- private_arg¶
The argument that is used to tell the browser to open in incognito/private mode
- Type:
- class flogin.flow.settings.CustomPluginHotkey(data)[source]¶
This is a replica of the
CustomPluginHotkeydataclass in flow.
- class flogin.flow.settings.PluginsSettings(data)[source]¶
This represents the user’s plugin settings from the general flow config file.
- python_executable¶
The location of the user’s python executable. If there is none, this attribute will be an empty string.
- Type:
- node_executable¶
The location of the user’s node executable. If there is none, this attribute will be an empty string.
- Type:
- plugins¶
A list of the user’s plugins, in partial form.
- Type:
list[
PartialPlugin]
- class flogin.flow.settings.LastQueryMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
- class flogin.flow.settings.SearchWindowScreens(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
- class flogin.flow.settings.SearchWindowAligns(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Errors¶
Plugin Errors¶
- class flogin.errors.PluginNotInitialized[source]¶
This is raised when you try to access something that needs data from the initialize method, and it hasn’t been called yet.
- class flogin.errors.EnvNotSet(name, alternative=None)[source]¶
This is raised when an environment variable that flow automatically sets is not set and can not be retrieved. This should only get raised when your plugin gets run, but not by flow.
- alternative¶
Optionally, the name of the keyword argument in the
PluginTesterconstructor that will set the variable for you.- Type:
Optional[
str]
JSON-RPC Errors¶
Testing¶
- class flogin.testing.plugin_tester.PluginTester(plugin, *, metadata, flow_api_client=..., flow_version=..., flow_application_dir=..., flow_program_dir=...)[source]¶
This can be used to write tests for your plugins.
See the Testing your plugin guide for more information on writing tests.
This class implements a generic for the
pluginattribute, which will be used for typechecking purposes.- Parameters:
plugin (
Plugin) – Your pluginmetadata (
PluginMetadata| dict[str, Any] | None) – Your plugin’s metadata. IfNoneis passed, flogin will attempt to get the metadata from yourplugin.jsonfile. ThePluginTester.create_plugin_metadata()andPluginTester.create_bogus_plugin_metadata()classmethods have been provided for creatingPluginMetadataobjects.flow_api_client (Optional[Any]) – If not passed, flogin will use a filler class which will raise a runtime error whenever an attribute is accessed. If passed, you should be passing an instance of a class which will replace
FlowLauncherAPI, so make sure to implement the methods you need and handle them accordingly.flow_version (Optional[
str]) –This is an optional positional keyword that if set, will automatically set the enviroment variable
FLOW_VERSIONto the value. This is useful if your code uses theflow_versionproperty.flow_application_dir (Optional[
str|Path]) –This is an optional positional keyword that if set, will automatically set the enviroment variable
FLOW_APPLICATION_DIRECTORYto the value. This is useful if your code uses theflow_application_dirproperty.flow_program_dir (Optional[
str|Path]) –This is an optional positional keyword that if set, will automatically set the enviroment variable
FLOW_PROGRAM_DIRECTORYto the value. This is useful if your code uses theflow_program_dirproperty.
- classmethod create_bogus_plugin_metadata()[source]¶
This classmethod can be used to easily and quickly create a
PluginMetadataobject that can be used for testing.Note
Since the information that this classmethod generates is bogus, it is not recommended to use this when your plugin relies on the plugin metadata. Consider using
PluginTester.create_plugin_metadata()instead.- Returns:
PluginMetadata– ThePluginMetadatainstance with your bogus information.
- classmethod create_plugin_metadata(*, id, name, author, version, description, website=None, disabled=False, directory=None, keywords=None, main_keyword=None, icon_path=None)[source]¶
This classmethod can be used to easily create a valid
PluginMetadataobject that has correct data.- Parameters:
id (
str) – The plugin’s idname (
str) – The plugin’s nameauthor (
str) – The plugin’s authorversion (
str) – The plugin’s versiondescription (
str) – The plugin’s descriptionwebsite (Optional[
str]) – The plugin’s website. If not given, the following fstring will be used instead:f"https://github.com/{author}/{name}"disabled (Optional[
bool]) – Whether or not to mark the plugin as disabled. Defaults toFalsedirectory (Optional[
str]) – The plugin’s directory. Defaults to the current working directory.keywords (Optional[list[
str]]) – The plugin’s keywords. Defaults to["*"]main_keyword (Optional[
str]) – The plugin’s main keyword. Defaults to the first keyword in the keywords parametericon_path (Optional[
str]) – The plugin’s icon. Defaults to an invalid icon path.
- Returns:
PluginMetadata– Your new metadata class.
- set_flow_api_client(flow_api_client=...)[source]¶
This sets the flow api client that the tests should use.
- Parameters:
flow_api_client (Optional[Any]) – If not passed, flogin will use a filler class which will raise a runtime error whenever an attribute is accessed. If passed, you should be passing an instance of a class which will replace
FlowLauncherAPI, so make sure to implement the methods you need and handle them accordingly.
This function is a coroutine.
This coroutine can be used to send a result’s context menu, and get the response.
Note
You should use this to test your context menus instead of invoking them directly because this method implements the post-processing that flogin puts onto your context menu and query methods.
- Parameters:
- Raises:
ValueError – This will be raised when
bypass_registrationis set toFalse, and the given result has not been registered.- Returns:
QueryResponse– The query response object that would normally be sent to flow.
- await test_query(text, *, keyword='*', is_requery=False, settings=...)[source]¶
This function is a coroutine.
This coroutine can be used to send your plugin a query, and get the response.
- Parameters:
query (
Query) – The query object that should be passed to your search handlers.settings (Optional[
Settings| dict[str, Any] | None]) – This will represent the settings that flogin will use when executing your search handlers. If not passed, flogin will not use any settings. IfNoneis passed, flogin will get the settings from the settings file (this is incompatible withPluginTester.create_bogus_plugin_metadata()). If a dict orSettingsobject is passed, those are the settings that will be put insettingsbefore executing your search handlers.
- Returns:
QueryResponse– The query response object that would normally be sent to flow.
Utils¶
- flogin.utils.setup_logging(*, formatter=None, handler=None)[source]¶
Sets up flogin’s default logger.
- Parameters:
formatter (Optional[
logging.Formatter]) – The formatter to use, incase you don’t want to use the default file formatter.
- await flogin.utils.coro_or_gen(coro)[source]¶
This function is a coroutine.
Executes an AsyncIterable or a Coroutine, and returns the result
- Parameters:
coro (
typing.Awaitable|typing.AsyncIterable) – The coroutine or asynciterable to be ran- Raises:
TypeError – Neither a
typing.Coroutineor antyping.AsyncIterablewas passed- Returns:
Any – Whatever was given from the
typing.Coroutineortyping.AsyncIterable.
- flogin.utils.print(*values, sep=...)[source]¶
A function that acts similar to the builtin print function, but uses the logging module instead.
This helper function is provided to easily “print” text without having to setup a logging object, because the builtin print function does not work as expected due to the jsonrpc pipes.
Added in version 1.1.0.
Note
The log/print statements can be viewed in your
flogin.logfile under the nameprinting
- flogin.utils.MISSING¶
A type safe sentinel used in the library to represent something as missing. Used to distinguish from
Nonevalues.
Caching¶
- @flogin.caching.cached_property(obj=None)[source]¶
A decorator that is similar to the builtin functools.cached_property decorator, but is async-safe and implements the ability to use
clear_cache().This decorator can also be called with the optional positional argument acting as a
nameargument. This is useful when usingclear_cache()as it lets you choose which items you want to clear the cache of.Example
class X: @cached_property def test(self): ...
class X: @cached_property("test_prop") def test(self): ...
- @flogin.caching.cached_coro(obj=None)[source]¶
A decorator to cache a coroutine’s contents based on the passed arguments. This decorator can also be called with the optional positional argument acting as a
nameargument. This is useful when usingclear_cache()as it lets you choose which items you want to clear the cache of.Note
The arguments passed to the coroutine must be hashable.
Example
@plugin.search() @cached_coro async def handler(query): ...
@plugin.search() @cached_coro("search-handler") async def handler(query): ...
- @flogin.caching.cached_gen(obj=None)[source]¶
A decorator to cache the contents of an async generator based on the passed arguments. This decorator can also be called with the optional positional argument acting as a
nameargument. This is useful when usingclear_cache()as it lets you choose which items you want to clear the cache of.Note
The arguments passed to the generator must be hashable.
Example
@plugin.search() .cached_gen async def handler(query): ...
@plugin.search() @cached_gen("search-handler") async def handler(query): ...
- @flogin.caching.cached_callable(obj=None)[source]¶
A decorator to cache a callable’s output based on the passed arguments. This decorator can also be called with the optional positional argument acting as a
nameargument. This is useful when usingclear_cache()as it lets you choose which items you want to clear the cache of.Note
The arguments passed to the callable must be hashable.
Example
@cached_callable def foo(bar): ...
@cached_callable("search-handler") def foo(bar): ...
- flogin.caching.clear_cache(key=...)[source]¶
This function is used to clear the cache of items that have been cached with this module.
The caching decorators provide an optional positional argument that acts as a
nameargument, which is used in combination of this function.- Parameters:
key (Optional[
str|None]) – Ifstris passed, every cached item with a name equal tokeywill have their cache cleared. IfNoneis passed, every cached item with a name equal toNonewill have their cache cleared (default value for a cached item’s name isNone). Lastly, if thekeyparameter is not passed at all, all caches will be cleared.