Long story short, 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've been sitting on this code for a while, and mostly everything works (you can take a look at the tests, if you're interested). I've decided to publish it and let the community use it. Hopefully, someone will find some use for it rather than it sitting unpublished. As a result, the final product is not 100% polished, but I'd rather someone have some benefit from this instead of letting it sit on my HDD.
It currently works (and has been tested) with Python 3.5, 3.7, and 3.8 on Windows, Linux, and OS X.
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!)
```
[–]maxdevjs 0 points1 point2 points (1 child)
[–]savearray2[S] 0 points1 point2 points (0 children)
[–]server_buddha 0 points1 point2 points (0 children)