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

piston-api

v1.0.1

Published

TypeScript/Node.js client for Piston code execution engine API with WebSocket support

Readme

Piston API Client

A comprehensive TypeScript client for the Piston API with WebSocket support for interactive code execution.

Features

  • 🔥 Simple API: Execute code with one line
  • 🌐 Interactive Sessions: Real-time WebSocket communication
  • 📝 Input Support: Send input to running programs
  • 🛡️ Type Safety: Full TypeScript support with Zod validation
  • 📊 Event-Driven: Listen to session lifecycle events
  • 🚀 High-Level: Automatic session management

Installation

npm install
npm run build

Quick Start

Simple Code Execution

import { PistonClient } from "./src/managers/client";

const piston = new PistonClient({ baseUrl: "http://localhost:2000" });

// Execute Python code
const result = await piston.run({
  language: "python",
  version: "*",
  code: 'print("Hello, World!")',
});
console.log(result.run.stdout); // "Hello, World!"

// Execute with input
const result2 = await piston.run({
  language: "python",
  version: "*",
  code: "print(input())",
  stdin: "User Input",
});
console.log(result2.run.stdout); // "User Input"

Interactive Sessions

// Create interactive session
const sessionId = await piston.runInteractive(
  `
while True:
    expr = input("> ")
    if expr == 'quit':
        break
    print(f"= {eval(expr)}")
`,
  "python"
);

// Listen for output
piston.on("sessionOutput", (id, output) => {
  console.log("Output:", output);
});

// Send input
piston.sendInput(sessionId, "2 + 3\\n");
piston.sendInput(sessionId, "quit\\n");

// Cleanup
piston.destroySession(sessionId);

C++ with Input

// C++ calculator
const result = await piston.run({
  language: "cpp",
  version: "*",
  code: `
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cout << "Enter two numbers: ";
    cin >> a >> b;
    cout << "Sum: " << (a + b) << endl;
    return 0;
}`,
  stdin: "10\\n5\\n",
});

console.log(result.run.stdout); // "Enter two numbers: Sum: 15"

API Reference

PistonClient

Methods

  • run(request) - Execute code once
  • runInteractive(code, language) - Start interactive session
  • sendInput(sessionId, input) - Send input to session
  • destroySession(sessionId) - End session
  • getRuntimes(input?, force?) - Get available languages
  • installPackage(request) - Install specific package version
  • installRuntime(language) - Install latest version of a runtime
  • validateInstance() - Check if Piston is available

Events

  • sessionCreated - Session started
  • sessionReady - Session ready for input
  • sessionOutput - Session produced output
  • sessionCompleted - Session ended
  • sessionError - Session error occurred
  • sessionDestroyed - Session cleaned up

Supported Languages

The client supports all languages available in Piston:

  • Python (python, py)
  • JavaScript (javascript, js, node)
  • C++ (c++)
  • C (c)
  • Java (java)
  • Go (go)
  • Rust (rust)
  • And many more!

Check available runtimes:

const runtimes = await piston.getRuntimes();
runtimes.forEach((r) => console.log(`${r.language} ${r.version}`));

// Install latest version of a runtime
await piston.installRuntime("python");

// Install specific package version
await piston.installPackage({ language: "python", version: "3.11.0" });

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.