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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

16 Commits

Repository files navigation

Node Python Runner

Dependency Status

Supported by:

CarmaCarma IOSCarma 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

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

Inline Script Using python3

varPython=require("python-runner");Python.exec(["print(line1)","print(line2)"],{/// set the python binary. Its 'python' by defaultbin: "python3",/// python variablesvars: {"line1": "Carma Carpooling","line2": "Get there together"},/// python environment variablesenv: {/// set the env for this executionPYTHONPATH: "..."}}).then(function(data){console.log(data);}).catch(function(err){console.log("Error",err);});

Script File

varPython=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

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages