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 πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

tpy

v1.0.0-RC

Published

πŸ”‘ A strongly typed Pylon API client.

Downloads

11

Readme

Tpy GitHub CI

A strongly typed Pylon API client. https://pylon.bot/

Tpy is a small and simplistic Deno module that provides an easier way to interact with the Pylon API. It provides the following qualities:

  • 🧬 Cross runtime support.
  • πŸ”‘ Fully typed APIs.
  • πŸ—Ί Developer-friendly error interface.
  • πŸ“„ Extensive documentation.
  • πŸ“ž Keep-alive WebSocket client.

Documentation

The API documentation can be viewed on the Deno website.

Installation

npm install tpy
yarn add tpy
pnpm add tpy

If you would like to use Tpy in the browser, considering vendoring dependencies to download the type dependencies locally.

Examples

Get the token's matching user.

const client = new Tpy({ token: "PYLON_TOKEN" });
const { displayName, id } = await client.getUser();

console.log(`Logged in as ${displayName} (<@${id}>).`);

Listen to a deployment's console output.

const client = new Tpy({ token: "PYLON_TOKEN" });
const ws = client.connectSocket(
  await client.getDeploymentIDfromGuild("GUILD_ID")),
);

ws.on("open", (_) => console.log("WebSocket Opened"));
ws.on("error", (_) => _);
// The array matches the console log parameter types.
ws.on<[string, string, number]>(
  "message",
  ({ data }) =>
    console.log(`${data[0]} said "${data[1]}" and sent ${data[2]} attachment(s).`),
);

// Remember this!
await ws.connect();

With the following Pylon code:

discord.on("MESSAGE_CREATE", async (message) => {
  console.log(
    // string
    message.author.username,
    // string
    message.content,
    // number
    message.attachments.length,
  );
});

Get a guild's statistics.

const client = new Tpy({ token: "PYLON_TOKEN" });
const guildStats = await client.getGuildStats("GUILD_ID");
const mostRecent = guildStats.find((e) =>
  e.date === Math.min(...guildStats.map((e) => e.date))
)!;
const { date, events, executionMsAvg } = mostRecent;

const mostRecentDateFormatted = new Date(date * 1000).toDateString();
console.log(
  `On ${mostRecentDateFormatted}, there was a total of ${events} events with an average execution time of ${executionMsAvg} (in ms).`,
);

Get a deployment's listening events and cron tasks.

const client = new Tpy({
  token: "PYLON_TOKEN",
  deploymentID: "DEPLOYMENT_ID",
});
const { config } = await client.getDeployment();
const { cronTasks } = config.tasks;
const { events } = config;
const cronTasksFormatted = cronTasks.map(({ cronString, name }) =>
  `    ${name} (${cronString})`
);

console.log(
  `Listening to ${events.length} discord event(s):
  ${events.join(", ")}\n`,
  `Running ${cronTasks.length} cron job(s):\n${cronTasksFormatted.join("\n")}`,
);

Get the keys in a KV namespace.

const client = new Tpy({ token: "PYLON_TOKEN" });
const kvnamespace = "tags";
const kv = client.KV(
  kvnamespace,
  await client.getDeploymentIDfromGuild("GUILD_ID"),
);

const keys = await kv.list({ limit: 10 });
const amountOfKeys = await kv.count();

console.log(
  `There are ${amountOfKeys} key(s) within the ${kvnamespace} KV namespace, these are the first 10 (or less).
  ${keys.join(", ")}`,
);

Get and modify values within a KV namespace.

const client = new Tpy({ token: "PYLON_TOKEN" });
const kvnamespace = "NAMESPACE";
const kv = client.KV(
  kvnamespace,
  await client.getDeploymentIDfromGuild("GUILD_ID"),
);

const key = "cool_lang";

console.log(`Value of key "${key}":`, await kv.get(key));

await kv.put(key, "rust");
console.log(`Value of key "${key}":`, await kv.get(key));

await kv.delete(key);
console.log(`Value of key "${key}":`, await kv.get(key));

Increment a key in a KV namespace.

// This is NOT an atomic mutation.

const client = new Tpy({ token: "PYLON_TOKEN" });
const kvnamespace = "NAMESPACE";
const kv = client.KV(
  kvnamespace,
  await client.getDeploymentIDfromGuild("GUILD_ID"),
);
const upto = 10;

for (let i = 0; i < upto; i++) {
  await kv.transact("counter", (p) => {
    p ||= 0;
    p++;
    return p;
  });
}

Contributing

If you'd like to contribute, please read the contributing guide before you start working. You can start a pre-setup remote workspace immediately by opening the project in Gitpod.

Open in Gitpod

Legal

Pylon is a copyright (c) of Uplol Inc., all rights reserved to Uplol.

Tpy is licensed under the MIT License.