Use Python for .NET for Channel Development?

Is it possible to use Python for .NET (http://pythonnet.sourceforge.net/) to integrate .NET assemblies for use in a Plex channel?

 

I'm new to Plex channel development, and new to Python.  I've got some ideas for Plex channels that would be well served by leveraging the .NET framework.  It'd be nice to know at the outset if there are really good reasons that it would be difficult to impossible to accomplish.  Is there any reason that the version of the Python runtime running inside the Plex server wouldn't allow a library like Python for .NET to run?

I would start by finding out, how that would work on anything else than a Windows based PMS.

(Read.....Go wide, and not the blue way, cuz it leads into darkness)

And would hate to see you develop something beautiful, that can't be used on a NAS, a Mac og a Linux based PMS

In one scenario I'm looking at I'm hoping to interface with the Windows Media Center database.  Possibly to pull in metadata, or maybe eventually to do direct streaming. In that case, it would explicitly be a platform specific plugin, no doubt.  And .NET is probably the best way forward for that purpose.

Of course, the Mono project has bridged the gap such that the .NET CLR can target all sorts of environments, so if I can get Python to call out to a CLR assembly in the Plex context, there's no reason I know of that it couldn't do so on a Mac or Linux machine as well.  In fact, the Python for .NET readme page explicitly mentions that initial testing shows that it works on Linux w/ Mono.

In one scenario I'm looking at I'm hoping to interface with the Windows Media Center database.  Possibly to pull in metadata, or maybe eventually to do direct streaming. In that case, it would explicitly be a platform specific plugin, no doubt.  And .NET is probably the best way forward for that purpose.

Of course, the Mono project has bridged the gap such that the .NET CLR can target all sorts of environments, so if I can get Python to call out to a CLR assembly in the Plex context, there's no reason I know of that it couldn't do so on a Mac or Linux machine as well.  In fact, the Python for .NET readme page explicitly mentions that initial testing shows that it works on Linux w/ Mono.

True, but if you release such a beast, you'll be busy for the rest of your life trying to help out people on other platforms than Windows explaining to them howto install Mono.

Also know, that a channel runs isolated within Plex, and as such, can't contact Mono, AFAIK, so you'll need to embed that for all the different platforms

(And not even sure if that's legal)

/T

True, but if you release such a beast, you'll be busy for the rest of your life trying to help out people on other platforms than Windows explaining to them howto install Mono.

Also know, that a channel runs isolated within Plex, and as such, can't contact Mono, AFAIK, so you'll need to embed that for all the different platforms

(And not even sure if that's legal)

/T

Good points, I'm sure, if/when I should ever look toward releasing such a thing.  

Today I'm just doing some initial probing around feasibility.  Do you have any ideas about that initial question, whether the Python runtime inside Plex would allow for running CLR code through Python for .NET (without regard for whether such a thing is "correct" in any broader sense)?

Good points, I'm sure, if/when I should ever look toward releasing such a thing.  

Today I'm just doing some initial probing around feasibility.  Do you have any ideas about that initial question, whether the Python runtime inside Plex would allow for running CLR code through Python for .NET (without regard for whether such a thing is "correct" in any broader sense)?

No idea, since never tried it......But guess it could be included....but only time (yours) will tell  :D

/T

OK, so I'm endeavoring to spend a little time (per the above suggestion) digging in to see if I can get the Python runtime in Plex to work with Python for .NET.  

I worked through a few issues with getting the latest release of Python for .NET working with Python at all (had to pull down the code and rebuild it).  I packed up my compiled assemblies and loaded them into the Code directory with my plugin.  These files are: clr.pyd (the primary loading point through which Python loads the .NET CLR), and Python.Runtime.dll (a CLR assembly for interfacing with Python).  

However, the import line in my __init__.py file is failing.  I'm having no issues otherwise with executing the import clr against Python 2.7 outside of the Plex plugin.  And I'm having no issues with importing other *.py files into my init script.  Are there restrictions against using ".pyd" assemblies inside the Plex plugin sandbox?  There's no big gnarly error thrown saying something is invalid about the pyd file, which I might have expected.  It just appears that the runtime doesn't see the file at all: No module named clr

Here's the relevant section from the plugin log:

2014-07-07 01:32:22,253 (7e8) :  CRITICAL (core:572) - Exception starting plug-in (most recent call last):
  File "C:\Users\Media\AppData\Local\Plex Media Server\Plug-ins\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\core.py", line 606, in start
    self.sandbox.execute(self.init_code)
  File "C:\Users\Media\AppData\Local\Plex Media Server\Plug-ins\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\code\sandbox.py", line 256, in execute
    exec(code) in self.environment
  File "C:\Users\Media\AppData\Local\Plex Media Server\Plug-ins\JasonsAwesome.bundle\Contents\Code\__init__.py", line 2, in 
    import clr
  File "C:\Users\Media\AppData\Local\Plex Media Server\Plug-ins\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\code\sandbox.py", line 345, in __import__
    raise e
ImportError: No module named clr

I also tried putting the Python for .NET assemblies into the ...\Versions\2\Python\Framework and ...\Versions\2\Python\Framework\code directories to see if it would find them there, but still no joy.  What might I be missing?

So, in answer to my earlier question: Yes, Python for .NET will run inside the Plex plugin engine.

In answer to my most recent question about why the clr.pyd assembly wasn't loading, it appears that I needed to have the PlexPluginCodePolicy key set with the Elevated value in my Info.plist file:

PlexPluginCodePolicy
Elevated

Once I got that in place, the clr.pyd file loaded fine, and I am able to load and utilize .NET CLR types in my plugin (only tried on a Windows server so far).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.