JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q34054F
  • License GPL-3.0

🚀 A Node.js library enabling easy interaction with Python. Execute Python commands effortlessly and access Python sessions and context with ease!

Package Exports

  • py3
  • py3/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (py3) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.