❔ 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
Chiyoko_S
Chiyoko_S2y ago
There's a thing called 'IronPython' which runs python in .NET but I think it only supports python 2
Will Pittenger
Will PittengerOP2y ago
That might or might not be a solution. Though a more recent Python might be needed. The project is yt-dlp.
Will Pittenger
Will PittengerOP2y ago
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
Will Pittenger
Will PittengerOP2y ago
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
Will Pittenger
Will PittengerOP2y ago
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...
Will Pittenger
Will PittengerOP2y ago
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.
Monsieur Wholesome
yt-dlp has a binary release, so why do you bother with python?
Will Pittenger
Will PittengerOP2y ago
Because I need some .NET types?
Monsieur Wholesome
So you want to use it as a library/api, not as a cli tool I see
Will Pittenger
Will PittengerOP2y ago
I'm doing a lot of processing in PowerShell. But would prefer C#.
Monsieur Wholesome
Is my conclusion right?
Will Pittenger
Will PittengerOP2y ago
Yes.
Monsieur Wholesome
pain
Will Pittenger
Will PittengerOP2y ago
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.
Monsieur Wholesome
I mean Doesnt the numpy example showcase wrapping "an entire library"?
Will Pittenger
Will PittengerOP2y ago
Numpy?
Monsieur Wholesome
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...
Will Pittenger
Will PittengerOP2y ago
Ah. I see what you're talking about.
Monsieur Wholesome
I hate python for its incompatibility of minor version updates...
Will Pittenger
Will PittengerOP2y ago
@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.
Monsieur Wholesome
I wanna ask again Why not wrap the yt-dlp binary and use it as cli tool <:DFrido_Hmm:704598915080781855>
Will Pittenger
Will PittengerOP2y ago
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.
Monsieur Wholesome
Sounds like you want seamless python common language infrastructure integration 😆
Sh1be
Sh1be2y ago
That sadly wont work But porting yt-dlp to c# does sound interesting Though it will be a huge pain maintaining it
Will Pittenger
Will PittengerOP2y ago
Not porting. Wrapping.
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server