Skip to main content

Websocket based IPC for discord.py bots

Project description

winerp

An IPC based on Websockets. Fast, Stable, and easy-to-use, for inter-communication between your processes or discord.py bots.

BREAKING CHANGES (1.4.0):
The message source name is passed to all registered routes. Instead of:

@ipc.route() # < v1.4.0
async def route_name():
    ...

Use:

@ipc.route() # >= v1.4.0
async def route_name(source):
    ...

Key Features

  • Fast with minimum recorded response time being < 2ms
  • Lightweight, Stable and Easy to integrate.
  • No limitation on number of connected clients.

Installation

Stable:

pip install -U winerp

Main branch (can be unstable/buggy):

pip install git+https://www.github.com/BlackThunder01001/winerp

Working:

This library uses a central server for communication between multiple clients. You can connect a large number of clients for sharing data, and data can be shared between any connected client.

  1. Import the library:
import winerp
  1. Initialize winerp client:
ipc_client = winerp.Client(local_name = "my-cool-app", port=8080)
  1. Start the client:
await ipc_client.start()
# or
asyncio.create_task(ipc_client.start())
  • Registering routes:
@ipc_client.route
async def route_name(source, user_name):
    return f"Hello {user_name}"
  • Requesting data from another client:
user_name = await ipc_client.request(route="fetch_user_name", source="another-cool-bot", user_id = 123)
  • Sending information type data to other clients:
data = [1, 2, 3, 4]
await ipc_client.inform(data, destinations=["another-cool-bot"])

Example Usage:

Start the server on terminal using $ winerp --port 8080. You can also start the server using winerp.Server

Client 1 (some-random-bot):

import winerp
import discord
from discord.ext.commands import Bot
bot = Bot(command_prefix="!", intents=discord.Intents.all())

bot.ipc = winerp.Client(local_name = "some-random-bot", port=8080)

@bot.command()
async def request(ctx):
    # Fetching data from a client named "another-bot" using route "get_some_data"
    data = await bot.ipc.request("get_some_data", source = "another-bot")
    await ctx.send(data)


@bot.ipc.route()
async def get_formatted_data(source, user_id = None):
    return f"<@{user_id}>"


@bot.ipc.event
async def on_winerp_ready():
    print("Winerp Client is ready for connections")

bot.loop.create_task(bot.ipc.start())
bot.run("TOKEN")

Client 2 (another-bot)

import winerp
import discord
from discord.ext.commands import Bot
bot = Bot(command_prefix="?", intents=discord.Intents.all())

bot.ipc = winerp.Client(local_name = "another-bot", port=8080)

@bot.command()
async def format(ctx):
    # Fetching data from a client named "some-random-bot" using route "get_formatted_data"
    data = await bot.ipc.request("get_formatted_data", source = "some-random-bot", user_id = ctx.author.id)
    await ctx.send(data)


@bot.ipc.route()
async def get_some_data(source):
    return "You are very cool"


bot.loop.create_task(bot.ipc.start())
bot.run("TOKEN")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

winerp-1.4.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

winerp-1.4.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file winerp-1.4.0.tar.gz.

File metadata

  • Download URL: winerp-1.4.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.5

File hashes

Hashes for winerp-1.4.0.tar.gz
Algorithm Hash digest
SHA256 4a8491ca2137dcb9de194a96ee152d7496c36b4933e26c28c7634cb65e68bf84
MD5 e7f8df5079805f40edde3e20ffdf5a18
BLAKE2b-256 74a9bfde2fe913ea57adaad75779ba87881f3de4ea9a6b7b580057454cf7ecf5

See more details on using hashes here.

File details

Details for the file winerp-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: winerp-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.5

File hashes

Hashes for winerp-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af26696d7bd4a64a334ad3a899b2ff75c367e5f74190c4a2a72008cf314ea4eb
MD5 4a89016382a937a7946287d9dbbc51f4
BLAKE2b-256 dfb22dae43c90c13d7e9c795b642665b0d09cc374bbafc420d384067a004a38f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page