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

pyfi-client

v1.0.4

Published

Make PyFi functionality available to a client 📼

Downloads

15

Readme

pyfi-client CircleCI License: MIT npm

Quickly make Python functions available to a javascript client when used along with PyFi

Usage

Pyfi-Client duplicates the functionality exposed to the server and makes it available to the client via Socket.io.

Setting up a server

Getting up and running is pretty simple. From your Node PyFi instance, attach a socket.io instance:

py._.attachClientSocketIO(io)

Here's a full example using express:

const express = require('express');
const PyFi = require('pyfi');

const app = require('express')();
const server = require('http').Server(app);
const io = require('socket.io')(server);

app.use(express.static('public'));


const py = PyFi({
    path: './python',
    imports: [{
      import: ['tell_me_the_time'],
      from: 'timing',
    }],
  });

py._.attachClientSocketIO(io);

// wait for PyFi to init
py._.onReady(() => {
  server.listen(3000, () => {
    console.log('listening on port 3000!');
  });
});

You can find the full working example here.

Connecting a Client

Once you have a server set up, it's quite straightforward to connect a client.

const PyFiClient = require('pyfi-client');
// or
import PyFiClient from 'pyfi-client';

const py = PyFiClient(http://localhost:3000)

py._.onReady(()=>{
  py.tell_me_the_time()
  .then(result => {
    console.log(result)
  })
  .catch(error => {
    // handle error
  })
})

PyFiClient automatically duplicates all of the Python functions imported on the server on the client.

Sending messages mid-execution

Just like in PyFi, PyfiClient supports receiving messages from Python while a function is running. That allows for, for example, streaming status back to a client while a long-running function is in progress.

It looks very similar to PyFi on Node: Python:

def my_function():
  # ... do something ...
  pyfi_message('my message')
  # ... do something else ...
  return 'done!'

Client:

py.my_function()
  .onMessage(data => {
    console.log(data)
    // 'my message'
  })
  .then(res => {
    console.log(res);
    // 'done'
  })

Reference

PyFiClient([address])

Returns a PyFiClient instance and initializes callables that match those available in the server instance of PyFi.

You may provide an address for the serer (i.e. http://localhost:3000), or if no server is provided, the client will connect to the host address. This matches the functionality of socket.io.

Methods

_.onReady(callback) Attach a callback function to call when the instance of PyFiClient is ready.

Contributing

We welcome issues and pull requests.

If you spot a bug, please provide as much context as possible – including your OS, which versions of Node and Python you're running on, how you're managing your Python environment, and anything else that could be relevant.

License

MIT License (c) 2018 - Present IDEO CoLab