Host interactive python REPL completely within C# .NET windows app

Nov 1, 2013 at 4:17 PM
I've searched this list (not exhaustively I'll admit) and have not found a definitive answer to the following:

I'd like to host an interactive python REPL completely within C# .NET windows app. That is, I want as much interactive capability, help comments, intellisense, debug, error statements, text coloring, etc. just as if I picked up the existing interactive python or ipython REPL console app and dropped it right into my windows app.

I realize I may not get all of those request items. But even a rich text box where I could type python commands, have them execute and see results directly within the hosted python window would be adequate.

Is there anything like this out there? I know I can create a text box, grab the text and run something like this on it: ScriptSource source = engine.CreateScriptSourceFromString(code,
SourceCodeKind.Statements); source.Execute(scope); But that seems a bit incomplete. Is there more interaction that I can get? Is there a sample project that exists like this? Not asking for free anything but some explicit pointers would be nice.

Thanks for any reply,
Nov 1, 2013 at 4:29 PM
Edited Nov 1, 2013 at 4:30 PM
We may be about the best sample project you'll find (see our ReplWindow project and the PythonTools\Repl folder), but we do reuse the Visual Studio editor to provide syntax highlighting. As far as I know, you can't embed that into a separate application - the closest you can do is embed your application inside VS (typically as an extension, using the Isolated shell if you want to freely redistribute the VS part of it). Otherwise, there are a number of free and/or open-source editors that could be modified to act as a REPL.

PythonReplEvaluator.cs and contain most of our Python-specific code, so you may find some inspiration here for communicating between a running Python process and your app.

All of our code is completely free to take and use however you like (in line with the derivative works section of our license - it's Apache 2.0, so not difficult to comply).
Nov 1, 2013 at 4:32 PM
For VS-less REPL, the biggest problem will be finding the editing component to provide all the necessary services like coloring and completion, on top of which the Python-specific logic can be implemented.
Nov 1, 2013 at 5:40 PM
Edited Nov 2, 2013 at 1:56 AM

So you're saying that in order to use your project one 'MUST' use VS? Or is there a way to simply use your PythonReplEvaluator as a base and forgo the VS capabilities?

And as far as the "number of free/os editors" - yeah, I've been looking for one that is fairly complete, but as of yet, have not found one that would get me juiced and jammin' fairly quickly. I know, I know, I haven't looked hard enough. But I have looked, for a while, but there so much noise, and old noise, out there about this topic...

Thanks for your quick replies though.


Nov 5, 2013 at 3:49 PM
The evaluator class itself is pretty closely tied to the ReplWindow extension we use, which is completely locked into Visual Studio. So you can't use the entire code directly.

However, there is a lot of BasePythonReplEvaluator that relates more to communicating with a hidden Python process (that is running, which may be useful to you, whether as code or as inspiration.
Nov 5, 2013 at 11:30 PM
Zooba, Thanks for your attention to this forum. Such focus always makes a difference.