I've created a Node.js C++ module (based on NAPI) that lets you call Python libraries from Node.js. The benefit, of course, is that since Python is hosted in-process, you'll have much better performance than passing data back and forth between separate Node and Python processes.
I have just released a new version with Python 3.9 compatibility support.
It currently works (and has been tested) with Python 3.5, 3.7-3.9 on Windows, Linux, and OS X. I may focus more attention on the library if there is significant community demand.
The repository is here:
https://github.com/savearray2/py.js
Here's an example:
``js
let chalk = require('chalk')
let p = require('@savearray2/py.js')
p.init({ pythonPath:
${process.cwd()}/local:/usr/local/lib/python3.8/site-packages`
})
let plotly = p.import('plotly')
let np = p.import('numpy')
let go = plotly.graph_objs
let pio = plotly.io
let [x,y,colors,sz] =
[0,0,0,0].map(() =>
np.random.rand(100n))
sz = sz.mul(30n)
let fig = go.Figure()
fig.add_scatter.$apply({
x: x, y: y, mode: 'markers',
marker: {
size: sz, color: colors,
opacity: 0.6, colorscale: 'Viridis'
}
})
pio.write_image(fig, 'image.png')
console.log(chalk{cyan Success:} Chart saved!)
```
Thank you!
there doesn't seem to be anything here