# Run CPython in a zero touch node

**URL:** <https://forum.dynamobim.com/t/run-cpython-in-a-zero-touch-node/93167>\
**Category:** Packages\
**Tags:** zerotouch, python, c\
**Created:** [August 24, 2023, 2:33pm UTC](https://forum.dynamobim.com/t/run-cpython-in-a-zero-touch-node/93167 "2023-08-24T14:33:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andre.abotnes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andre.abotnes/32/42003_2.png) [@andre.abotnes](https://forum.dynamobim.com/u/andre.abotnes)\
**Post date:** [August 24, 2023, 2:33pm UTC](https://forum.dynamobim.com/t/run-cpython-in-a-zero-touch-node/93167/1 "2023-08-24T14:33:42Z")

</div>

Hi

I am looking into upgrading my package to zero touch nodes, and I found an example of executing an IronPython script from string in C# using the IronPython.Hosting namespace.  
[https://developer.dynamobim.org/03-Development-Options/3-3-python-scripts-in-csharp.html](https://developer.dynamobim.org/03-Development-Options/3-3-python-scripts-in-csharp.html)

Now that we are using CPython I tried finding an example for the same solution, but I could not find a good example that references CPython use. I would like to run a pythonscript from string, and return some object or value from the python execution.

Does anyone have any experience with this?

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [August 24, 2023, 3:09pm UTC](https://forum.dynamobim.com/t/run-cpython-in-a-zero-touch-node/93167/2 "2023-08-24T15:09:54Z")

</div>

you can see how Dynamo does it here:

> <https://github.com/DynamoDS/Dynamo/blob/master/src/Libraries/DSCPython/CPythonEvaluator.cs>

curious why you want to do this?

---

<div class="post-metadata">

**Author:** ![andre.abotnes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andre.abotnes/32/42003_2.png) [@andre.abotnes](https://forum.dynamobim.com/u/andre.abotnes)\
**Post date:** [August 24, 2023, 3:53pm UTC](https://forum.dynamobim.com/t/run-cpython-in-a-zero-touch-node/93167/3 "2023-08-24T15:53:31Z")

</div>

Excellent, thank you so much for that great example 🙂  
The main reason is curiosity, but I would also like to play with the idea of building a python interpreter into my C# addin for Revit to make users able to expand on my functionality.

I.E. I have a filtering system in place for some of my addin tasks, and I would love it if users could append small python scripts on top of my C# basic filter GUI for more advanced cases.

Could this be used outside of the Dynamo environment as well, or does it require Dynamo to be running?

---

<div class="post-metadata">

**Author:** ![RMohareb](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rmohareb/32/120534_2.png) [@RMohareb](https://forum.dynamobim.com/u/RMohareb)\
**Post date:** [August 25, 2023, 11:27am UTC](https://forum.dynamobim.com/t/run-cpython-in-a-zero-touch-node/93167/4 "2023-08-25T11:27:36Z")

</div>

@andre.abotnes @Michael_Kirschner2  
can You give me simple example how we can call Cpython from c#  
I try this code but the out is non

```auto
using System;
using Python.Runtime;

namespace PythonDotNetExample
{
    public class pythontest
    {
        public static string rrr()
        {
            // Initialize Python engine
            PythonEngine.Initialize();

            string result;

            using (Py.GIL()) // Acquire the Python Global Interpreter Lock (GIL)
            {
                // Run the Python code
                dynamic output = PythonEngine.RunString(@"# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
C=2 + 3

OUT=C
");

                // Convert the Python output to a string
                result = output?.ToString();
            }

            // Finalize Python engine
            PythonEngine.Shutdown();

            return result;
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [August 25, 2023, 11:00pm UTC](https://forum.dynamobim.com/t/run-cpython-in-a-zero-touch-node/93167/5 "2023-08-25T23:00:07Z")

</div>

I think the pythonNet readme will explain using pythonNet better than I ever could 😉

> **[GitHub - pythonnet/pythonnet: Python for .NET is a package that gives Python...](https://github.com/pythonnet/pythonnet)**
>
> Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET develo...
