Skip to main content

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.objects import ClientPayload

class Routes(commands.Cog):
    def __init__(self, bot: commands.Bot):
        self.bot = bot
        self.ipc = ipc.Server(self.bot, secret_key="🐼")

    @commands.Cog.listener()    
    async def on_ready(self):
        await self.ipc.start()

    @Server.route()
    async def get_user_data(self, data: ClientPayload):
        user = self.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


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.1.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

Pycord_IPC-1.0.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file Pycord-IPC-1.0.1.tar.gz.

File metadata

  • Download URL: Pycord-IPC-1.0.1.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for Pycord-IPC-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2a8fa26bcb3309521c059dbf16c70032906b5604ad36b02f519acfbc2cc149da
MD5 fc04703362d95b2faae0641038acf24e
BLAKE2b-256 9d4efcad1422804ffb1d11c4cb79bdeaef4bd0664bfeec36bbbb030da6ba4e06

See more details on using hashes here.

File details

Details for the file Pycord_IPC-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: Pycord_IPC-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for Pycord_IPC-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 11c92b8ce3757663d9dee42ee5d2ccedb4c869af9c9bf77b54b93751b1bd57a2
MD5 f65f99fb6c4a7f1e2256d4448fff5e42
BLAKE2b-256 9ef753f9d5ecfd39558848029c81b517eff9fc06a41e7a3b9444dc33393dc2f5

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