Elektra
0.9.6
|
The plugin uses Python to do magic things. It allows plugins to be written in Python.
What a Python script can do is not really limited by design, so any kind of plugin may be implemented. The python plugin is especially useful to write filter and logging scripts.
See installation. The package is called libelektra5-python
.
The python plugin requires the configuration parameter script holding the file path to a python script. The mount command would look like
if the ini plugin should be used for storage and the python plugin only serves to invoke the filter script.
For a Python script that serves as INI storage plugin itself, one uses
The python plugin supports following optional configuration values/flags:
script
(string): The script to be executed.print
(flag): Make the plugin print engine errors, triggered by the calls of this plugin, to stderr. Mainly intended for diagnostic. Please note that the Python engine itself will print script errors to stderr regardless of this flag.python/path
(string): Extends sys.path by this entry. Better then PYTHONPATH it is always available, regardless of the context where a binary is executed.Python scripts must implement a class called ElektraPlugin
with one parameter. The class itself can implement the following functions
where config & returned are KeySets and errorKey & parentKey are Keys. For the return codes of the functions, the same rules as for normal plugins apply.
If a function is not available, it simply is not called. A script does not have to implement all functions therefore.
Access to kdb can be retrieved using the Python import
An example script that prints some information for each method call would be:
Further examples can be found in the python directory.
Be aware that a Python script will never be as performant as a native C/C++ plugin. Spinning up the interpreter takes additional time and resources.