{"id":19102484,"url":"https://github.com/insyri/tpy","last_synced_at":"2025-04-30T16:26:32.943Z","repository":{"id":38389203,"uuid":"487667438","full_name":"insyri/tpy","owner":"insyri","description":"🔑 A strongly typed Pylon API client.","archived":false,"fork":false,"pushed_at":"2023-10-05T06:14:24.000Z","size":350,"stargazers_count":7,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T06:57:02.313Z","etag":null,"topics":["deno","node","pylonbot","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/insyri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-01T23:44:41.000Z","updated_at":"2024-01-12T18:30:05.000Z","dependencies_parsed_at":"2025-04-18T20:04:01.423Z","dependency_job_id":null,"html_url":"https://github.com/insyri/tpy","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insyri%2Ftpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insyri%2Ftpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insyri%2Ftpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insyri%2Ftpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/insyri","download_url":"https://codeload.github.com/insyri/tpy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251741297,"owners_count":21636223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","node","pylonbot","typescript"],"created_at":"2024-11-09T03:55:50.993Z","updated_at":"2025-04-30T16:26:32.905Z","avatar_url":"https://github.com/insyri.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"right\" width=\"150\" alt=\"pylon\" src=\"https://raw.githubusercontent.com/insyri/tpy/main/.github/assets/pylon.svg\"\u003e\n\n# Tpy [![GitHub CI](https://github.com/insyri/tpy/actions/workflows/ci.yml/badge.svg)](https://github.com/insyri/tpy/actions/workflows/ci.yml)\n\nA strongly typed Pylon API client. https://pylon.bot/\n\n[![](https://shields.io/badge/deno.land/x-05122A?logo=deno\u0026style=for-the-badge)](https://deno.land/x/tpy)\n[![](https://shields.io/badge/npmjs.com-05122A?logo=npm\u0026style=for-the-badge)](https://www.npmjs.com/package/tpy)\n\nTpy is a small and simplistic [Deno](https://deno.land/) module that provides an\neasier way to interact with the [Pylon](https://pylon.bot/) API. It provides the\nfollowing qualities:\n\n- 🧬 Cross runtime support.\n- 🔑 Fully typed APIs.\n- 🗺 Developer-friendly error interface.\n- 📄 Extensive documentation.\n- 📞 Keep-alive WebSocket client.\n\n## Documentation\n\nThe API documentation can be viewed on the\n[Deno website](https://deno.land/x/tpy/mod.ts/).\n\n## CommonJS/ESModule Support\n\nIt was considered for Tpy to become an ESModule project for Node.js, however,\nmany projects are still built on CommonJS, a module system specific to Node.\n\nTo combat this, Tpy now ships an `*-esm` version of the package, allowing users\nto install the desired module system without downloading the other that will not\nbe used. For example: `1.0.0-RC-2` ships CommonJS, `1.0.0-RC-2-esm` ships\nESModules.\n\n## Installation\n\n```bash\nnpm install tpy\nyarn add tpy\npnpm add tpy\n```\n\nIf you would like to use Tpy in the browser, considering\n[vendoring dependencies](https://deno.land/manual@v1.26.1/tools/vendor) to\ndownload the type dependencies locally.\n\n## Examples\n\n#### Get the token's matching user.\n\n```ts\nconst client = new Tpy({ token: \"PYLON_TOKEN\" });\nconst { displayName, id } = await client.getUser();\n\nconsole.log(`Logged in as ${displayName} (\u003c@${id}\u003e).`);\n```\n\n#### Listen to a deployment's console output.\n\n```ts\nconst client = new Tpy({ token: \"PYLON_TOKEN\" });\nconst ws = client.connectSocket(\n  await client.getDeploymentIDfromGuild(\"GUILD_ID\")),\n);\n\nws.on(\"open\", (_) =\u003e console.log(\"WebSocket Opened\"));\nws.on(\"error\", (_) =\u003e _);\n// The array matches the console log parameter types.\nws.on\u003c[string, string, number]\u003e(\n  \"message\",\n  ({ data }) =\u003e\n    console.log(`${data[0]} said \"${data[1]}\" and sent ${data[2]} attachment(s).`),\n);\n\n// Remember this!\nawait ws.connect();\n```\n\nWith the following Pylon code:\n\n```ts\ndiscord.on(\"MESSAGE_CREATE\", async (message) =\u003e {\n  console.log(\n    // string\n    message.author.username,\n    // string\n    message.content,\n    // number\n    message.attachments.length,\n  );\n});\n```\n\n#### Get a guild's statistics.\n\n```ts\nconst client = new Tpy({ token: \"PYLON_TOKEN\" });\nconst guildStats = await client.getGuildStats(\"GUILD_ID\");\nconst mostRecent = guildStats.find((e) =\u003e\n  e.date === Math.min(...guildStats.map((e) =\u003e e.date))\n)!;\nconst { date, events, executionMsAvg } = mostRecent;\n\nconst mostRecentDateFormatted = new Date(date * 1000).toDateString();\nconsole.log(\n  `On ${mostRecentDateFormatted}, there was a total of ${events} events with an average execution time of ${executionMsAvg} (in ms).`,\n);\n```\n\n#### Get a deployment's listening events and cron tasks.\n\n```ts\nconst client = new Tpy({\n  token: \"PYLON_TOKEN\",\n  deploymentID: \"DEPLOYMENT_ID\",\n});\nconst { config } = await client.getDeployment();\nconst { cronTasks } = config.tasks;\nconst { events } = config;\nconst cronTasksFormatted = cronTasks.map(({ cronString, name }) =\u003e\n  `    ${name} (${cronString})`\n);\n\nconsole.log(\n  `Listening to ${events.length} discord event(s):\n  ${events.join(\", \")}\\n`,\n  `Running ${cronTasks.length} cron job(s):\\n${cronTasksFormatted.join(\"\\n\")}`,\n);\n```\n\n#### Get the keys in a KV namespace.\n\n```ts\nconst client = new Tpy({ token: \"PYLON_TOKEN\" });\nconst kvnamespace = \"tags\";\nconst kv = client.KV(\n  kvnamespace,\n  await client.getDeploymentIDfromGuild(\"GUILD_ID\"),\n);\n\nconst keys = await kv.list({ limit: 10 });\nconst amountOfKeys = await kv.count();\n\nconsole.log(\n  `There are ${amountOfKeys} key(s) within the ${kvnamespace} KV namespace, these are the first 10 (or less).\n  ${keys.join(\", \")}`,\n);\n```\n\n#### Get and modify values within a KV namespace.\n\n```ts\nconst client = new Tpy({ token: \"PYLON_TOKEN\" });\nconst kvnamespace = \"NAMESPACE\";\nconst kv = client.KV(\n  kvnamespace,\n  await client.getDeploymentIDfromGuild(\"GUILD_ID\"),\n);\n\nconst key = \"cool_lang\";\n\nconsole.log(`Value of key \"${key}\":`, await kv.get(key));\n\nawait kv.put(key, \"rust\");\nconsole.log(`Value of key \"${key}\":`, await kv.get(key));\n\nawait kv.delete(key);\nconsole.log(`Value of key \"${key}\":`, await kv.get(key));\n```\n\n#### Increment a key in a KV namespace.\n\n```ts\n// This is NOT an atomic mutation.\n\nconst client = new Tpy({ token: \"PYLON_TOKEN\" });\nconst kvnamespace = \"NAMESPACE\";\nconst kv = client.KV(\n  kvnamespace,\n  await client.getDeploymentIDfromGuild(\"GUILD_ID\"),\n);\nconst upto = 10;\n\nfor (let i = 0; i \u003c upto; i++) {\n  await kv.transact(\"counter\", (p) =\u003e {\n    p ||= 0;\n    p++;\n    return p;\n  });\n}\n```\n\n## Contributing\n\nIf you'd like to contribute, please read the\n[contributing guide](.github/CONTRIBUTING.md) before you start working. You can\nstart a pre-setup remote workspace immediately by opening the project in Gitpod.\n\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/insyri/tpy)\n\n## Legal\n\nPylon is a copyright (c) of Uplol Inc., all rights reserved to Uplol.\n\nTpy is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsyri%2Ftpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finsyri%2Ftpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsyri%2Ftpy/lists"}