API Reference¶
The following section outlines the API of flogin.
Types¶
- type flogin.Jsonable¶
This is a type used to represent anything json serializable.
It is literally defined as:
str | int | float | None | bool | list["Jsonable"] | dict[str, "Jsonable"]
Plugins¶
- defcheck_for_log_override_files
- @event
- deffetch_flow_settings
- defregister_event
- defregister_search_handler
- defregister_search_handlers
- defrun
- @search
- asyncstart
- class flogin.plugin.Plugin[SettingsT](**options)[source]¶
This class represents your plugin.
- 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 toFalsedisable_log_override_files (Optional[
bool]) – Whether or not to disable the log override files. Defaults toFalse. See Log Override Files for more information on this.
- @event[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:
from flogin.utils import print @plugin.event async def on_initialization(): print('Ready!')
As a classmethod:
from flogin.utils import print class MyPlugin(Plugin): @Plugin.event async def on_initialization(self): print('Ready!')
- @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.
Changed in version 2.0.0: The search decorator can now be used as a classmethod
Note
This decorator can also be used as a classmethod
- 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
With an instance:
@plugin.search() async def example_search_handler(data: Query): return "This is a result!"
As a classmethod:
class MyPlugin(Plugin): @Plugin.search() async def example_search_handler(self, data: Query): return "This is a result!"
- api¶
An easy way to acess Flow Launcher’s API
- Type:
- 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
Models¶
Settings¶
- class flogin.settings.Settings[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[ConditionDataT][source]¶
This class represents the query data sent from flow launcher
- 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 (Optional[
str|None]) –The text that will be used with the query.
Changed in version 2.0.0:
textcan now beNone, and is now optionalkeyword (Optional[
str|None]) – 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 (Optional[
bool]) – Whether or not to re-send a query request in the event that the new query is the same as the current query. Defaults toFalse
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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[PluginT](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.
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.
Changed in version 2.0.0: A result callback can not return
boolorNone- Returns:
ExecuteResponse|bool|None– A response to flow determining whether or not to hide flow’s menu, or a bool that will be turned into a response.Nonewill be converted intoTrueto align with the default value forhide
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
- class flogin.jsonrpc.results.Glyph(text, font_family)[source]¶
This represents a glyph object with flow launcher, which is an alternative to
Resulticons.
- typeddict flogin.jsonrpc.results.ResultConstructorKwargs[source]¶
This represents the possible kwargs that can be passed to
Result.This can be useful when overriding
Resultto create a basic implementation of something for your project, but still want the ability to pass kwargs with proper typing.Note
See
Resultfor more information about each key and value.Example
This is an example of how you might use this to create a url result
from typing import Unpack from flogin import Result, ResultConstructorKwargs class MyRes(Result): def __init__(self, url: str, **kwargs: Unpack[ResultConstructorKwargs]) -> None: self.url = url super().__init__(**kwargs) async def callback(self): await self.plugin.api.open_url(self.url)
Responses¶
- class flogin.jsonrpc.responses.ErrorResponse[source]¶
This represents an error sent to or from flow.
- data¶
Any extra data
- Type:
Optional[Any]
- class flogin.jsonrpc.responses.QueryResponse[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[PluginT](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()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
- @error[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 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
- 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.
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.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.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[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.
- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- await change_query(new_query, requery=False)[source]¶
This function is a coroutine.
Change the query in flow launcher’s menu.
- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- 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
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
- await get_all_plugins()[source]¶
This function is a coroutine.
Get the metadata of all plugins that the user has installed
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
list[
PluginMetadata]
- await hide_main_window()[source]¶
This function is a coroutine.
This method tells flow to hide the main window
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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.
- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
This function is a coroutine.
This method tells flow to open up the settings menu.
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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.
- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- await reload_all_plugin_data()[source]¶
This function is a coroutine.
This method tells flow to trigger a reload of all plugins.
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- await remove_keyword(plugin_id, keyword)[source]¶
This function is a coroutine.
Unregisters a keyword for a plugin with flow launcher.
- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- 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.
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- await run_shell_cmd(cmd, filename='cmd.exe')[source]¶
This function is a coroutine.
Tell flow to run a shell command
- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- await save_all_app_settings()[source]¶
This function is a coroutine.
This method tells flow to save all app settings.
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- await save_plugin_settings()[source]¶
This function is a coroutine.
This method tells flow to save plugin settings
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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
- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- await show_main_window()[source]¶
This function is a coroutine.
This method tells flow to show the main window
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- await update_results(raw_query, results)[source]¶
This function is a coroutine.
Tells flow to change the results shown to the user
Note
The
raw_queryparameter is required by flow launcher, and must be the same as the current raw query in flow launcher for the results to successfully update.- Parameters:
- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- Returns:
None
- class flogin.flow.fuzzy_search.FuzzySearchResult[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[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- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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- Raises:
JsonRPCException – This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
- 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[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[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[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[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[source]¶
This is a replica of the
CustomPluginHotkeydataclass in flow.
- class flogin.flow.settings.PluginsSettings[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]
Errors¶
Plugin Errors¶
- exception flogin.errors.PluginException[source]¶
Bases:
ExceptionA class that represents exceptions with your plugin
- exception flogin.errors.PluginNotInitialized[source]¶
Bases:
PluginExceptionThis is raised when you try to access something that needs data from the initialize method, and it hasn’t been called yet.
- exception flogin.errors.EnvNotSet[source]¶
Bases:
PluginExceptionThis 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¶
- exception flogin.jsonrpc.errors.JsonRPCException(message, data=None)[source]¶
Bases:
ExceptionThis is a generic class representing a JsonRPCException
- data¶
Any data sent with the error
- Type:
Optional[Any]
- exception flogin.jsonrpc.errors.ParserError(message, data=None)[source]¶
Bases:
JsonRPCExceptionThis is a specialized JsonRPCException specifically for the error code -32700, which should mean that flogin sent invalid data and flow was unable to parse it.
- data¶
Any data sent with the error
- Type:
Optional[Any]
- exception flogin.jsonrpc.errors.InvalidRequest(message, data=None)[source]¶
Bases:
JsonRPCExceptionThis is a specialized JsonRPCException specifically for the error code -32600, which should mean that flogin sent an invalid request object.
- data¶
Any data sent with the error
- Type:
Optional[Any]
- exception flogin.jsonrpc.errors.MethodNotFound(message, data=None)[source]¶
Bases:
JsonRPCExceptionThis is a specialized JsonRPCException specifically for the error code -32601, which should mean that flogin is attempting to use a method that doesn’t exist.
- data¶
Any data sent with the error
- Type:
Optional[Any]
- exception flogin.jsonrpc.errors.InvalidParams(message, data=None)[source]¶
Bases:
JsonRPCExceptionThis is a specialized JsonRPCException specifically for the error code -32602, which should mean that flogin is attempting to use a method, but is sending the wrong parameters.
- data¶
Any data sent with the error
- Type:
Optional[Any]
- exception flogin.jsonrpc.errors.InternalError(message, data=None)[source]¶
Bases:
JsonRPCExceptionThis is a specialized JsonRPCException specifically for the error code -32603, which should mean that flogin has received an error.
- data¶
Any data sent with the error
- Type:
Optional[Any]
- exception flogin.jsonrpc.errors.FlowError(message, data=None)[source]¶
Bases:
JsonRPCExceptionThis is a specialized JsonRPCException specifically for error codes between -32000 and -32099, which means that flow has ran into an error.
- data¶
Any data sent with the error
- Type:
Optional[Any]
Pip Errors¶
- exception flogin.errors.PipException[source]¶
Bases:
ExceptionThis is a base class to represent errors derived from the
Pipobject.Added in version 2.0.0.
- exception flogin.errors.UnableToDownloadPip[source]¶
Bases:
PipExceptionThis is an exception which is used to indicate that an error occurred while attempting to download pip.
Added in version 2.0.0.
- error¶
The error that was raised by the Requests: HTTP for Humans™ module.
- exception flogin.errors.PipExecutionError[source]¶
Bases:
PipExceptionThis is an exception which is raised whenever
flogin.pip.Pip.run()gets a return code that isn’t0.Added in version 2.0.0.
- error¶
The original error that was raised by subprocess
- property output¶
strThe output fromsubprocess.CalledProcessError.output
- property returncode¶
intThe returncode fromsubprocess.CalledProcessError.returncode
- property stderr¶
strThe stderr fromsubprocess.CalledProcessError.stderr
Testing¶
- class flogin.testing.plugin_tester.PluginTester[PluginT](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.
- 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,Jsonable] |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, logger=None)[source]¶
Sets up flogin’s default logger.
Changed in version 2.0.0:
setup_logging()now returns tuple[logging.Logger,logging.Handler]- Parameters:
formatter (Optional[
logging.Formatter]) – The formatter to use, incase you don’t want to use the default file formatter.handler (Optional[
logging.Handler]) –The handler object that should be added to the logger. Defaults to
logging.handlers.RotatingFileHandlerwith the following arguments:filename="flogin.log", maxBytes=1000000, encoding="UTF-8", backupCount=1
Added in version 2.0.0.
logger (Optional[
logging.Logger]) –The logger object that the handler/formatter should be added to.
Added in version 2.0.0.
- Returns:
tuple[
logging.Logger,logging.Handler] – The logger and handler used to setup the logs.
- 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=..., name=...)[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.
Changed in version 2.0.0: The default log name now defaults to the filepath of the file that called the function opposed to
printing.- Parameters:
- flogin.utils.MISSING¶
A type safe sentinel used in the library to represent something as missing. Used to distinguish from
Nonevalues.
Pip¶
- defdelete_pip
- defdownload_pip
- defensure_installed
- deffreeze
- definstall_packages
- defrun
- class flogin.pip.Pip(libs_dir='lib')[source]¶
This is a helper class for dealing with pip in a production environment.
When flow launcher installs python, it does not install pip. Because of that, this class will temp-install pip while you need it, then delete it when you’re done with it.
Added in version 2.0.0.
Warning
This class is blocking, and should only be used before you load your plugin.
- Parameters:
libs_dir (Optional[
pathlib.Path|str]) – The directory that your plugin’s dependencies are installed to. Defaults tolib.
Example
This should be used before your plugin gets loaded. Here is an example of what your main file might look like when using pip:
# Add your paths sys.path.append(...) sys.path.append(...) from flogin import Pip with Pip() as pip: pip.ensure_installed("msgspec") # ensure the msgspec package is installed correctly # import and run your plugin from plugin.plugin import YourPlugin YourPlugin().run()
- with Pip(...) as pip:
Pipcan be used as a context manager, withPip.download_pip()being called on enter andPip.delete_pip()being called on exit.
- delete_pip()[source]¶
Deletes the temp version of pip installed on the system.
Note
This is automatically called when using
Pipas a context manager.- Returns:
None
- download_pip()[source]¶
Downloads the temp version of pip from pypa.
Note
This is automatically called when using
Pipas a context manager.- Raises:
UnableToDownloadPip – This is raised when an error occured while attempting to download pip.
- Returns:
None
- ensure_installed(package, *, module=None)[source]¶
Ensures a package is properly installed, and if not, reinstalls it.
- Parameters:
- Raises:
PipException – This is raised when the returncode that pip gives indicates an error.
- Returns:
bool–Trueindicates that the package wasn’t properly installed, and was successfully reinstalled.Falseindicates that the package was already properly installed.
- freeze()[source]¶
Returns a list of installed packages from
pip freeze.Note
The directory checked for packages is set in
Pip.libs_dir.- Raises:
PipException – This is raised when the returncode that pip gives indicates an error.
- Returns:
list[
str] – The list of packages and versions.
- install_packages(*packages)[source]¶
An easy way to install packages for your plugin.
Note
The packages will be installed to the directory set in
Pip.libs_dir.- Parameters:
*packages (
str) – The name of the packages on PyPi that you want to install.- Raises:
PipException – This is raised when the returncode that pip gives indicates an error.
- Returns:
None
- property libs_dir¶
The directory that your plugin’s dependencies are installed to.
- Type:
- run(*args)[source]¶
Runs a pip CLI command.
This method is used to interact directly with pip.
Note
This method can not be used until
download_pip()is ran, which you can do by calling it manually or usingPipas a context manager.- Parameters:
*args (
str) – The args that should be passed to pip. Ex:help.- Raises:
PipExecutionError – This is raised when the returncode that pip gives indicates an error.
RuntimeError – This is raised when
Pip.download_pip()has not ran yet.
- Returns:
str– The output from pip.
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.