Coder Social home page Coder Social logo

shreyasy2k / python-spawn Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 364 KB

NPM Package for easiest way to execute python scripts from nodejs

Home Page: https://www.npmjs.com/package/python-spawn

License: MIT License

JavaScript 1.20% TypeScript 98.80%
child-process nodejs-python npm npm-package python-shell typescript

python-spawn's Introduction

python-spawn

python-spawn Logo

`python-spawn` is an npm package designed to bridge the gap between Node.js and Python, allowing Node.js applications to execute Python scripts seamlessly. This package simplifies the integration process by providing an easy-to-use interface for running Python code, functions, and scripts directly from Node.js.

Features

  • Automatic Python Command Detection: Determines the available Python command (python or python3) on the system.
  • Script Execution: Enables the execution of entire Python scripts or specific functions within scripts, with argument passing capability.
  • Asynchronous Support: Executes Python scripts asynchronously, returning results via Promises for better integration with modern JavaScript code.
  • Error Handling: Provides comprehensive error messages to aid in debugging.
  • Temporary Script Wrapping: Generates a temporary wrapper script for executing specific Python functions, ensuring clean execution and removal post-execution.

Installation

Install python-spawn using npm:

npm install python-spawn

Usage

Basic Usage

const { PythonExecutor } = require("python-spawn");

// Creating an Instance
const executor = new PythonExecutor();

// Executing a Python Script
executor
  .executeScript("/path/to/your/script.py")
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

// Executing a Python Function withing a Script
executor
  .executeScript("/path/to/your/script.py", "function_name", ["arg1", "arg2"])
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

Contributing

Contributions are welcome! Please refer to the Contributing Guidelines for detailed information.

License

This project is licensed under the MIT License.

python-spawn's People

Contributors

shreyasy2k avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.