Skip to main content

A pycord extension for inter-process communication.

Project description

pycord-ipc

A pycord extension for inter-process communication.

Installation

Python >= 3.10.x is required.

# Windows
pip install --upgrade pycord-inter-process

# Linux
pip3 install --upgrade pycord-inter-process

Examples

Server example

import discord
from pycord.ipc import Server

print("Bot starting...")

intents = discord.Intents.all()
bot = discord.Bot(intents=intents)
ipc_server = Server(bot, secret_key=<"your IPCSecret">, host=<"your IPCHost">, port=63719)

@bot.event
async def on_ready():
    await ipc_server.start()

# @bot.event
# async def on_ipc_ready():
#     """Called upon the IPC Server being ready"""
#     print(f"Starting IPC server")

@bot.event
async def on_ipc_error(endpoint, error):
    print(f"{endpoint} raised {error}")

@ipc_server.route()
async def get_bot_stats(data):
    return {
        "guild_count": len(bot.guilds),
        "channel_count": sum(len(guild.channels) for guild in bot.guilds),
        "member_count": sum(len(guild.members) for guild in bot.guilds),
    }

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

bot.run(<"your Token">)

Client example

from quart import Quart, request, session, redirect, url_for, jsonify
from pycord.ipc import Client

app = Quart(__name__)
ipc_client = Client(secret_key=<"your IPCSecret">, host=<"your IPC Server IP">, port=<"your IPC Server Port">)

@app.route("/api/bot/stats", methods=["GET"])
async def get_bot_stats():
    try:
        bot_stats = await ipc_client.request("get_bot_stats")
        return jsonify({
            "success": True,
            "data": {
                "guild_count": bot_stats["guild_count"],
                "channel_count": bot_stats["channel_count"],
                "member_count": bot_stats["member_count"]
            }
        })
    except Exception as e:
        return jsonify({
            "success": False,
            "error": str(e)
        }), 500

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080, debug=True)

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_inter_process-0.1.2.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycord_inter_process-0.1.2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file pycord_inter_process-0.1.2.tar.gz.

File metadata

  • Download URL: pycord_inter_process-0.1.2.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for pycord_inter_process-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8be9092b0eea01eab37d442e149ccdf6f00602fe4537c505bb9b9308940884c4
MD5 c68e1744d8dccb04360b168761d338b1
BLAKE2b-256 61f088f4b134cebaf7f2887517c5fcec4293a2c7b9cf289c2f6ad53f5976d2c3

See more details on using hashes here.

File details

Details for the file pycord_inter_process-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pycord_inter_process-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5ce0d2002ce819b8ca0341ce72ea42a4f237f1ba08925ed686f74f5032222c49
MD5 1d71e83e26fcbf5531279a766a91094d
BLAKE2b-256 0f48f518ca625d059a743a6ed878d5d3d557bbc86f3d9b81861f055c35668862

See more details on using hashes here.

Supported by

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