A high-performance inter-process communication library designed to work with the latest version of discord.py
Project description
Better IPC
High-performance inter-process communication library designed to work with the latest version of discord.py
This library is heavily based on discord-ext-ipc, which is no longer maintained.
Installation
Stable version
python3 -m pip install -U better-ipc
Development version
python3 -m pip install -U git+https://github.com/MiroslavRosenov/better-ipc
Support
You can join the support server here
Examples
Client example
import discord
from typing import Dict
from discord.ext import commands, ipc
from discord.ext.ipc.server import route
from discord.ext.ipc.objects import ClientPayload
class MyBot(commands.Bot):
def __init__(self) -> None:
intents = discord.Intents.all()
super().__init__(
command_prefix="$.",
intents=intents,
case_insensitive=True,
status=discord.Status.online
)
self.ipc = ipc.Server(self, secret_key="🐼")
async def setup_hook(self) -> None:
await self.ipc.start()
@route()
async def get_user_data(self, data: ClientPayload) -> Dict:
user = self.get_user(data.user_id)
return user._to_minimal_user_json()
MyBot.ipc.route()
Cog example
from typing import Dict
from discord.ext import commands, ipc
from discord.ext.ipc.server import route
from discord.ext.ipc.errors import IPCError
from discord.ext.ipc.objects import ClientPayload
class Routes(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
if not hasattr(bot, "ipc"):
bot.ipc = ipc.Server(self.bot, secret_key="🐼")
@commands.Cog.listener()
async def on_cog_load(self) -> None:
await self.bot.ipc.start()
@commands.Cog.listener()
async def on_cog_unload(self) -> None:
await self.bot.ipc.stop()
@route()
async def get_user_data(self, data: ClientPayload) -> Dict:
user = self.bot.get_user(data.user_id)
return user._to_minimal_user_json()
async def setup(bot):
await bot.add_cog(Routes(bot))
Inside your web application
from quart import Quart
from discord.ext.ipc import Client
app = Quart(__name__)
ipc = Client(secret_key="🐼")
@app.route('/')
async def main():
async with ipc as conn:
return await conn.request("get_user_data", user_id=383946213629624322)
if __name__ == '__main__':
app.run()
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
better-ipc-1.1.1.tar.gz
(12.2 kB
view hashes)
Built Distribution
better_ipc-1.1.1-py3-none-any.whl
(13.4 kB
view hashes)
Close
Hashes for better_ipc-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3f165ff76c374b31155ad90215bfbcc22214748de2a16e7c37b587a06b691b9 |
|
MD5 | 727c65ec95c76915ee74955a1bb95a8b |
|
BLAKE2b-256 | a2e4521ac50a0e9e16d34098a0b0958d216ff2e9543bb5063ef7407c80c97edf |