A high-performance inter-process communication library designed to work with the latest version of py-cord
Project description
Pycord IPC
High-performance inter-process communication library designed to work with the latest version of Pycord
This library is based on Better-IPC.
Installation
Stable version
For Linux
python3 -m pip install -U pycord-ipc
For Windows
py -m pip install -U pycord-ipc
Examples
Client example
import asyncio
import websockets
import discord
from discord.ext import commands
from ipc.server import Server
from ipc.objects import ClientPayload
intents = discord.Intents.all()
bot = discord.Bot(intents=intents)
ipc = Server(bot, secret_key="🐼")
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
@Server.route()
async def get_user_data(self,data: ClientPayload):
user = bot.get_user(int(data.user_id))
return user._to_minimal_user_json()
async def main():
await ipc.start()
await bot.start('BOT_TOKEN')
if __name__ == "__main__":
asyncio.run(main())
Cog example
from typing import Dict
from discord.ext import commands, ipc
from discord.ext.ipc.server import Server
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="🐼")
async def cog_load(self):
await self.bot.ipc.start()
async def cog_unload(self):
await self.bot.ipc.stop()
self.bot.ipc = None
@Server.route()
async def get_user_data(self, data: ClientPayload):
user = self.bot.get_user(int(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('/user/<user>')
async def main(user):
resp = await ipc.request("get_user_data", user_id=user)
return str(resp.response)
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
Pycord-IPC-1.0.0.tar.gz
(8.0 kB
view hashes)
Built Distributions
Close
Hashes for pycord_ipc-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2fff8a731822392b777ed43c157a644baa8b225d82758b6b0a9c866fc8c906b |
|
MD5 | b6d5b29da92bbd5fc61e6be564a07d7d |
|
BLAKE2b-256 | 253c82b6afe2ef09c0bfb648b097200db99b71011f09e8173bd3aa7ee1a95177 |
Close
Hashes for Pycord_IPC-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c13c0fe461106292ea7b7f3c1aef5eecc8ef6c21e8040821f6d5bd558b3beb5 |
|
MD5 | 9664970e8f4c00555df4692d80d6adb5 |
|
BLAKE2b-256 | 0f932982891f3dffb623beee48e7aabeb2e258fcf0654bbbe4f7dd9c30c08c63 |