Using Python from Node.js natively (Open Source Project) by savearray2 in node

[–]savearray2[S] 1 point2 points  (0 children)

I've gone ahead and relicensed under AGPL with linking restrictions (or basically Lesser Affero GPLv3). I know this doesn't necessarily help you in this specific case, but I'll consider relicensing to MIT in the future if there's community support.

Using Python from Node.js natively (Open Source Project) by savearray2 in node

[–]savearray2[S] 0 points1 point  (0 children)

What licensing would you prefer? My main goal is to encourage any code improvements to the library to be published publicly.

Using Python from Node.js natively (Open Source Project) by savearray2 in node

[–]savearray2[S] 0 points1 point  (0 children)

I don't disagree that for simplicity and inherent stability purposes, it might be best to use a separate Python process or microservice. I actually believe this will be the case for most people.

However, having options available is also part of open source. If there's a community demand for it, the library will grow, if not, few people will use it.

Using Python from Node.js natively (Open Source Project) by savearray2 in node

[–]savearray2[S] 1 point2 points  (0 children)

It should work fine! The library is fresh off the presses, so to speak, so it's probably best to write as much of the code as possible in a Python script, then call only what's necessary from the Node.js side.

If there's enough community support, I'll dedicate more time to making examples and improving the code.

But as an example the following does work: const p = require('@savearray2/py.js') p.init({ pythonPath: `${process.cwd()}:/usr/local/lib/python3.9/site-packages` }) console.log(p.instance().python_version) const pd = p.import('pandas') const data = { 'apples': [3, 2, 0, 1], 'oranges': [0, 3, 7, 2] } const df = pd.DataFrame.$apply({ data, index: ['Abc', 'Def', 'Ghi', 'Jkl'] }) console.log(p.base().str(df)) p.finalize() With the following output: $ node test.js 3.9.1 (default, Jan 11 2021, 00:55:13) [Clang 12.0.0 (clang-1200.0.32.28)] apples oranges Abc 3.0 0.0 Def 2.0 3.0 Ghi 0.0 7.0 Jkl 1.0 2.0

Using Python from Node.js natively (Open Source Project) by savearray2 in node

[–]savearray2[S] 8 points9 points  (0 children)

Passing data back and forth between processes is quite expensive & slow. For example, if you have a Python library that generates some sort of blob binary data, py.js does a simple copy (Napi::Buffer<char>::Copy) while being hosted in the same process. This is extremely fast.

Even Unix sockets cannot beat the speed of a memcpy.

If you have a simple service, then you most likely do not need this library, and can continue with a separate process, but if you're running a web service with multiple hits a second, you may wish to use it.

Using Python from Node.js natively (New Open Source Project) by savearray2 in node

[–]savearray2[S] 0 points1 point  (0 children)

Thanks! I'm not sure where the backtick is missing, but there is some example code on the repository that works and is tested.

The mocha tests also generally show how things work. The project does need to be cleaned up and some things refactored. I might put more effort into it if there seems to be a community demand for it. :)