Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/obaydmerz/py3

🚀 A versatile Node.js library for seamless interaction with Python. Execute Python commands effortlessly and manage Python sessions with ease! ( No Dependencies )
https://github.com/obaydmerz/py3

api blender child-process cross-platform error-handling fast ipc linux no-dependencies node nodejs process py py3 python python3 shell windows

Last synced: 14 days ago
JSON representation

🚀 A versatile Node.js library for seamless interaction with Python. Execute Python commands effortlessly and manage Python sessions with ease! ( No Dependencies )

Awesome Lists containing this project

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)**

```bash
npm install obaydmerz/py3
```

**From npm (For Stable Releases)**

```bash
npm install py3
```

## Usage

**Interesting Example**

```javascript
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**

```javascript
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](https://hecto.gitbook.io/py3).