New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

python-js-executor

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

python-js-executor

Execute Python code and files from JavaScript with full import support

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
0
Created
Source

Python JS Executor

Execute Python code and files from JavaScript with full import support.

Installation

npm install python-js-executor

Requirements

  • Node.js >= 14.0.0
  • Python 3.x installed and accessible in PATH

Usage

const PythonRunner = require('python-js-executor');

const runner = new PythonRunner();

// Execute Python code directly
const code = `
import math
print(math.sqrt(16))
`;

runner.runCode(code)
  .then(output => console.log(output))
  .catch(err => console.error(err));

// Execute Python file
runner.runFile('./script.py', ['arg1', 'arg2'])
  .then(output => console.log(output))
  .catch(err => console.error(err));

API

PythonRunner

Constructor

const runner = new PythonRunner();

Methods

runCode(code: string, args?: string[]): Promise<string[]>

Execute Python code directly from a string.

  • code: Python code to execute
  • args: Optional array of arguments to pass to the Python code
  • Returns: Promise resolving to array of output lines
runFile(pythonFile: string, args?: string[]): Promise<string[]>

Execute a Python file.

  • pythonFile: Path to the Python file
  • args: Optional array of arguments to pass to the Python script
  • Returns: Promise resolving to array of output lines

License

MIT

Author

Abhinav Tiwari (PINAKA)

Keywords

python

FAQs

Package last updated on 02 Feb 2025

Did you know?

Socket

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.

Install

Related posts