npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@d1vij/py-bridge

v1.6.4

Published

Simple Node.js library to call existing Python functions and get their return value in Node.js environment

Readme

PyBridge

PyBridge is a simple Node.js library for running Python functions without modifying your existing Python scripts.

It uses your existing python environment to run the scripts.

[!NOTE] The only Python dependency required is the requests module, which enables communication between the Python runtime and the ? > Node.js runtime. Although the Python runtime can automatically install this module if it is not found, it is strongly ? recommended to install it in advance to avoid delays or unexpected runtime issues.

Installation

  • Install the latest package from npm registry
npm install @d1vij/py-bridge

Usage

Running python functions

  • Before running any Python script, the Python runtime must be made aware of the correct environment in order to resolve dependent modules. This is achieved by setting the absolute path to your existing environment using the pythonPath.set() method:
import { pythonPath } from "@d1vij/py-bridge";

// For Unix-based environments
pythonPath.set("/home/foo/bar/.venv/bin/python");

// For Windows environments
pythonPath.set("C:\\foo\\bar\\.venv\\scripts\\python.exe");

This configuration only needs to be set once per runtime session.

  • The core API is the execute function which asynchronously runs a target function from a python module and returns a promise with execution results.
// Signature
export function execute<T>( // Type defaults to string if not passed, and has no runtime effect
  filepath: string,      // Absolute path to the Python module
  functionName: string,  // Name of the function to run (must exist in the module)
  kwargs: Object = {},   // Keyword arguments, passed as foo(**kwargs)
  port?: string          // Optional port for Node-Python runtimes communication. (random if not specified)
): Promise<ExecResults<T>>;

with ExecResults being defined as

export type ExecResults<T> = {
    success: boolean;   // whether the execution succeeded
    errorMsg?: string;  // exception raised (if any)
    payload?: T;   // return value of the Python function
};

Example

# ~/python-scripts/calc.py
def add(x: int, y: int) -> int:
    return x + y
// script.ts
import {execute, pythonPath} from "@d1vij/py-bridge";

pythonPath.set("/home/divij/coding/examples/add/.venv/bin/python");
async function main(){
    const results = await execute<number>("~/python-scripts/calc.py", "add", {
        x:10, //variables retain their datatype
        y:20
    })
    //returns payload as: 30 (int)
}
main().catch(console.log);

[!NOTE] More examples in the /examples/ folder

[!IMPORTANT] Although scripts can be executed without modifications, only JSON-serializable data can be returned as payloads. Returning non-serializable Python objects will raise an exception. To avoid this, wrap return values in a serializable form (e.g., str, list, or dict).

# for example
import numpy as np
def foo() -> np.Array:
    return np.arange(1,10) # this would raise exception in the json.dumps

def bar() -> str:
    return str(np.arange(1,10)) # this could be fixed by returning a json serializable object instead

def foo_wrapper() -> str:
    return str(foo()) # or else calling a wrapper instead of foo