Skip to main content

Inter-process communication library for Python3 to interact with JS renderer

Project description

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.

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

pythonipc-1.4.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

pythonipc-1.4.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file pythonipc-1.4.2.tar.gz.

File metadata

  • Download URL: pythonipc-1.4.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for pythonipc-1.4.2.tar.gz
Algorithm Hash digest
SHA256 a3a72cfcf58269483d3b6720085b5420f1849526d1a31e496a06aeeb89dea031
MD5 feda38a930c9897d3bed5feeb73e517b
BLAKE2b-256 09a7c1fa96e1d75b2be0497203b4d7450615f32e84a602bf8da8d909d880152b

See more details on using hashes here.

File details

Details for the file pythonipc-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: pythonipc-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for pythonipc-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b96cf373cf0fbd857f87581f657795ab225940f8ab4adb3c15376d12e674de38
MD5 301635ca242a50815ad235e6070a8054
BLAKE2b-256 ac1da75e924a8532d072e5b089d00144eb3ee270c40877c1d4b0964bc933db54

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