# VL.PythonNet?

**URL:** <http://forum.vvvv.org/t/vl-pythonnet/20037>\
**Category:** wip\
**Tags:** vl\
**Created:** [December 7, 2021, 12:46pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037 "2021-12-07T12:46:39Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeos](http://forum.vvvv.org/user_avatar/forum.vvvv.org/zeos/32/21518_2.png) [@zeos](http://forum.vvvv.org/u/zeos)\
**Post date:** [December 7, 2021, 12:46pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/1 "2021-12-07T12:46:39Z")

</div>

hi vvvvolks,

I was working with Python more extensively in the last years and really like the language and its rich ecosystem of libraries. Recently, I stumbled upon this fantastic .NET library [[http://pythonnet.github.io](http://pythonnet.github.io)([http://pythonnet.github.io](http://pythonnet.github.io))] offering a very tight coupling between the Python interpreter and the .NET clr. Looks like a good opportunity to introduced a Python region/editor(extension)/class into VL, so one can embed python code within a patch. What do you think? How should one approach this? I did some simple experiments with Visual Studio and C# and the interoperability layer works like a charm. There are also some examples of passing parameters to the Python script, getting results, multithreading handling, etc… any thoughts?

cheers

---

<div class="post-metadata">

**Author:** ![ravazquez](http://forum.vvvv.org/user_avatar/forum.vvvv.org/ravazquez/32/217_2.png) [@ravazquez](http://forum.vvvv.org/u/ravazquez)\
**Post date:** [December 9, 2021, 10:13am UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/2 "2021-12-09T10:13:42Z")

</div>

> [@zeos](#):
>
> ght coupling between the Python interpreter and the .NET clr. Looks like a good opportunity to introduced a Python region/edi

This could be huge, specially for ML and CV stuff.

---

<div class="post-metadata">

**Author:** ![Elias](http://forum.vvvv.org/letter_avatar_proxy/v2/letter/e/999999/32.png) [@Elias](http://forum.vvvv.org/u/Elias)\
**Post date:** [December 9, 2021, 11:15am UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/3 "2021-12-09T11:15:17Z")

</div>

Interesting. How about approaching it like we did with shaders in Stride using VL’s node factories? I’m thinking one could have a subfolder called python containing python scripts whose interior gets made available as nodes - this assumes you can reflect over those scripts? Anything like that in there?

---

<div class="post-metadata">

**Author:** ![zeos](http://forum.vvvv.org/user_avatar/forum.vvvv.org/zeos/32/21518_2.png) [@zeos](http://forum.vvvv.org/u/zeos)\
**Post date:** [December 9, 2021, 12:06pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/4 "2021-12-09T12:06:31Z")

</div>

Yes, the implications of integrating Python3 are huge. I have a proof-of-concept that works, using an intermediate c# DLL, could not manage to make it work with just importing PythonNET.dll assembly and using pure VL. However, I would like to have the results from a PythonScript execution as native pins with the correct datatypes, which is handled gracefully by the PythonNet interoperability layer.

---

<div class="post-metadata">

**Author:** ![Elias](http://forum.vvvv.org/letter_avatar_proxy/v2/letter/e/999999/32.png) [@Elias](http://forum.vvvv.org/u/Elias)\
**Post date:** [December 9, 2021, 12:19pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/5 "2021-12-09T12:19:03Z")

</div>

Do you have some reflection example code already?

---

<div class="post-metadata">

**Author:** ![zeos](http://forum.vvvv.org/user_avatar/forum.vvvv.org/zeos/32/21518_2.png) [@zeos](http://forum.vvvv.org/u/zeos)\
**Post date:** [December 9, 2021, 12:19pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/6 "2021-12-09T12:19:04Z")

</div>

![pythonnet-test](http://forum.vvvv.org/uploads/default/original/2X/c/cda202083614f2fb70f7d5fed9a7103d117b8f81.jpeg)

a very crude test… still thinking how to approach the multi-threading…PythonNet offers some mechanisms

---

<div class="post-metadata">

**Author:** ![zeos](http://forum.vvvv.org/user_avatar/forum.vvvv.org/zeos/32/21518_2.png) [@zeos](http://forum.vvvv.org/u/zeos)\
**Post date:** [December 9, 2021, 12:23pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/7 "2021-12-09T12:23:43Z")

</div>

@Elias: No, I have’t made any reflection tests now. Can you point me to some digestible example code for using VL’s node factories?

---

<div class="post-metadata">

**Author:** ![Hadasi](http://forum.vvvv.org/letter_avatar_proxy/v2/letter/h/999999/32.png) [@Hadasi](http://forum.vvvv.org/u/Hadasi)\
**Post date:** [December 9, 2021, 12:58pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/8 "2021-12-09T12:58:53Z")

</div>

IIRC pythonNet objects are ‘dynamic’ types that need to convert to specific c# types. This was an issue a few years back that made using it in vl a little complicated, so the key step might be casting cleverly in vl by somehow checking the script. Because objects aren’t strongly typed in python this can be a little tricky.

Another way to look at it to think of wrapping particular python projects in c# and importing them to vl, a bit like [tensorflow.net](https://github.com/SciSharp/TensorFlow.NET), though that’s quite an extreme case. Ideally, we have a minimal amount of c#

---

<div class="post-metadata">

**Author:** ![Elias](http://forum.vvvv.org/letter_avatar_proxy/v2/letter/e/999999/32.png) [@Elias](http://forum.vvvv.org/u/Elias)\
**Post date:** [December 9, 2021, 12:59pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/9 "2021-12-09T12:59:10Z")

</div>

Sadly we only have examples yet ([Node Factories | vvvv gamma documentation](https://thegraybook.vvvv.org/reference/extending/node-factories.html))

And of course [VL.Stride](https://github.com/vvvv/VL.Stride/blob/preview/2021.4/packages/VL.Stride.Runtime/src/Rendering/Effects/EffectShaderNodes.cs), but probably a little hard to begin with. So take that one maybe for later when it’s about details like auto-reloading or exporting applications.

The steps on the C# side are:

- Add a VL specific assembly initializer which will be called by the compiler when the assembly gets referenced by any document
- In that intializer register your node factory
- Your node factory must implement `IVLNodeDescriptionFactory` - you can either implement that yourself or (like done in Stride) use an implementation we provide which makes heavy use of delegates and closures, so that’s up to you.
- That factory will be called back by our compiler when it looks up node references - you’ll need to spit out node descriptions which contains static information like name, category, pin names etc. - this is the stuff which will show up in the nodebrowser when your node factory is referenced (we come to that later)
- Once the factory is referenced by a document it will also get another callback with the path of that document, where it can spit out another factory specific to that path - that’s what I meant above with having a subfolder called `python`.
- The node description will later be called by the runtime to create the actual node - this is the next interface you’ll need to implement. There it’s finally about the real stuff.

The steps on the VL side are:

- Reference your assembly. Once referenced you should see another entry in the dependencies menu where you can reference your node factory. Once you do that your nodes should show up.
- In order to make it scale, and package it all up, you can build a full VL package and forward your node factory through the forwarding menu. Once the factory gets forwarded, any document referencing your nuget will also pick up any `python` subfolder beside it.

---

<div class="post-metadata">

**Author:** ![zeos](http://forum.vvvv.org/user_avatar/forum.vvvv.org/zeos/32/21518_2.png) [@zeos](http://forum.vvvv.org/u/zeos)\
**Post date:** [December 9, 2021, 1:04pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/10 "2021-12-09T13:04:58Z")

</div>

ooook, much to read. Thank you for the references and the clues!

I am currently making a simple c# app in VS that is loading arbitrary python class/script and is trying to get all necessary information for the reflection/node factory, such as classes, methods, parameters and functions, etc. If this works well, I see no reason why can not be done as you suggest. Thanks again!

---

<div class="post-metadata">

**Author:** ![Elias](http://forum.vvvv.org/letter_avatar_proxy/v2/letter/e/999999/32.png) [@Elias](http://forum.vvvv.org/u/Elias)\
**Post date:** [December 9, 2021, 1:09pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/11 "2021-12-09T13:09:12Z")

</div>

Seems like a good idea to prototype it in a little console app first. And what @Hadasi said, that indeed could be problematic, as all pins would by typed `dynamic`. So I guess we need some idea here - does python have something like attributes?

---

<div class="post-metadata">

**Author:** ![zeos](http://forum.vvvv.org/user_avatar/forum.vvvv.org/zeos/32/21518_2.png) [@zeos](http://forum.vvvv.org/u/zeos)\
**Post date:** [December 9, 2021, 1:12pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/12 "2021-12-09T13:12:18Z")

</div>

Yes, exactly! I am doing a little c# app to inspect a given Python script. Now I can successfully extract all functions and classes/methods, and now trying to get the respective parameters, possibly with DataTypes, since in C#/VL we need to make the pins of specific type, right? Dynamic type pins are not possible.

---

<div class="post-metadata">

**Author:** ![Elias](http://forum.vvvv.org/letter_avatar_proxy/v2/letter/e/999999/32.png) [@Elias](http://forum.vvvv.org/u/Elias)\
**Post date:** [December 9, 2021, 2:08pm UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/13 "2021-12-09T14:08:42Z")

</div>

Our type system has currently no idea about `dynamic`, the user couldn’t really connect anything. Of course this can be discussed and eventually added to our typing rules if need be.

---

<div class="post-metadata">

**Author:** ![nissidis](http://forum.vvvv.org/user_avatar/forum.vvvv.org/nissidis/32/7139_2.png) [@nissidis](http://forum.vvvv.org/u/nissidis)\
**Post date:** [January 6, 2022, 8:45am UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/14 "2022-01-06T08:45:46Z")

</div>

@zeos really interesting I tried in the past many different ways to make python shell to comply with vvvv (beta and gamma) nothing really worked as I would like to. My main problems where the definitions and the different “pickle” approaches. Although nowadays there are some tables and libs to make it happen.  
@Elias in Python there are “decorators” and “class Attributes” which are working quite similar to C# Attributes but can you elaborate a bit more, how attributes would be useful for a Node Factory approach ?

---

<div class="post-metadata">

**Author:** ![phitho](http://forum.vvvv.org/letter_avatar_proxy/v2/letter/p/999999/32.png) [@phitho](http://forum.vvvv.org/u/phitho)\
**Post date:** [May 20, 2023, 7:03am UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/15 "2023-05-20T07:03:20Z")

</div>

Hi, any updates on this? I would love a stateful python interpreter in vvvv. Even if it’s hacky and not fully working, I’d be happy to take a look.

---

<div class="post-metadata">

**Author:** ![tonfilm](http://forum.vvvv.org/user_avatar/forum.vvvv.org/tonfilm/32/406_2.png) [@tonfilm](http://forum.vvvv.org/u/tonfilm)\
**Post date:** [February 26, 2025, 11:39am UTC](http://forum.vvvv.org/t/vl-pythonnet/20037/16 "2025-02-26T11:39:10Z")

</div>

This exists now:

> [@VL.PythonNET and AI worflows like StreamDiffusion in vvvv gamma](https://forum.vvvv.org/t/vl-pythonnet-and-ai-worflows-like-streamdiffusion-in-vvvv-gamma/22596):
>
> Hello vvvv community, I’ve been working on integrating Python into vvvv to leverage the explosion of AI and GenAI projects out there. These mind-blowing Python-based GitHub repositories are popping up day by day. It’s about transforming these repositories from neat, standalone proofs of concept into interactive, usable components within the vvvv ecosystem. VL.PythonNET The heart of this development is embedding the Python runtime within a vvvv process, allowing for direct interaction with Pyth…
