PyCS

Embedded Python 3.13 interop engine that extracts an embedded Python environment, installs pip, manages packages, and executes Python scripts from C#.

Constructors

C#
PyCS py = new PyCS(); // Show console log output
PyCS pyQuiet = new PyCS(false); // Hide console output

Methods

void InstallPip()

Installs pip into the embedded Python directory structure if not present.

void Pip(string[] args) / PipUpgrade(string[] args) / PipLocal(string[] args)

Executes pip install operations (remote, upgrade, or offline wheel directory installation).

void Run(string script) / RunFile(string filePath)

Executes a Python code block or script file and outputs results to the console.

string GetOutput(string script) / GetFileOutput(string filePath)

Executes Python code or file script and returns standard output/error as a string.

void Stop()

Gracefully terminates or kills the currently executing Python process.

Usage Example

C#
PyCS py = new PyCS();
py.InstallPip();
py.Pip(new string[] { "requests" });

string result = py.GetOutput("import requests\nprint(requests.get('https://api.github.com').status_code)");