Embedding Node.js in Python
NickName:Toaster Ask DateTime:2014-09-18T05:28:40

Embedding Node.js in Python

I am looking at the option of embedding node.js into python to add node.js functionality to my existing python code. I know that it can be done the other way around, as described in this post. However, I want to keep the as much of the existing Python project intact as possible, which means allowing Python to manage execution.

PyV8 does just about everything I want except provide a node.js-like environment that would allow me to use node.js modules in PyV8, so it seems like a good starting point.

Does node.js provide an external API similar to that of V8 such that one could modify PyV8 to wrap node.js? If not, is there a way to load the node.js environment into PyV8 so I can use node.js modules?

Thanks!

Copyright Notice:Content Author:「Toaster」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25900639/embedding-node-js-in-python

Answers
abarnert 2014-09-17T22:03:44

What you want to do is not supported. Unlike, say, the CPython interpreter, or even the V8 JavaScript interpreter, Node.js was not designed to be embedded, has no interface for doing so, and no serious plan to change that.\n\nI can't find any official documentation on that, but there are numerous threads like this one that give the relevant information.\n\nBut that doesn't mean it's impossible. The top layer of Node isn't that complicated, and really you'd just need to patch out a few parts of it to do different things. And, in fact, people have tried to do exactly that, in projects like tacnode. I don't know if any of them are ready for prime time or not, but it may be worth looking at them, especially if you're willing and able to contribute if they're incomplete.\n\nOf course that only gets you embedding in C or C++; you still need to embed in Python. But wrapping a C shared library so you can use it in Python (well, CPython and PyPy) is a long-solved problem; Python has had extension modules since almost the beginning, as well as ctypes and cffi if you don't want to write any C code. And there are third-party projects like Cython to let you write almost-Python code that directly calls your shared library as if it were native C, and compiles to a Python extension module.\n\nSo, it's almost certainly doable, but it's probably not going to be trivial, or packaged and ready to go out of the box.",


More about “Embedding Node.js in Python” related questions

Embedding Node.js in Python

I am looking at the option of embedding node.js into python to add node.js functionality to my existing python code. I know that it can be done the other way around, as described in this post. Howe...

Show Detail

Embedding python in an installer

The accepted answer to this question deploying python applications discusses "embedding Python" in your installer to deploy it as an Exe. I would like to take this approach to deploying a python app

Show Detail

Embedding Node.js into a C Application (for Pure Data)

I am looking into the feasibility of embedding Node.js into a C application. Pure Data is a graphical programming language which is written in C. I am looking to write a C extension for the program...

Show Detail

Embedding python error Import by filename is not supported

I'm trying to embed python in to my application and have got stuck pretty early on. I am embedding python into my C++ application and using the code found at this tutorial: http://docs.python.org/2/

Show Detail

Embedding specific Python

I am currently embedding Python3 into my C++ application. We also ships a defined version of Python3. Currently Py_Initialize finds the system python in /usr/lib/python3.5 (which we do not want). I

Show Detail

embedding python in tcsh

So as an example, I know that embedding python in bash as follows work: python -c "import os dict_name[\"var1\"]=1 dict_name[\"var2\"]=2 " However, when I do the same exact thing in tcsh, I

Show Detail

Embedding Python Design

There are lots of tutorials/instructions on how to embed python in an application, but nothing (that I've seen) on overall design for how the embedded interpreter should be used and interact with the

Show Detail

Embedding Python with C

I want to use an event based Python library in a C application. I use the offical C-API for embedding Python: http://docs.python.org/2/c-api/index.html#c-api-index It is no problem to call methods...

Show Detail

Virtual environments and embedding Python

I'm quite fond of Python's virtualenv, which facilitates maintenance of separate Python configurations. I'm considering embedding Python into a C++ application and was wondering how the embedded P...

Show Detail

Embedding Python: ImportError: No module named

I'm new to Python and trying to embedd it in my c++ application. For this i follow the official doc. But when i try to execute the program i get following output: ImportError: No module named 'mu...

Show Detail