Skip to content

Electron ipc controls ported to a python3 server,

License

Notifications You must be signed in to change notification settings

its-mr-monday/pyipc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PYTHONIPC

This project is solely used because I hate using js for IPC controls

Essentially this is a python port of electron IPC module

Instead of the renderer interacting with the main process, a socketio client is used to communicate with a python3 socketio server

A package for javascript client is available under the following git:

JsIPC

Installation

Simply install using pip or your favourite package manager

    pip install pythonipc

PYTHONIPC ocumentation

Import

from pythonipc import PyIPC

Class: PyIPC

Constructor

PyIPC(port: int = 5000, debug = False)

Creates a new PyIPC instance.

  • port: The port number to run the server on (default is 5000)

Methods

start()

Starts the PyIPC server in a separate thread.

ipc = PyIPC()
ipc.start()

on(event: str)

Decorator to register a handler for a specific event.

@ipc.on('greet')
def greet_handler(data):
    return f"Hello, {data['name']}!"

off(event: str)

Removes a handler for a specific event.

ipc.off('greet')

invoke(event: str, data: Any = None, timeout: float = 5.0) -> Any

Invokes a remote procedure and waits for its response.

result = ipc.invoke('greet', {'name': 'Alice'})
print(result)  # Outputs: Hello, Alice!

get_connections() -> int

Get the number of connected clients.

connections = ipc.get_connections()
print(f"There are {connections} clients connected")

has_connection() -> bool

Check if there are any connected clients.

if ipc.has_connection():
    print("We have a connection!")

kill()

Stops the PyIPC server and cleans up resources.

ipc.kill()

Full Example

from pythonipc import PyIPC

ipc = PyIPC(port=5000)

@ipc.on('greet')
def greet_handler(data):
    return f"Hello, {data['name']}!"

def main():
    ipc.start()
    
    try:
        result = ipc.invoke('greet', {'name': 'Alice'})
        print(result)  # Outputs: Hello, Alice!
    finally:
        ipc.kill()

main()

This example sets up a PyIPC server, registers a 'greet' handler, invokes it, and then shuts down the server.

About

Electron ipc controls ported to a python3 server,

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages