py-em-node
v1.0.2
Published
py-em-node is a Node.js package designed to facilitate the execution and management of Python scripts within a Node.js environment.
Downloads
11
Readme
py-em-node
Introduction
py-em-node
is a Node.js package designed to facilitate the execution and management of Python scripts within a Node.js environment. It provides functions to install Python, read configuration files, and execute Python scripts seamlessly.
Installation
You can install py-em-node
via npm, yarn or pnpm:
npm install py-em-node
OR
pnpm add py-em-node
OR
yarn add py-em-node
Usage
Package.json OR Command-Line Interface (CLI)
py-em-node
offers a command-line interface (CLI) or package.json for executing scripts directly from the terminal.
Example Usage
For this: Follow the Configuration Options as well
py-em-node start
OR
"scripts": {
"start": "py-em-node start"
},
npm run start
OR
pnpm start
OR
yarn start
This command will execute the Python script specified as the entry point in the configuration file.
Check out this video for quick sample usage:
Configuration
py-em-node
supports configuration through a JSON file named python.config.json
. TSON file python.config.tson
will be removed in the next upcoming version.
Place this file in the root directory of your project.
Configuration Options
entryPoint
: Specifies the entry point Python file (default:app.py
).usePythonThree
: Specifies the use of python3 if installed on system
Example Configuration File (python.config.json)
{
"entryPoint": "main.py",
}
If using python3, and/or already installed
{
"entryPoint": "main.py",
"usePythonThree": true
}
API Reference
executeScript(script: string): Promise
Executes the specified Python script based on the provided script name.
script
: Name of the script to execute.
readConfig(): Config
Reads the configuration from the python.config.json
file and returns the configuration object.
executePythonScript(scriptPath: string, args: string[]): void
Executes the Python script located at the specified path with the provided arguments.
scriptPath
: Path to the Python script.args
: Array of arguments to pass to the Python script.
License
This package is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
- This package was inspired by the need to seamlessly integrate Python scripts into Node.js applications.
Note: Make sure to have Python installed on your system before using this package.
Credits
🎯 The following features are planned for future support
- Allow user to enter the requirement.txt, and let this handle the installation.
- Add support for command support that execute a script or starts a project.
- More to be added.