DotnetPythonHandler 1.1.0
dotnet add package DotnetPythonHandler --version 1.1.0
NuGet\Install-Package DotnetPythonHandler -Version 1.1.0
<PackageReference Include="DotnetPythonHandler" Version="1.1.0" />
paket add DotnetPythonHandler --version 1.1.0
#r "nuget: DotnetPythonHandler, 1.1.0"
// Install DotnetPythonHandler as a Cake Addin
#addin nuget:?package=DotnetPythonHandler&version=1.1.0
// Install DotnetPythonHandler as a Cake Tool
#tool nuget:?package=DotnetPythonHandler&version=1.1.0
PythonHandler
This package is a wrapper around IronPython/CPython allowing for easily running Python scripts.
Create a Handler
(IronPython)
using PythonHandler;
// Create a handler without additional module search paths.
Handler pythonHandler = new Handler();
// Create a handler with additional module search paths.
var searchPaths = new List<string>() {"/custom/python/lib"}
Handler pythonHandler = new Handler(searchPaths);
Run from String (IronPython)
using PythonHandler;
Handler pythonHandler = new Handler();
// Run an IronPython script from a string without a return value.
pythonHandler.RunFromString("import sys; sysversion = sys.version");
// Run an IronPython script from a string with a return value.
var result = pythonHandler.RunFromString<string>("import sys; sysversion = sys.version", "sysversion");
// Run an IronPython script from a string with a return value and additional variables.
var tdict = new Dictionary<string, object>();
tdict.Add("testvar", "1ece43cc-b45a-4f97-ba69-5106f23e3932");
var result = pythonHandler.RunFromString<string>("import sys", "testvar", tdict);
Run from File (IronPython)
using PythonHandler;
Handler pythonHandler = new Handler();
// Run an IronPython script from a file without a return value.
pythonHandler.RunFromFile("import sys; sysversion = sys.version");
// Run an IronPython script from a file with a return value.
var result = pythonHandler.RunFromFile<string>("import sys; sysversion = sys.version", "sysversion");
// Run an IronPython script from a file with a return value and additional variables.
var tdict = new Dictionary<string, object>();
tdict.Add("testvar", "1ece43cc-b45a-4f97-ba69-5106f23e3932");
var result = pythonHandler.RunFromFile<string>("import sys", "testvar", tdict);
Create a CHandler
(CPython)
using PythonHandler;
// Create a handler without additional module search paths.
CHandler pythonHandler = new CHandler();
// Create a handler with additional module search paths.
var searchPaths = new List<string>() {"/custom/python/lib"}
CHandler pythonHandler = new CHandler(searchPaths);
Run from String (CPython)
using PythonHandler;
CHandler pythonHandler = new CHandler();
// Run a CPython script from a string without a return value.
pythonHandler.RunFromString("import sys; sysversion = sys.version");
// Run a CPython script from a string with a return value.
var result = pythonHandler.RunFromString<string>("import sys; sysversion = sys.version", "sysversion");
// Run a CPython script from a string with a return value and additional variables.
var tdict = new Dictionary<string, object>();
tdict.Add("testvar", "1ece43cc-b45a-4f97-ba69-5106f23e3932");
var result = pythonHandler.RunFromString<string>("import sys", "testvar", tdict);
Run from File (CPython)
using PythonHandler;
CHandler pythonHandler = new CHandler();
// Run a CPython script from a file without a return value.
pythonHandler.RunFromFile("import sys; sysversion = sys.version");
// Run a CPython script from a file with a return value.
var result = pythonHandler.RunFromFile<string>("import sys; sysversion = sys.version", "sysversion");
// Run a CPython script from a file with a return value and additional variables.
var tdict = new Dictionary<string, object>();
tdict.Add("testvar", "1ece43cc-b45a-4f97-ba69-5106f23e3932");
var result = pythonHandler.RunFromFile<string>("import sys", "testvar", tdict);
Contents
- PythonHandler
- Create a
Handler
(IronPython) - Run from String (IronPython)
- Run from File (IronPython)
- Create a
CHandler
(CPython) - Run from String (CPython)
- Run from File (CPython)
- Contents
- Classes
CHandler
- Constructor & Destructor Documentation
- Member Function Documentation
- void PythonHandler.CHandler.RunFromFile (string scriptFile)
- void PythonHandler.CHandler.RunFromFile (string scriptFile, Dictionary< string, object > variables)
- TResult PythonHandler.CHandler.RunFromFile< TResult > (string scriptFile, string returnVariable)
- TResult PythonHandler.CHandler.RunFromFile< TResult > (string scriptFile, string returnVariable, Dictionary< string, object > variables)
- void PythonHandler.CHandler.RunFromString (string code)
- void PythonHandler.CHandler.RunFromString (string code, Dictionary< string, object > variables)
- TResult PythonHandler.CHandler.RunFromString< TResult > (string code, string returnVariable)
- TResult PythonHandler.CHandler.RunFromString< TResult > (string code, string returnVariable, Dictionary< string, object > variables)
Handler
- Constructor & Destructor Documentation
- Member Function Documentation
- void PythonHandler.Handler.AppendSearchPath (string searchPath)
- void PythonHandler.Handler.RunFromFile (string scriptFile)
- void PythonHandler.Handler.RunFromFile (string scriptFile, Dictionary< string, object > variables)
- TResult PythonHandler.Handler.RunFromFile< TResult > (string scriptFile, string returnVariable)
- TResult PythonHandler.Handler.RunFromFile< TResult > (string scriptFile, string returnVariable, Dictionary< string, object > variables)
- void PythonHandler.Handler.RunFromString (string code)
- void PythonHandler.Handler.RunFromString (string code, Dictionary< string, object > variables)
- TResult PythonHandler.Handler.RunFromString< TResult > (string code, string returnVariable)
- TResult PythonHandler.Handler.RunFromString< TResult > (string code, string returnVariable, Dictionary< string, object > variables)
- Create a
Classes
CHandler
Class CHandler
handles execution of Python scripts using a local
Python setup.
Constructor & Destructor Documentation
PythonHandler.CHandler.CHandler (string pythonDllPath)
This constructor initializes a new CHandler
.
Parameters
pythonDllPath The local path of the Python DLL to use for the runtime.
PythonHandler.CHandler.CHandler (string pythonDllPath, string pythonHome)
This constructor initializes a new CHandler
.
Parameters
pythonDllPath The local path of the Python DLL to use for the runtime.
pythonHome The path to the python home directory.
Member Function Documentation
void PythonHandler.CHandler.RunFromFile (string scriptFile)
This method runs a Python script.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
void PythonHandler.CHandler.RunFromFile (string scriptFile, Dictionary< string, object > variables)
This method runs a Python script.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
variablesvariables
is anDictionary
containing the key/values of variables to set.
TResult PythonHandler.CHandler.RunFromFile< TResult > (string scriptFile, string returnVariable)
This method runs a Python script.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
returnVariablereturnVariable
is the variable to read from the scope.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
Returns
The value of the
returnVariable
from the scope.
TResult PythonHandler.CHandler.RunFromFile< TResult > (string scriptFile, string returnVariable, Dictionary< string, object > variables)
This method runs a Python script.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
returnVariablereturnVariable
is the variable to read from the scope.
variablesvariables
is anDictionary
containing the key/values of variables to set.
Returns
The value of the
returnVariable
from the scope.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
void PythonHandler.CHandler.RunFromString (string code)
This method runs a string of Python code.
Parameters
code
code
is the Python string to execute.
void PythonHandler.CHandler.RunFromString (string code, Dictionary< string, object > variables)
This method runs a string of Python code.
Parameters
code
code
is the Python string to execute.
variablesvariables
is anDictionary
containing the key/values of variables to set.
TResult PythonHandler.CHandler.RunFromString< TResult > (string code, string returnVariable)
This method runs a string of Python code.
Parameters
code
code
is the Python string to execute.
returnVariablereturnVariable
is the variable to read from the scope.
Returns
The value of the
returnVariable
from the scope.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
TResult PythonHandler.CHandler.RunFromString< TResult > (string code, string returnVariable, Dictionary< string, object > variables)
This method runs a string of Python code.
Parameters
code
code
is the Python string to execute.
returnVariablereturnVariable
is the variable to read from the scope.
variablesvariables
is anDictionary
containing the key/values of variables to set.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
Returns
The value of the
returnVariable
from the scope.
Handler
Class Handler
handles execution of Python scripts using IronPython.
Constructor & Destructor Documentation
PythonHandler.Handler.Handler (ICollection< string > additionalSearchPaths)
This constructor initializes a new Handler
with additional module
search paths.
Parameters
additionalSearchPaths
additionalSearchPaths
is a collection of addtional module search paths to add to the IronPython scope.
Member Function Documentation
void PythonHandler.Handler.AppendSearchPath (string searchPath)
This method appends a search path to the engine.
Parameters
searchPath
searchPath
is the new search path to append to the engine.
void PythonHandler.Handler.RunFromFile (string scriptFile)
This method runs a Python script.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
void PythonHandler.Handler.RunFromFile (string scriptFile, Dictionary< string, object > variables)
This method runs a Python script.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
variablesvariables
is anDictionary
containing the key/values of variables to set.
TResult PythonHandler.Handler.RunFromFile< TResult > (string scriptFile, string returnVariable)
This method runs a Python script.
Template Parameters
TResult The type of data to return.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
returnVariablereturnVariable
is the variable to read from the scope.
Returns
The value of the
returnVariable
from the scope.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
TResult PythonHandler.Handler.RunFromFile< TResult > (string scriptFile, string returnVariable, Dictionary< string, object > variables)
This method runs a Python script.
Template Parameters
TResult The type of data to return.
Parameters
scriptFile
scriptFile
is the path to the Python script to execute.
returnVariablereturnVariable
is the variable to read from the scope.
variablesvariables
is anDictionary
containing the key/values of variables to set.
Returns
The value of the
returnVariable
from the scope.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
void PythonHandler.Handler.RunFromString (string code)
This method runs a string of Python code.
Parameters
code
code
is the Python string to execute.
void PythonHandler.Handler.RunFromString (string code, Dictionary< string, object > variables)
This method runs a string of Python code.
Parameters
code
code
is the Python string to execute.
variablesvariables
is anDictionary
containing the key/values of variables to set.
TResult PythonHandler.Handler.RunFromString< TResult > (string code, string returnVariable)
This method runs a string of Python code.
Template Parameters
TResult The type of data to return.
Parameters
code
code
is the Python string to execute.
returnVariablereturnVariable
is the variable to read from the scope.
Returns
The value of the
returnVariable
from the scope.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
TResult PythonHandler.Handler.RunFromString< TResult > (string code, string returnVariable, Dictionary< string, object > variables)
This method runs a string of Python code.
Template Parameters
TResult The type of data to return.
Parameters
code
code
is the Python string to execute.
returnVariablereturnVariable
is the variable to read from the scope.
variablesvariables
is anDictionary
containing the key/values of variables to set.
Returns
The value of the
returnVariable
from the scope.
Exceptions
KeyNotFoundException The
returnVariable
was not found.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- IronPython (>= 3.4.0)
- IronPython.StdLib (>= 3.4.0)
- pythonnet (>= 3.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.