Better IPC
A high-performance inter-process communication library designed to work with the latest version of discord.py
This library is heavily based on discod-ext-ipc, which is no longer maintained.
Installation
Stable version (Guaranteed to work)
python -m pip install better-ipc
Unstable version (Active getting updates)
python -m pip install -U git+https://github.com/MiroslavRosenov/better-ipc
Inside your Discord client (with decorator)
import logging
import discord
from discord.ext import commands, ipc
from discord.ext.ipc.Server import route
from discord.ext.ipc.errors import IPCError
class Routes(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
if not hasattr(bot, "ipc"):
bot.ipc = ipc.Server(self.bot, host="127.0.0.1", port=2300, secret_key="your_secret_key_here")
bot.ipc.start(self)
@commands.Cog.listener()
async def on_ipc_ready(self):
logging.info("Ipc is ready")
@commands.Cog.listener()
async def on_ipc_error(self, endpoint: str, error: IPCError):
logging.error(endpoint, "raised", error, file=sys.stderr)
@route()
async def get_user_data(self, data):
user = self.bot.get_user(data.user_id)
return user._to_minimal_user_json() # THE OUTPUT MUST BE JSON SERIALIZABLE!
async def setup(bot):
await bot.add_cog(Routes(bot))
Inside your Discord client (with manual endpoint register)
import logging
import discord
from discord.ext import commands, ipc
from discord.ext.ipc.Server import route
from discord.ext.ipc.errors import IPCError
class Routes(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
if not hasattr(bot, "ipc"):
bot.ipc = ipc.Server(self.bot, host="127.0.0.1", port=2300, secret_key="your_secret_key_here")
bot.ipc.start(self)
for name, function in inspect.getmembers(self):
if name.startswith("get_"): # ATTENTION: Every function that stats with `get_` will be registered as endpoint
bot.ipc.endpoints[name] = function
@commands.Cog.listener()
async def on_ipc_ready(self):
logging.info("Ipc is ready")
@commands.Cog.listener()
async def on_ipc_error(self, endpoint: str, error: IPCError):
logging.error(endpoint, "raised", error, file=sys.stderr)
async def get_user_data(self, data):
user = self.bot.get_user(data.user_id)
return user._to_minimal_user_json() # THE OUTPUT MUST BE JSON SERIALIZABLE!
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(
host="127.0.0.1",
port=2300,
secret_key="your_secret_key_here"
) # These params must be the same as the ones in the client
@app.route('/')
async def main():
data = await ipc_client.request("get_user_data", user_id=383946213629624322)
return str(data)
if __name__ == '__main__':
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
app.ipc = loop.run_until_complete(IPC.start(loop=loop)) # `Client.start()` returns new Client instance
app.run(loop=loop)
finally:
loop.run_until_complete(app.ipc.close()) # Closes the session, doesn't close the loop
loop.close()
Metadata
Release files for better-ipc 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| better-ipc-1.0.1.tar.gz | 9.6 kB | Without provenance | Details for better-ipc-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| better_ipc-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for better_ipc-1.0.1-py3-none-any.whl |
Total release size: 21.3 kB
Release files / better-ipc-1.0.1.tar.gz
| Download URL | better-ipc-1.0.1.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdfad6b6e477b2351e1f34b1902996cbed433489e441ba69aac1d11b2268a936
|
|
BLAKE2b-256 checksum How to use checksums |
e81644bed756b90c1a0cf53ab0c13a19994725539eb596c2ac1bcdeeb5273ad3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / better_ipc-1.0.1-py3-none-any.whl
| Download URL | better_ipc-1.0.1-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b9d0dac301be3515d0f507387d429646f6462012612d1d2f3c3cf15e1a256fe
|
|
BLAKE2b-256 checksum How to use checksums |
9ec94cd07f6584929d0fb754bb4f2eafba721615115b32bc40f4d95b4598cb0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for better-ipc 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.