Provides the infrastructure for executing Python scripts. Typically used areas and classes/interfaces/services: - PythonLanguageService. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.
$ dotnet add package Kephas.Scripting.PythonThe Python scripting area in Kephas handles Python dynamic code execution using IronPython.
Check the following packages for more information:
// normally you would get the processor injected into the service constructor.
var processor = injector.Resolve<IScriptProcessor>();
var result = await processor.ExecuteAsync(new PythonStringScript("name[..4] + str(age)"), new Expando { ["name"] = "Johnny", ["age"] = 42 })).PreserveThreadContext();
Assert.Equals("John42", result);
The file scripts assume that the language can be inferred from the file extension.
For Python, it means that the file needs to and with a *.py extension.
If this is not the case, make sure you specify the language explicitly when creating a FileScript.
// normally you would get the processor injected into the service constructor.
var processor = injector.Resolve<IScriptProcessor>();
// Python scripts ending with *.py
var result = await processor.ExecuteAsync(new FileScript("myscript.py"), new { name = "Johnny", age = 42 })).PreserveThreadContext();
Assert.Equals("John42", result);
// Python scripts not ending with *.py
var result = await processor.ExecuteAsync(new FileScript("myscript.txt", PythonLanguageService.Language), new { name = "Johnny", age = 42 })).PreserveThreadContext();
Assert.Equals("John42", result);
PythonLanguageServiceThis service is the ILanguageService implementation for the Python language.
It uses the PythonSettings to configure the way it controls the execution. These are the options:
Note: The search paths are locations handled by the
ILocationsManagerservice. When adding tenant support, each tenant will get its own copy.
{
"searchPaths": [ "../config/.pylib" ],
"preloadGlobalModules": true
}