Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
edge-iron-py
Advanced tools
edge-py
edge-py
only supports .NET Framework 4.x, edge-iron-py
supports dotnet 6 and higher.
NOTE This functionality requires IronPython 3.4 and has been tested on Windows only.
Install edge-js and edge-iron-py modules:
npm install edge-js
npm install edge-iron-py
var edge = require('edge-js');
var hello = edge.func('iron-py', function () {/*
def hello(input):
return "Python welcomes " + input
lambda x: hello(x)
*/});
hello('Node.js', function (error, result) {
if (error) throw error;
console.log(result);
});
Your Python script must evaluate to a lambda expression that accepts a single parameter. The parameter represents marshalled input from the Node.js code. The return value of the lambda expression is passed back as the result to Node.js code. The Python script can contain constructs (e.g. Python functions) that are used in the closure of the lambda expression. The instance of the script with associated state is created when edge.func
is called in Node.js. Each call to the function referes to that instance.
The simplest echo Python script you can embed in Node.js looks like this:
lambda x: x
To say hello, you can use something like this:
lambda: x: "Hello, " + x
To maintain a running sum of numbers:
current = 0
def add(x):
global current
current = current + x
return current
lambda x: add(x)
You can reference Python script stored in a *.py file instead of embedding Python code in a Node.js script.
In your hello.py file:
def hello(input):
return "Python welcomes " + input
lambda x: hello(x)
In your hello.js file:
var edge = require('edge-js');
var hello = edge.func('iron-py', 'hello.py');
hello('Node.js', function (error, result) {
if (error) throw error;
console.log(result);
});
In the examples above Python script was executing asynchronously on its own thread without blocking the singleton V8 thread on which the Node.js event loop runs. This means your Node.js application remains responsive while the Python code executes in the background.
If you know your Python code is non-blocking, or if you know what you are doing, you can tell Edge.js to execute Python code on the singleton V8 thread. This will improve performance for non-blocking Python scripts embedded in a Node.js application:
var edge = require('edge-js');
var hello = edge.func('iron-py', {
source: function () {/*
def hello(input):
return "Python welcomes " + input
lambda x: hello(x)
*/},
sync: true
});
console.log(hello('Node.js', true));
The sync: true
property in the call to edge.func
tells Edge.js to execute Python code on the V8 thread as opposed to creating a new thread to run Python script on. The true
parameter in the call to hello
requests that Edge.js does in fact call the hello
function synchronously, i.e. return the result as opposed to calling a callback function.
See Edge.Js on GitHub for more information.
FAQs
Edge-iron-py: run Python and node.js code in-process with edge.js
The npm package edge-iron-py receives a total of 1 weekly downloads. As such, edge-iron-py popularity was classified as not popular.
We found that edge-iron-py demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.