❔ Wrapping Python code in C# .NET classes
I'm working with a project written in Python. Is there a way to take their calls and wrap them in .NET classes written in C#?
26 Replies
There's a thing called 'IronPython' which runs python in .NET but I think it only supports python 2
That might or might not be a solution. Though a more recent Python might be needed. The project is yt-dlp.
GitHub
yt-dlp/README.md at master · yt-dlp/yt-dlp
A youtube-dl fork with additional features and fixes - yt-dlp/README.md at master · yt-dlp/yt-dlp
GitHub
yt-dlp/README.md at master · yt-dlp/yt-dlp
A youtube-dl fork with additional features and fixes - yt-dlp/README.md at master · yt-dlp/yt-dlp
From https://github.com/IronLanguages/ironpython3/releases/tag/v3.4.0
The baseline for IronPython 3.4 is Python 3.4, although it also includes some syntax and features from newer Python versions, most notably f-string support (from 3.6).
GitHub
Release IronPython 3.4.0 · IronLanguages/ironpython3
On behalf of the IronPython team, I'm very happy to announce the release of IronPython 3.4.0. The runtime targets are .NET Framework 4.6.2, .NET Core 3.1 and .NET 6. The baseline for IronPython...
Sigh. 😦 https://ironpython.net/documentation/dotnet/dotnet.html#id85 lists a website for the documentation on how to embed Python code into .NET classes. But it's on a domain,
compilerlab.members.winisp.net
, that's dead.yt-dlp has a binary release, so why do you bother with python?
Because I need some .NET types?
So you want to use it as a library/api, not as a cli tool
I see
I'm doing a lot of processing in PowerShell.
But would prefer C#.
Is my conclusion right?
Yes.
pain
Python.NET's demo on wrapping Python in .NET is bare minimal. It shows the Python code as a string. I'd have an entire library.
And yt-dlp needs Python 3.7.
I mean
Doesnt the numpy example showcase wrapping "an entire library"?
Numpy?
GitHub
GitHub - pythonnet/pythonnet: Python for .NET is a package that giv...
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...
Ah. I see what you're talking about.
I hate python for its incompatibility of minor version updates...
@chatgpt plus user: Any suggestions on how I'd import their code? Ideally, it'd be part of one of my assemblies.
But I don't want to constantly copy their code. Something like a NuGet package would help. While there are some youtube-dl NuGet packages out there, documentation is limited as is support. Plus, yt-dlp does a LOT the original doesn't.
I wanna ask again
Why not wrap the yt-dlp binary and use it as cli tool <:DFrido_Hmm:704598915080781855>
It's a pain converting between text and objects. Plus, things like cookies need to be constantly reloaded.
@chatgpt plus user: I'd also like to pass delegates as hooks.
Sounds like you want seamless python common language infrastructure integration 😆
That sadly wont work
But porting yt-dlp to c# does sound interesting
Though it will be a huge pain maintaining it
Not porting. Wrapping.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.