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.
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.
- Import the library:
import winerp
- Initialize winerp client:
ipc_client = winerp.Client(local_name = "my-cool-app", port=8080)
- Start the client:
await ipc_client.start()
# or
asyncio.create_task(ipc_client.start())
- Registering routes:
@ipc_client.route
async def route_name(name):
return f"Hello {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(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():
return "You are very cool"
bot.loop.create_task(bot.ipc.start())
bot.run("TOKEN")
Project details
Release history Release notifications | RSS feed
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.3.1.tar.gz
(13.4 kB
view details)
Built Distribution
winerp-1.3.1-py3-none-any.whl
(13.7 kB
view details)
File details
Details for the file winerp-1.3.1.tar.gz
.
File metadata
- Download URL: winerp-1.3.1.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e48f9f2e5a26e2edb1326370bfcde2bdd8222617f375a656657769ed8402deaf |
|
MD5 | a26285b9e8e108c9b348011ffbfdde6f |
|
BLAKE2b-256 | a4c28ca7e05372da10a4606fa85851695fdad6e0783722ca52f61edddb6d3acb |
File details
Details for the file winerp-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: winerp-1.3.1-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aa440608aa612ed2e1367e6b168707ac7dc9e8fc5c9703a7cb0cca7863746f6 |
|
MD5 | 85ef9374b4889c2490d3cb2c6e04c2f0 |
|
BLAKE2b-256 | 4eefe5cd3a479ed11dba4bd39411b1056e5bc8c8e475a2b3f420bbad87a0c889 |