octoprint.plugin¶
This module represents OctoPrint’s plugin subsystem. This includes management and helper methods as well as the registered plugin types.
-
octoprint.plugin.plugin_manager(init=
False
, plugin_folders=None
, plugin_bases=None
, plugin_entry_points=None
, plugin_disabled_list=None
, plugin_sorting_order=None
, plugin_blacklist=None
, plugin_restart_needing_hooks=None
, plugin_obsolete_hooks=None
, plugin_considered_bundled=None
, plugin_flags=None
, plugin_validators=None
, compatibility_ignored_list=None
)¶ Factory method for initially constructing and consecutively retrieving the
PluginManager
singleton.- Parameters:¶
- init : boolean¶
A flag indicating whether this is the initial call to construct the singleton (True) or not (False, default). If this is set to True and the plugin manager has already been initialized, a
ValueError
will be raised. The same will happen if the plugin manager has not yet been initialized and this is set to False.- plugin_folders : list¶
A list of folders (as strings containing the absolute path to them) in which to look for potential plugin modules. If not provided this defaults to the configured
plugins
base folder andsrc/plugins
within OctoPrint’s code base.- plugin_bases : list¶
A list of recognized plugin base classes for which to look for provided implementations. If not provided this defaults to
OctoPrintPlugin
.- plugin_entry_points : list¶
A list of entry points pointing to modules which to load as plugins. If not provided this defaults to the entry point
octoprint.plugin
.- plugin_disabled_list : list¶
A list of plugin identifiers that are currently disabled. If not provided this defaults to all plugins for which
enabled
is set toFalse
in the settings.- plugin_sorting_order : dict¶
A dict containing a custom sorting orders for plugins. The keys are plugin identifiers, mapped to dictionaries containing the sorting contexts as key and the custom sorting value as value.
- plugin_blacklist : list¶
A list of plugin identifiers/identifier-requirement tuples that are currently blacklisted.
- plugin_restart_needing_hooks : list¶
A list of hook namespaces which cause a plugin to need a restart in order be enabled/disabled. Does not have to contain full hook identifiers, will be matched with startswith similar to logging handlers
- plugin_obsolete_hooks : list¶
A list of hooks that have been declared obsolete. Plugins implementing them will not be enabled since they might depend on functionality that is no longer available.
- plugin_considered_bundled : list¶
A list of plugin identifiers that are considered bundled plugins even if installed separately.
- plugin_flags : dict¶
A dict mapping plugin identifiers to additional flags used to override certain behaviours using configuration.
- plugin_validators : list¶
A list of additional plugin validators through which to process each plugin.
- compatibility_ignored_list : list¶
A list of plugin keys for which it will be ignored if they are flagged as incompatible. This is for development purposes only and should not be used in production.
- Returns:¶
- A fully initialized
PluginManager
instance to be used for plugin management tasks.
- A fully initialized
- Return type:¶
- Raises:¶
ValueError –
init
was True although the plugin manager was already initialized, or it was False although the plugin manager was not yet initialized.
-
octoprint.plugin.plugin_settings(plugin_key, defaults=
None
, get_preprocessors=None
, set_preprocessors=None
, settings=None
)¶ Factory method for creating a
PluginSettings
instance.- Parameters:¶
- plugin_key : string¶
The plugin identifier for which to create the settings instance.
- defaults : dict¶
The default settings for the plugin, if different from get_settings_defaults.
- get_preprocessors : dict¶
The getter preprocessors for the plugin.
- set_preprocessors : dict¶
The setter preprocessors for the plugin.
- settings : octoprint.settings.Settings¶
The settings instance to use.
- Returns:¶
- A fully initialized
PluginSettings
instance to be used to access the plugin’s settings
- A fully initialized
- Return type:¶
-
octoprint.plugin.call_plugin(types, method, args=
None
, kwargs=None
, callback=None
, error_callback=None
, sorting_context=None
, initialized=True
, manager=None
)¶ Helper method to invoke the indicated
method
on all registered plugin implementations implementing the indicatedtypes
. Allows providing method arguments and registering callbacks to call in case of success and/or failure of each call which can be used to return individual results to the calling code.Example:
def my_success_callback(name, plugin, result): print("{name} was called successfully and returned {result!r}".format(**locals())) def my_error_callback(name, plugin, exc): print("{name} raised an exception: {exc!s}".format(**locals())) octoprint.plugin.call_plugin( [octoprint.plugin.StartupPlugin], "on_startup", args=(my_host, my_port), callback=my_success_callback, error_callback=my_error_callback )
- Parameters:¶
- types : list¶
A list of plugin implementation types to match against.
- method : string¶
Name of the method to call on all matching implementations.
- args : tuple¶
A tuple containing the arguments to supply to the called
method
. Optional.- kwargs : dict¶
A dictionary containing the keyword arguments to supply to the called
method
. Optional.- callback : function¶
A callback to invoke after an implementation has been called successfully. Will be called with the three arguments
name
,plugin
andresult
.name
will be the plugin identifier,plugin
the plugin implementation instance itself andresult
the result returned from themethod
invocation.- error_callback : function¶
A callback to invoke after the call of an implementation resulted in an exception. Will be called with the three arguments
name
,plugin
andexc
.name
will be the plugin identifier,plugin
the plugin implementation instance itself andexc
the caught exception.- initialized : boolean¶
Ignored.
- manager : PluginManager or None¶
The plugin manager to use. If not provided, the global plugin manager
-
class octoprint.plugin.PluginSettings(settings, plugin_key, defaults=
None
, get_preprocessors=None
, set_preprocessors=None
)¶ The
PluginSettings
class is the interface for plugins to their own or globally defined settings.It provides some convenience methods for directly accessing plugin settings via the regular
octoprint.settings.Settings
interfaces as well as means to access plugin specific folder locations.All getter and setter methods will ensure that plugin settings are stored in their correct location within the settings structure by modifying the supplied paths accordingly.
- Parameters:¶
-
get(path, merged=
False
, asdict=False
)¶ Retrieves a raw value from the settings for
path
, optionally merging the raw value with the default settings ifmerged
is set to True.
-
get_int(path, min=
None
, max=None
)¶ Like
get()
but tries to convert the retrieved value toint
. Ifmin
is provided and the retrieved value is less than it, it will be returned instead of the value. Likewise formax
- it will be returned if the value is greater than it.
-
get_float(path, min=
None
, max=None
)¶ Like
get()
but tries to convert the retrieved value tofloat
. Ifmin
is provided and the retrieved value is less than it, it will be returned instead of the value. Likewise formax
- it will be returned if the value is greater than it.
-
set_int(path, value, force=
False
, min=None
, max=None
)¶ Like
set()
but ensures the value is anint
through attempted conversion before setting it. Ifmin
and/ormax
are provided, it will also be ensured that the value is greater than or equal tomin
and less than or equal tomax
. If that is not the case, the limit value (min
if less than that,max
if greater than that) will be set instead.
-
set_float(path, value, force=
False
, min=None
, max=None
)¶ Like
set()
but ensures the value is anfloat
through attempted conversion before setting it. Ifmin
and/ormax
are provided, it will also be ensured that the value is greater than or equal tomin
and less than or equal tomax
. If that is not the case, the limit value (min
if less than that,max
if greater than that) will be set instead.
-
set_boolean(path, value, force=
False
)¶ Like
set()
but ensures the value is anboolean
through attempted conversion before setting it.
-
save(force=
False
, trigger_event=False
)¶ Saves the settings to
config.yaml
if there are active changes. Ifforce
is set toTrue
the settings will be saved even if there are no changes. Settingstrigger_event
toTrue
will cause aSettingsUpdated
event to get triggered.
-
add_overlay(overlay, at_end=
False
, key=None
)¶ Adds a new config overlay for the plugin’s settings. Will return the overlay’s key in the map.
- remove_overlay(key)¶
Removes an overlay from the settings based on its key. Return
True
if the overlay could be found and was removed,False
otherwise.
- get_plugin_data_folder()¶
Deprecated since version 1.2.0: Replaced by
get_plugin_data_folder()
-
get_plugin_logfile_path(postfix=
None
)¶ Retrieves the path to a logfile specifically for the plugin. If
postfix
is not supplied, the logfile will be namedplugin_<plugin identifier>.log
and located within the configuredlogs
folder. If a postfix is supplied, the name will beplugin_<plugin identifier>_<postfix>.log
at the same location.Plugins may use this for specific logging tasks. For example, a
SlicingPlugin
might want to create a log file for logging the output of the slicing engine itself if some debug flag is set.
- global_get(path, **kwargs)¶
Getter for retrieving settings not managed by the plugin itself from the core settings structure. Use this to access global settings outside of your plugin.
Directly forwards to
octoprint.settings.Settings.get()
.
- global_get_basefolder(folder_type, **kwargs)¶
Retrieves a globally defined basefolder of the given
folder_type
. Directly forwards tooctoprint.settings.Settings.getBaseFolder()
.
- global_get_boolean(path, **kwargs)¶
Like
global_get()
but directly orwards tooctoprint.settings.Settings.getBoolean()
.
- global_get_float(path, **kwargs)¶
Like
global_get()
but directly forwards tooctoprint.settings.Settings.getFloat()
.
- global_get_int(path, **kwargs)¶
Like
global_get()
but directly forwards tooctoprint.settings.Settings.getInt()
.
- global_set(path, value, **kwargs)¶
Setter for modifying settings not managed by the plugin itself on the core settings structure. Use this to modify global settings outside of your plugin.
Directly forwards to
octoprint.settings.Settings.set()
.
- global_set_boolean(path, value, **kwargs)¶
Like
global_set()
but directly forwards tooctoprint.settings.Settings.setBoolean()
.
- global_set_float(path, value, **kwargs)¶
Like
global_set()
but directly forwards tooctoprint.settings.Settings.setFloat()
.
- global_set_int(path, value, **kwargs)¶
Like
global_set()
but directly forwards tooctoprint.settings.Settings.setInt()
.
octoprint.plugin.core¶
In this module resides the core data structures and logic of the plugin system.
-
class octoprint.plugin.core.PluginManager(plugin_folders, plugin_bases, plugin_entry_points, logging_prefix=
None
, plugin_disabled_list=None
, plugin_sorting_order=None
, plugin_blacklist=None
, plugin_restart_needing_hooks=None
, plugin_obsolete_hooks=None
, plugin_considered_bundled=None
, plugin_flags=None
, plugin_validators=None
, compatibility_ignored_list=None
)¶ The
PluginManager
is the central component for finding, loading and accessing plugins provided to the system.It is able to discover plugins both through possible file system locations as well as customizable entry points.
-
enable_plugin(name, plugin=
None
, initialize_implementation=True
, startup=False
)¶ Enables a plugin
- get_filtered_implementations(f, *types, **kwargs)¶
Get all mixin implementations that implement all of the provided
types
and match the provided filter f.
- get_helpers(name, *helpers)¶
Retrieves the named
helpers
for the plugin with identifiername
.If the plugin is not available, returns None. Otherwise returns a
dict
with the requested plugin helper names mapped to the method - if a helper could not be resolved, it will be missing from the dict.
- get_implementations(*types, **kwargs)¶
Get all mixin implementations that implement all of the provided
types
.
-
get_plugin(identifier, require_enabled=
True
)¶ Retrieves the module of the plugin identified by
identifier
. If the plugin is not registered or disabled andrequired_enabled
is True (the default) None will be returned.
-
get_plugin_info(identifier, require_enabled=
True
)¶ Retrieves the
PluginInfo
instance identified byidentifier
. If the plugin is not registered or disabled andrequired_enabled
is True (the default) None will be returned.
- static has_any_of_hooks(plugin, *hooks)¶
Tests if the
plugin
contains any of the providedhooks
.Uses
octoprint.plugin.core.PluginManager.hook_matches_hooks()
.
- static has_any_of_mixins(plugin, *mixins)¶
Tests if the
plugin
has an implementation implementing any of the providedmixins
.
- has_restart_needing_hooks(plugin)¶
Checks whether the plugin has any hooks that need a restart on changes
- has_restart_needing_implementation(plugin)¶
Checks whether the plugin’s implementation needs a restart on changes
- static hook_matches_hooks(hook, *hooks)¶
Tests if
hook
matches any of the providedhooks
to test for.hook
is expected to be an exact hook name.hooks
is expected to be a list containing one or more hook names or patterns. That can be either an exact hook name or anfnmatch.fnmatch()
pattern.
- property plugin_hooks¶
Returns: (dict) dictionary of registered hooks and their handlers
- property plugins¶
Returns: (list) list of enabled and disabled registered plugins
- register_message_receiver(client)¶
Registers a
client
for receiving plugin messages. Theclient
needs to be a callable accepting two input arguments,plugin
(the sending plugin’s identifier) anddata
(the message itself), and one optional keyword argument,permissions
(an optional list of permissions to test against).
-
reload_plugins(startup=
False
, initialize_implementations=True
, force_reload=None
)¶ Reloads plugins, detecting newly added ones in the process.
-
send_plugin_message(plugin, data, permissions=
None
)¶ Sends
data
in the name ofplugin
to all currently registered message receivers by invoking them with the three arguments.
-
enable_plugin(name, plugin=
-
class octoprint.plugin.core.PluginInfo(key, location, instance, name=
None
, version=None
, description=None
, author=None
, url=None
, license=None
, parsed_metadata=None
)¶ The
PluginInfo
class wraps all available information about a registered plugin.This includes its meta data (like name, description, version, etc) as well as the actual plugin extensions like implementations, hooks and helpers.
It works on Python module objects and extracts the relevant data from those via accessing the control properties.
- Parameters:¶
- key : str¶
Identifier of the plugin
- location : str¶
Installation folder of the plugin
- instance : module¶
Plugin module instance - this may be
None
if the plugin has been blacklisted!- name : str¶
Human readable name of the plugin
- version : str¶
Version of the plugin
- description : str¶
Description of the plugin
Author of the plugin
- url : str¶
URL of the website of the plugin
- license : str¶
License of the plugin
- property author¶
Author of the plugin. Will be taken from the author attribute of the plugin module as defined in
attr_author
if available, otherwise from theauthor
supplied during construction. May be None.
- blacklisted¶
Whether the plugin is blacklisted.
- bundled¶
Whether this plugin is bundled with OctoPrint.
- property check¶
Method for pre-load check of plugin. Will be taken from the check attribute of the plugin module as defined in
attr_check
if available, otherwise a lambda always returning True is returned.
- property description¶
Description of the plugin. Will be taken from the description attribute of the plugin module as defined in
attr_description
if available, otherwise from thedescription
supplied during construction. May be None.
- property disable¶
Method for disabling the plugin module. Will be taken from the disable attribute of the plugin module as defined in
attr_disable
if available, otherwise a no-operation lambda will be returned.
- property disabling_discouraged¶
Reason why disabling of this plugin is discouraged. Only evaluated for bundled plugins! Will be taken from the disabling_discouraged attribute of the plugin module as defined in
attr_disabling_discouraged
if available. False if unset or plugin not bundled.
- property enable¶
Method for enabling the plugin module. Will be taken from the enable attribute of the plugin module as defined in
attr_enable
if available, otherwise a no-operation lambda will be returned.
- enabled¶
Whether the plugin is enabled.
- flags¶
Additional flags assigned to the plugin through config.
- forced_disabled¶
Whether the plugin has been force disabled by the system, e.g. due to safe mode blacklisting.
- property helpers¶
Helpers provided by the plugin. Will be taken from the helpers attribute of the plugin module as defined in
attr_helpers
if available, otherwise an empty list is returned.
Hidden flag.
Whether the plugin should be flagged as hidden or not
- property hooks¶
Hooks provided by the plugin. Will be taken from the hooks attribute of the plugin module as defined in
attr_hooks
if available, otherwise an empty dictionary is returned.
- property implementation¶
Implementation provided by the plugin. Will be taken from the implementation attribute of the plugin module as defined in
attr_implementation
if available, otherwise None is returned.
- incompatible¶
Whether this plugin has been detected as incompatible.
- invalid_syntax¶
Whether invalid syntax was encountered while trying to load this plugin.
- property license¶
License of the plugin. Will be taken from the license attribute of the plugin module as defined in
attr_license
if available, otherwise from thelicense
supplied during construction. May be None.
- property load¶
Method for loading the plugin module. Will be taken from the load attribute of the plugin module as defined in
attr_load
if available, otherwise a no-operation lambda will be returned.
- loaded¶
Whether this plugin has been loaded.
-
long_str(show_bundled=
False
, bundled_strs=(' [B]', '')
, show_location=False
, location_str=' - {location}'
, show_enabled=False
, enabled_strs=('* ', ' ', 'X ', 'C ')
)¶ Long string representation of the plugin’s information. Will return a string of the format
<enabled><str(self)><bundled><location>
.enabled
,bundled
andlocation
will only be displayed if the corresponding flags are set toTrue
. The will be filled fromenabled_str
,bundled_str
andlocation_str
as follows:enabled_str
a 4-tuple, the first entry being the string to insert when the plugin is enabled, the second entry the string to insert when it is not, the third entry the string when it is blacklisted and the fourth when it is incompatible.
bundled_str
a 2-tuple, the first entry being the string to insert when the plugin is bundled, the second entry the string to insert when it is not.
location_str
a format string (to be parsed with
str.format
), the{location}
placeholder will be replaced with the plugin’s installation folder on disk.
- Parameters:¶
- show_enabled : boolean¶
whether to show the
enabled
part- enabled_strs : tuple¶
the 2-tuple containing the two possible strings to use for displaying the enabled state
- show_bundled : boolean¶
whether to show the
bundled
part- bundled_strs : tuple¶
the 2-tuple containing the two possible strings to use for displaying the bundled state
- show_location : boolean¶
whether to show the
location
part- location_str : str¶
the format string to use for displaying the plugin’s installation location
- Returns:¶
The long string representation of the plugin as described above
- Return type:¶
- property looks_like_plugin¶
Returns whether the plugin actually looks like a plugin (has control properties) or not.
- managable¶
Whether this plugin can be managed by OctoPrint.
- property name¶
Human readable name of the plugin. Will be taken from name attribute of the plugin module if available, otherwise from the
name
supplied during construction with a fallback tokey
.
- needs_restart¶
Whether this plugin needs a restart of OctoPrint after enabling/disabling.
- origin¶
The origin from which this plugin was loaded, either a
EntryPointOrigin
,FolderOrigin
orModuleOrigin
instance. Set during loading, initiallyNone
.
- property parsed_metadata¶
The plugin metadata parsed from the plugin’s AST.
- property privacypolicy¶
Privacy Policy URL of the plugin. Will be taken from the privacy policy attribute of the plugin module as defined in
attr_privacypolicy
if available. May be None.
- property pythoncompat¶
Python compatibility string of the plugin module as defined in
attr_pythoncompat
if available, otherwise defaults to>=2.7,<3
.
- property unload¶
Method for unloading the plugin module. Will be taken from the unload attribute of the plugin module as defined in
attr_unload
if available, otherwise a no-operation lambda will be returned.
- property url¶
Website URL for the plugin. Will be taken from the url attribute of the plugin module as defined in
attr_url
if available, otherwise from theurl
supplied during construction. May be None.
-
validate(phase, additional_validators=
None
)¶ Validates the plugin for various validation phases.
phase
can be one ofbefore_import
,before_load
,after_load
.Used by
PluginManager
, should not be used elsewhere.
- class octoprint.plugin.core.Plugin¶
The parent class of all plugin implementations.
- _identifier¶
The identifier of the plugin. Injected by the plugin core system upon initialization of the implementation.
- _plugin_name¶
The name of the plugin. Injected by the plugin core system upon initialization of the implementation.
- _plugin_version¶
The version of the plugin. Injected by the plugin core system upon initialization of the implementation.
- _basefolder¶
The base folder of the plugin. Injected by the plugin core system upon initialization of the implementation.
- _logger¶
The logger instance to use, with the logging name set to the
PluginManager.logging_prefix
of thePluginManager
concatenated with_identifier
. Injected by the plugin core system upon initialization of the implementation.
- initialize()¶
Called by the plugin core after performing all injections. Override this to initialize your implementation.
- on_plugin_disabled()¶
Called by the plugin core when the plugin was disabled. Override this to react to the event.
- on_plugin_enabled()¶
Called by the plugin core when the plugin was enabled. Override this to react to the event.
- class octoprint.plugin.core.RestartNeedingPlugin¶
Mixin for plugin types that need a restart after enabling/disabling them.
- class octoprint.plugin.core.SortablePlugin¶
Mixin for plugin types that are sortable.
-
get_sorting_key(context=
None
)¶ Returns the sorting key to use for the implementation in the specified
context
.May return
None
if order is irrelevant.Implementations returning None will be ordered by plugin identifier after all implementations which did return a sorting key value that was not None sorted by that.
-
get_sorting_key(context=
octoprint.plugin.types¶
This module bundles all of OctoPrint’s supported plugin implementation types as well as their common parent
class, OctoPrintPlugin
.
Please note that the plugin implementation types are documented in the section Available plugin mixins.
- class octoprint.plugin.types.OctoPrintPlugin¶
Bases:
Plugin
The parent class of all OctoPrint plugin mixins.
- _plugin_manager¶
The
PluginManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _printer_profile_manager¶
The
PrinterProfileManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _event_bus¶
The
EventManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _analysis_queue¶
The
AnalysisQueue
instance. Injected by the plugin core system upon initialization of the implementation.
- _slicing_manager¶
The
SlicingManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _file_manager¶
The
FileManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _printer¶
The
PrinterInterface
instance. Injected by the plugin core system upon initialization of the implementation.
- _app_session_manager¶
The
SessionManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _plugin_lifecycle_manager¶
The
LifecycleManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _user_manager¶
The
UserManager
instance. Injected by the plugin core system upon initialization of the implementation.
- _connectivity_checker¶
The
ConnectivityChecker
instance. Injected by the plugin core system upon initialization of the implementation.
- _data_folder¶
Path to the data folder for the plugin to use for any data it might have to persist. Should always be accessed through
get_plugin_data_folder()
since that function will also ensure that the data folder actually exists and if not creating it before returning it. Injected by the plugin core system upon initialization of the implementation.
- get_plugin_data_folder()¶
Retrieves the path to a data folder specifically for the plugin, ensuring it exists and if not creating it before returning it.
Plugins may use this folder for storing additional data they need for their operation.
- on_plugin_pending_uninstall()¶
Called by the plugin manager when the plugin is pending uninstall. Override this to react to the event.
NOT called during plugin uninstalls triggered outside of OctoPrint!