IPC Server Tools¶
discord_tools provides a simple IPC handler. This section outlines
everything about it.
Models¶
ClientSession¶
- asyncrequest
- class discord_tools.ipc.ClientSession(host='localhost', port=..., multicast_port=20000, secret_key=..., *, session=...)[source]¶
A simple wrapper around an
ClientSessionfor easy handling with an IPC server.Added in version 1.0.
- async with x
Asynchronously starts this client session.
- Parameters:
host (
str) – The host to connect to. Defaults tolocalhost.port (
int) – The port to connect to. If missing, uses the multicast port.multicast_port (
int) – The multicast port to connect to. Defaults to20000.secret_key (
str) – The secret key to use on theAuthorizationheader on request. This must have the same value asServer.secret_key.session (
ClientSession) – The session to use with this handler. If not provided creates a new one.
- property resolved_port¶
Returns the resolved port to connect to, this is either the
portparameter or themulticast_portparameter if no value was provided on the previous one.- Type:
Server¶
- @route
- asyncterminate_server
- class discord_tools.ipc.Server(client, host='localhost', port=8000, secret_key=..., multicast=True, multicast_port=20000)[source]¶
The server used for the IPC.
Added in version 1.0.
- Parameters:
client (
Client) – The client associated to this server.host (
str) – The host to run the server on. Defaults tolocalhost.port (
int) – The port to run the server on. Defaults to8000.secret_key (
str) – The secret key to check for on theAuthorizationheader on requests. This can be used to limit requests to your bot, you must have the same secret key on the client.multicast (
bool) – Whether to enable multicasting. Defaults toTrue.multicast_port (
int) – The port to run the multicasting server on. Defaults to20000.
- property secret_key¶
Returns the secret key required for requests handling, or
None.- Type:
Optional[
str]
Request¶
- class discord_tools.ipc.Request(data, ws, endpoint, headers, loop)[source]¶
Represents an IPC request.
Added in version 1.0.
- for ... in x
Iterates through all the request data keys.
- keys()[source]¶
KeysView: Returns all the keys of the data the request provided.This is similar to
dict.keys().- Return type:
- values()[source]¶
ValuesView: Returns all the values of the data the request provided.This is similar to
dict.values().- Return type:
- items()[source]¶
ItemsView: Returns (key, value) pairs of all the keys and values the request provided.This is similar to
dict.items().- Return type:
Route¶
Functions¶
Event Reference¶
- discord_tools.ipc.on_raw_ipc_request(request)¶
Called when the IPC receives a request. This is called before the actual route callback, so it is recommended to not respond to the request in this event nor depend on it.
Note
This event is dispatched always, even if the endpoint is not a valid one.
- Parameters:
request (Request) – The raw request
- discord_tools.ipc.on_ipc_request_completion(request)¶
Called when the IPC completes a request. This is called after the route callback.
Note
Unlike
on_raw_ipc_request(), this event is not dispatched if the route is not valid.- Parameters:
request (Request) – The request that was completed