Ekeel.Interop.Python 1.0.1

dotnet add package Ekeel.Interop.Python --version 1.0.1
NuGet\Install-Package Ekeel.Interop.Python -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ekeel.Interop.Python" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ekeel.Interop.Python --version 1.0.1
#r "nuget: Ekeel.Interop.Python, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Ekeel.Interop.Python as a Cake Addin
#addin nuget:?package=Ekeel.Interop.Python&version=1.0.1

// Install Ekeel.Interop.Python as a Cake Tool
#tool nuget:?package=Ekeel.Interop.Python&version=1.0.1

Ekeel.Interop.Python

A wrapper around PythonNet that allows for execution of Python code.

using Ekeel.Interop.Python;

var pythonHandler = new Handler();

var variables = new Dictionary<string, object>();
variables.Add("test_var", "test_var_val");

pythonHandler.RunFromFile(@"C:\tmp\test.py", "test_var", variables);

Handler

Class Handler handles execution of Python scripts using a local Python setup.

Constructors

Handler()

This constructor initializes a new Handler using a .env file.

Notes:

  • Read required variables from a local .env file.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();
Handler(string pythonDllPath)

This constructor initializes a new Handler.

Parameters:

  • pythonDllPath
    • The local path of the Python DLL to use for the runtime.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler(@"C:\tmp\test.dll");
Handler(string pythonDllPath, string pythonHome)

This constructor initializes a new Handler.

Parameters:

  • pythonDllPath
    • The local path of the Python DLL to use for the runtime.
  • pythonHome
    • The path to the python home directory.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler(@"C:\tmp\test.dll", @"C:\python\");

Instance Methods

void RunFromString(string code)

This method runs a string of Python code.

Parameters:

  • code
    • The Python string to execute.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

pythonHandler.RunFromString("import sys; sysversion = sys.version");
void RunFromString(string code, Dictionary<string, object> variables)

This method runs a string of Python code.

Parameters:

  • code
    • The Python string to execute.
  • variables
    • Dictionary containing the key/values of variables to set.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

var variables = new Dictionary<string, object>();
variables.Add("test_var", "test_var_val");

pythonHandler.RunFromString("import sys; sysversion = sys.version; print('test_var')", variables);
TResult RunFromString<TResult>(string code, string returnVariable)

This method runs a string of Python code.

Parameters:

  • code
    • The Python string to execute.
  • returnVariable
    • The variable to read from the scope.

Returns:

  • The value of the returnVariable from the scope.

Exceptions:

  • KeyNotFoundException
    • The returnVariable was not found.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

var retVal = pythonHandler.RunFromString("import sys; sysversion = sys.version", "sysversion");
TResult RunFromString<TResult>(string code, string returnVariable, Dictionary<string, object> variables)

This method runs a string of Python code.

Parameters:

  • code
    • The Python string to execute.
  • returnVariable
    • The variable to read from the scope.
  • variables
    • Dictionary containing the key/values of variables to set.

Returns:

  • The value of the returnVariable from the scope.

Exceptions:

  • KeyNotFoundException
    • The returnVariable was not found.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

var variables = new Dictionary<string, object>();
variables.Add("test_var", "test_var_val");

var retVal = pythonHandler.RunFromString("import sys; sysversion = sys.version", "sysversion", variables);
void RunFromFile(string scriptFile)

This method runs a Python script.

Parameters:

  • scriptFile
    • he path to the Python script to execute.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

pythonHandler.RunFromFile(@"C:\tmp\test.py");
void RunFromFile(string scriptFile, Dictionary<string, object> variables)

This method runs a Python script.

Parameters:

  • scriptFile
    • he path to the Python script to execute.
  • variables
    • Dictionary containing the key/values of variables to set.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

var variables = new Dictionary<string, object>();
variables.Add("test_var", "test_var_val");

pythonHandler.RunFromFile(@"C:\tmp\test.py", variables);
TResult RunFromFile<TResult>(string scriptFile, string returnVariable)

This method runs a Python script.

Parameters:

  • scriptFile
    • he path to the Python script to execute.
  • returnVariable
    • The variable to read from the scope.

Returns:

  • The value of the returnVariable from the scope.

Exceptions:

  • KeyNotFoundException
    • The returnVariable was not found.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

pythonHandler.RunFromFile(@"C:\tmp\test.py", "sysversion");
TResult RunFromFile<TResult>(string scriptFile, string returnVariable, Dictionary<string, object> variables)

This method runs a Python script.

Parameters:

  • scriptFile
    • he path to the Python script to execute.
  • returnVariable
    • The variable to read from the scope.
  • variables
    • Dictionary containing the key/values of variables to set.

Returns:

  • The value of the returnVariable from the scope.

Exceptions:

  • KeyNotFoundException
    • The returnVariable was not found.

Examples:

var pythonHandler = new Ekeel.Interop.Python.Handler();

var variables = new Dictionary<string, object>();
variables.Add("test_var", "test_var_val");

pythonHandler.RunFromFile(@"C:\tmp\test.py", "sysversion", variables);
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 275 1/12/2023
1.0.0 249 1/10/2023