| Name | pythonipc JSON |
| Version |
1.4.2
JSON |
| download |
| home_page | https://github.com/its-mr-monday/pyipc |
| Summary | Inter-process communication library for Python3 to interact with JS renderer |
| upload_time | 2024-08-27 13:45:35 |
| maintainer | None |
| docs_url | None |
| author | itsmrmonday |
| requires_python | >=3.6 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# 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](https://github.com/its-mr-monday/jsipc)
## Installation
Simply install using pip or your favourite package manager
```console
pip install pythonipc
```
# PYTHONIPC ocumentation
## Import
```python
from pythonipc import PyIPC
```
## Class: PyIPC
### Constructor
```python
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.
```python
ipc = PyIPC()
ipc.start()
```
#### on(event: str)
Decorator to register a handler for a specific event.
```python
@ipc.on('greet')
def greet_handler(data):
return f"Hello, {data['name']}!"
```
#### off(event: str)
Removes a handler for a specific event.
```python
ipc.off('greet')
```
#### invoke(event: str, data: Any = None, timeout: float = 5.0) -> Any
Invokes a remote procedure and waits for its response.
```python
result = ipc.invoke('greet', {'name': 'Alice'})
print(result) # Outputs: Hello, Alice!
```
#### get_connections() -> int
Get the number of connected clients.
```python
connections = ipc.get_connections()
print(f"There are {connections} clients connected")
```
### has_connection() -> bool
Check if there are any connected clients.
```python
if ipc.has_connection():
print("We have a connection!")
```
#### kill()
Stops the PyIPC server and cleans up resources.
```python
ipc.kill()
```
## Full Example
```python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/its-mr-monday/pyipc",
"name": "pythonipc",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "itsmrmonday",
"author_email": "zackary.live8@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/09/a7/c1fa96e1d75b2be0497203b4d7450615f32e84a602bf8da8d909d880152b/pythonipc-1.4.2.tar.gz",
"platform": null,
"description": "# PYTHONIPC\r\n\r\nThis project is solely used because I hate using js for IPC controls\r\n\r\nEssentially this is a python port of electron IPC module\r\n\r\nInstead of the renderer interacting with the main process, a socketio client is used to communicate with a python3 socketio server\r\n\r\nA package for javascript client is available under the following git:\r\n\r\n[JsIPC](https://github.com/its-mr-monday/jsipc)\r\n\r\n## Installation\r\n\r\nSimply install using pip or your favourite package manager\r\n\r\n```console\r\n pip install pythonipc\r\n```\r\n\r\n# PYTHONIPC ocumentation\r\n\r\n## Import\r\n\r\n```python\r\nfrom pythonipc import PyIPC\r\n```\r\n\r\n## Class: PyIPC\r\n\r\n### Constructor\r\n\r\n```python\r\nPyIPC(port: int = 5000, debug = False)\r\n```\r\n\r\nCreates a new PyIPC instance.\r\n\r\n- `port`: The port number to run the server on (default is 5000)\r\n\r\n### Methods\r\n\r\n#### start()\r\n\r\nStarts the PyIPC server in a separate thread.\r\n\r\n```python\r\nipc = PyIPC()\r\nipc.start()\r\n```\r\n\r\n#### on(event: str)\r\n\r\nDecorator to register a handler for a specific event.\r\n\r\n```python\r\n@ipc.on('greet')\r\ndef greet_handler(data):\r\n return f\"Hello, {data['name']}!\"\r\n```\r\n\r\n#### off(event: str)\r\n\r\nRemoves a handler for a specific event.\r\n\r\n```python\r\nipc.off('greet')\r\n```\r\n\r\n#### invoke(event: str, data: Any = None, timeout: float = 5.0) -> Any\r\n\r\nInvokes a remote procedure and waits for its response.\r\n\r\n```python\r\nresult = ipc.invoke('greet', {'name': 'Alice'})\r\nprint(result) # Outputs: Hello, Alice!\r\n```\r\n\r\n#### get_connections() -> int\r\n\r\nGet the number of connected clients.\r\n\r\n```python\r\nconnections = ipc.get_connections()\r\nprint(f\"There are {connections} clients connected\")\r\n```\r\n\r\n### has_connection() -> bool\r\n\r\nCheck if there are any connected clients.\r\n\r\n```python\r\nif ipc.has_connection():\r\n print(\"We have a connection!\")\r\n```\r\n\r\n#### kill()\r\n\r\nStops the PyIPC server and cleans up resources.\r\n\r\n```python\r\nipc.kill()\r\n```\r\n\r\n## Full Example\r\n\r\n```python\r\nfrom pythonipc import PyIPC\r\n\r\nipc = PyIPC(port=5000)\r\n\r\n@ipc.on('greet')\r\ndef greet_handler(data):\r\n return f\"Hello, {data['name']}!\"\r\n\r\ndef main():\r\n ipc.start()\r\n \r\n try:\r\n result = ipc.invoke('greet', {'name': 'Alice'})\r\n print(result) # Outputs: Hello, Alice!\r\n finally:\r\n ipc.kill()\r\n\r\nmain()\r\n```\r\n\r\nThis example sets up a PyIPC server, registers a 'greet' handler, invokes it, and then shuts down the server.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Inter-process communication library for Python3 to interact with JS renderer",
"version": "1.4.2",
"project_urls": {
"Homepage": "https://github.com/its-mr-monday/pyipc"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ac1da75e924a8532d072e5b089d00144eb3ee270c40877c1d4b0964bc933db54",
"md5": "301635ca242a50815ad235e6070a8054",
"sha256": "b96cf373cf0fbd857f87581f657795ab225940f8ab4adb3c15376d12e674de38"
},
"downloads": -1,
"filename": "pythonipc-1.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "301635ca242a50815ad235e6070a8054",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5841,
"upload_time": "2024-08-27T13:45:34",
"upload_time_iso_8601": "2024-08-27T13:45:34.766488Z",
"url": "https://files.pythonhosted.org/packages/ac/1d/a75e924a8532d072e5b089d00144eb3ee270c40877c1d4b0964bc933db54/pythonipc-1.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "09a7c1fa96e1d75b2be0497203b4d7450615f32e84a602bf8da8d909d880152b",
"md5": "feda38a930c9897d3bed5feeb73e517b",
"sha256": "a3a72cfcf58269483d3b6720085b5420f1849526d1a31e496a06aeeb89dea031"
},
"downloads": -1,
"filename": "pythonipc-1.4.2.tar.gz",
"has_sig": false,
"md5_digest": "feda38a930c9897d3bed5feeb73e517b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5668,
"upload_time": "2024-08-27T13:45:35",
"upload_time_iso_8601": "2024-08-27T13:45:35.722065Z",
"url": "https://files.pythonhosted.org/packages/09/a7/c1fa96e1d75b2be0497203b4d7450615f32e84a602bf8da8d909d880152b/pythonipc-1.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-27 13:45:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "its-mr-monday",
"github_project": "pyipc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pythonipc"
}