I've written a Python program that I want to package and upload to the Python package index. After doing this, is there any way for me to import that Python package and use it in Node.js or ReactJS? I basically want to use the functions and classes in the Python package to get some information and show it in some frontend application.
Asked
Active
Viewed 245 times
0
-
not really but there are a few workarounds https://stackoverflow.com/questions/23450534/how-to-call-a-python-function-from-node-js – Serge Nov 16 '21 at 19:30
-
Oh I see. So you can pretty much only send back text with this method. Would it just be a better idea to store the output from the Python program into some database that the application could read from? – Nov 16 '21 at 19:33
-
What would you need to send back? You can [encode any data you need to text if need be](https://en.wikipedia.org/wiki/Base64) though it's likely your use case is better served with JSON. – AKX Nov 16 '21 at 19:35
-
1Ideally I'd want to get back some JSON files from the Python script. Are you saying I can encode the JSON and send it to node.js, and then decode it into a JSON file again? – Nov 16 '21 at 19:37
-
yes you can, also you have several different answers besides child_process – Serge Nov 16 '21 at 19:43
-
Ok sounds good, I'll see what I can do. Thanks for the help. – Nov 16 '21 at 19:52
1 Answers
0
I am not sure if there is any mode to access the packages directly, however, you sure can execute a python script from your Node.js backend by using the child_process
package.
Reference:

Iker
- 16
- 1
- 5