ts2py
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

ts2py

A library to create interfaces from TypeScript to Python3

Installation

npm i ts2py

Usage

// Import factory function
import { makePythonInterface } from "ts2py";

// Create the interface
const {call, cleanup} = makePythonInterface({
    // Supply an array of custom function definitions, note the argument (*)
    processFunctions: [
        `process_func = lambda line: 'Hello at ' + line`
    ]
});

// Use the interface
async function main() {
    for(let i = 0; i < 100; ++i) {
        // Call your function from the interface: 
        // - process_func is the name of the function inside Python3 script
        // - new Date().toISOString() will be passd as `line` to the Python function
        // - as for now, arguments must be JSON.stringify()'able!
        const result = await call('process_func', new Date().toISOString());

        // Use the results
        console.log(i, result);
    }
}

// Do not forget to cleanup to not leave your node process stuck at exit
main().then(cleanup);

Readme

Keywords

Package Sidebar

Install

npm i ts2py

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

5.96 kB

Total Files

6

Last publish

Collaborators

  • kormanowsky