Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

teamcarma/node-python-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Python Runner

Supported by:

Carma Carma IOS Carma Android

A library that allows you to execute python code and get its output from nodejs. You can execute inline commands or script files.

This can be useful to bridge nodejs with python code. Each execution will create a python process.

Install

npm install python-runner -g

The only dependencies of this package are:

## Usage

The execution function will run send every command to the python stdin interpreter returning a Q promise. This will be resolved with the stdout of the python binary.

The python binary will be executed with the same environment variables as its parent process.

You can tweak the following options:

  • bin - The python binary to be used
  • env - Replace the environment variables for this python execution. Useful for PYTHONPATH, ...

Inline Script

var Python = requrie("python-runner");

Python.exec(
	"print('Carma Carpooling')" + "\n" + 
	"print('Get there together')" + "\n"
)
.then(function(data){
	console.log(data);
});

Inline Script Using python3

Python.exec( "print('Carma Carpooling')" + "\n" + "print('Get there together')" + "\n", { /// set the python binary. Its 'python' by default bin: "python3", env: { /// set the env for this execution PYTHONPATH: "..." } } ) .then(function(data){ console.log(data); }) .catch(function(err){ console.log("Error", err); });

Script File

var Python = requrie("python-runner");

Python.execScript( __dirname + "/example.py", { bin: "python3", args: [ "argument" ] } ) .then(function(data){ console.log(data); }) .catch(function(err){ console.log("Error", err); });

You can always take a look at the examples folder!

Authors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published