@onehilltech/blueprint-python

4.76.5 • Public • Published

blueprint-python

Run Python scripts from a Blueprint application

Installation

npm install @onehilltech/blueprint-python --save

Getting Started

Running a Python script

You run a Python script by first injecting the python service into a Blueprint component, such as a controller, action, service, or policy. After injecting the service, call the run (args, options) method on the service. This is an asynchronous method. The return value is the standard output (i.e., stdout) of the script.

const { Action, Controller, service } = require ('@onehilltech/blueprint');

module.exports = Controller.extend ({
  __invoke () {
    return Action.extend ({
      /// Inject the Python service into the action.
      python: service (),
      
      async execute (req, res) {
        const result = await this.python.run (script);
        
        return res.status (200, { result } );
      }
    });
  }
});

Passing arguments to the Python script

You can pass arguments to the python script by passing an array as the first parameter of the run (args, options) method.

const { Action, Controller, service } = require ('@onehilltech/blueprint');

module.exports = Controller.extend ({
  __invoke () {
    return Action.extend ({
      /// Inject the Python service into the action.
      python: service (),
      
      async execute (req, res) {
        const result = await this.python.run ([script, arg1, arg2]);
        
        return res.status (200, { result } );
      }
    });
  }
});

Passing options to the execution process

The last parameter of run (args, options) are options for configuring the execution process that runs the Python script. The options supported are the same as the options from process.spawn.

Happy Coding!

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.76.51latest

Version History

VersionDownloads (Last 7 Days)Published
4.76.51
4.74.10
4.71.00
4.67.00
4.65.190
5.0.0-alpha.10
4.65.110
4.65.00
4.64.10
4.64.00

Package Sidebar

Install

npm i @onehilltech/blueprint-python

Weekly Downloads

1

Version

4.76.5

License

Apache-2.0

Unpacked Size

7.33 kB

Total Files

16

Last publish

Collaborators

  • onehilltech