Skip to content

Latest commit

 

History

History
79 lines (49 loc) · 2.44 KB

README.md

File metadata and controls

79 lines (49 loc) · 2.44 KB

Py3: Python Interaction library

Py3 is a versatile Node.js library designed to facilitate interaction with Python, seamlessly bridging the gap between the two languages.

Key Features

  • Pure JavaScript Implementation: Enjoy enhanced flexibility with a pure JavaScript implementation, eliminating the need for native files and streamlining the setup process.

  • Seamless Python Integration: Py3 allows you to effortlessly execute Python commands and scripts directly from your JavaScript or TypeScript code, enabling you to harness the full capabilities of Python within your application.

  • Robust Error Handling: With Py3, you benefit from robust error handling mechanisms, ensuring graceful error capture and handling to maintain application stability even during the execution of complex Python commands.

  • Asynchronous Execution: Execute Python commands asynchronously to prevent application unresponsiveness while awaiting script execution completion.

  • Detailed Results: Access comprehensive results of Python script executions, including standard output, standard error, and execution success status, facilitated through a convenient result object for easy data retrieval.

  • Comprehensive Documentation: Py3 comes with comprehensive TypeScript declaration files (.d.ts) and inline code comments, facilitating easy understanding and utilization of the module within your projects.

  • Cross-Platform Compatibility: Designed for cross-platform compatibility, Py3 ensures consistent Python integration across various operating systems.

Installation

From GitHub (For Latest Features)

npm install obaydmerz/py3

From npm (For Stable Releases)

npm install py3

Usage

Interesting Example

import { Py } from "py3";

// Create a Py instance
const py3 = new Py();

py3.on("print", (x) => {
  console.log("Printed", x);
});

py3.start().then(async () => {
  await py3.exec(`def hello(bar):
    print("Hello World!")
    return {'hello': 'world', 'foo': bar}`);

  const res = await py3.context.hello(19);

  console.log(res.foo);
});

Accessing globals

import { Py } from "py3";

const py3 = new Py();

(async () => {
  await py3.start();

  console.log(py3.context.__name__);
})();

Simple, isn't it?

API Documentation

For detailed API documentation, refer to the index.d.ts. For further information and advanced usage, explore the Py3 Wiki.