Groupcast
============
**Groupcast** is a lightweight Python utility for broadcasting method calls and aggregating attribute access across a group of objects — as if they were a single entity.
It supports both serial and parallel execution modes, along with list-like behavior (iteration, indexing, appending, popping).
---
## Features
- ✅ Broadcast method calls across objects (`group.method(args)`)
- ✅ Access non-callable attributes as aggregated lists (`group.attr`)
- ✅ Switch between **serial** and **parallel** execution modes
- ✅ Direct control via `apply()` for methods and `get()` for attributes
- ✅ List-like behavior: `len()`, `[]`, iteration, `append()`, `pop()`
---
## Installation
This library is instable via pip using the command `pip install groupcast`, if you would rather not use pip, you could also just drop this file into your project and import it that way.
Simple Usage
-----
```python
class Example:
def __init__(self, x):
self.x = x
def double(self):
return(self.x * 2)
inputs = [[1], [2], [3]]
group = groupcast.Group(Example, inputs=inputs)
print(group.x)
# should result in [1, 2, 3]
print(group.double())
# should result in [2, 4, 6]
print(group[0].x) #< to only print the value for the first object
# should result in 1
```
Constructor
-----------
`Group(inputs=None, class_=None, objects=None, parallel=False, maxWorkers=None)`
You can initialize a `Group` in two ways:
1. **Using `class_`**:
* Creates a list of objects by creating the `class_` constructor.
2. **Using `objects` directly**:
* Pass in a list of pre-created objects.
If neither `objects` nor `class_` is provided, a `TypeError` is raised.
Execution Modes
---------------
Use `.changeExecutionMode(parallel=True, maxWorkers=...)` to toggle between:
* **Serial mode (default):** runs method calls one after another.
* **Parallel mode:** runs method calls concurrently using threads.
To change modes, use the following:<br>
`group.changeExecutionMode(parallel=True) # now runs in parallel` <br>
You can also set it to false to return back to serial mode
Attribute & Method Access
-------------------------
* `group.attr` returns a list of attribute values (e.g., `group.x will return [x1,x2,x3,x4] for every object`)
* `group.method(*args)` broadcasts the call across all objects and will return the results
* For explicit control:
* `group.get("attrName")`
* `group.apply("methodName", *args)`
* * *
Appending & Removing
--------------------
To append, you can use the append and pass the same varibles as you pass to __init__ <br>
EX:
`group.append(input=4, class_=Example)` will add a new Example object initialized with the value `4`
You can append using either `class_`, or a ready `object`.
Example Use Cases
-----------------
* Managing multiple similar sensor or device objects.
* Group operations on widgets, models, or entities in simulations/games.
* Synchronous control of multiple instances for testing or broadcasting commands.
License
-------
MIT License (see LICENSE file for more information)
Raw data
{
"_id": null,
"home_page": null,
"name": "groupcast",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "delegation, broadcasting, group, OOP, metaprogramming",
"author": null,
"author_email": "Tzur Soffer <tzur.soffer@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/18/66/79295b0fa5b0dc26851d988b8c822b35d3c629e902ba4b5eb39d33a4032d/groupcast-1.1.2.tar.gz",
"platform": null,
"description": "\r\n\r\nGroupcast\r\n============\r\n\r\n**Groupcast** is a lightweight Python utility for broadcasting method calls and aggregating attribute access across a group of objects \u2014 as if they were a single entity.\r\n\r\nIt supports both serial and parallel execution modes, along with list-like behavior (iteration, indexing, appending, popping).\r\n\r\n\r\n---\r\n\r\n## Features\r\n\r\n- \u2705 Broadcast method calls across objects (`group.method(args)`)\r\n- \u2705 Access non-callable attributes as aggregated lists (`group.attr`)\r\n- \u2705 Switch between **serial** and **parallel** execution modes\r\n- \u2705 Direct control via `apply()` for methods and `get()` for attributes\r\n- \u2705 List-like behavior: `len()`, `[]`, iteration, `append()`, `pop()`\r\n\r\n---\r\n\r\n## Installation\r\n\r\nThis library is instable via pip using the command `pip install groupcast`, if you would rather not use pip, you could also just drop this file into your project and import it that way.\r\n\r\nSimple Usage\r\n-----\r\n\r\n```python\r\nclass Example:\r\n def __init__(self, x):\r\n self.x = x\r\n def double(self):\r\n return(self.x * 2)\r\ninputs = [[1], [2], [3]]\r\ngroup = groupcast.Group(Example, inputs=inputs) \r\nprint(group.x)\r\n# should result in [1, 2, 3]\r\n\r\nprint(group.double())\r\n# should result in [2, 4, 6]\r\n\r\nprint(group[0].x) #< to only print the value for the first object\r\n# should result in 1\r\n```\r\n\r\nConstructor\r\n-----------\r\n\r\n`Group(inputs=None, class_=None, objects=None, parallel=False, maxWorkers=None)`\r\n\r\nYou can initialize a `Group` in two ways:\r\n\r\n1. **Using `class_`**:\r\n \r\n * Creates a list of objects by creating the `class_` constructor.\r\n \r\n2. **Using `objects` directly**:\r\n \r\n * Pass in a list of pre-created objects.\r\n \r\n\r\nIf neither `objects` nor `class_` is provided, a `TypeError` is raised.\r\n\r\nExecution Modes\r\n---------------\r\n\r\nUse `.changeExecutionMode(parallel=True, maxWorkers=...)` to toggle between:\r\n\r\n* **Serial mode (default):** runs method calls one after another.\r\n \r\n* **Parallel mode:** runs method calls concurrently using threads.\r\n\r\nTo change modes, use the following:<br>\r\n`group.changeExecutionMode(parallel=True) # now runs in parallel` <br>\r\nYou can also set it to false to return back to serial mode\r\n\r\nAttribute & Method Access\r\n-------------------------\r\n\r\n* `group.attr` returns a list of attribute values (e.g., `group.x will return [x1,x2,x3,x4] for every object`)\r\n \r\n* `group.method(*args)` broadcasts the call across all objects and will return the results\r\n \r\n* For explicit control:\r\n \r\n * `group.get(\"attrName\")`\r\n \r\n * `group.apply(\"methodName\", *args)`\r\n \r\n\r\n* * *\r\n\r\nAppending & Removing\r\n--------------------\r\n\r\nTo append, you can use the append and pass the same varibles as you pass to __init__ <br>\r\nEX:\r\n`group.append(input=4, class_=Example)` will add a new Example object initialized with the value `4`\r\n\r\nYou can append using either `class_`, or a ready `object`.\r\n\r\nExample Use Cases\r\n-----------------\r\n\r\n* Managing multiple similar sensor or device objects.\r\n \r\n* Group operations on widgets, models, or entities in simulations/games.\r\n \r\n* Synchronous control of multiple instances for testing or broadcasting commands.\r\n \r\n\r\nLicense\r\n-------\r\n\r\nMIT License (see LICENSE file for more information)\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Dynamic method broadcasting to groups of objects",
"version": "1.1.2",
"project_urls": {
"Homepage": "https://github.com/TzurSoffer/Groupcast",
"Repository": "https://github.com/TzurSoffer/Groupcast"
},
"split_keywords": [
"delegation",
" broadcasting",
" group",
" oop",
" metaprogramming"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4afb97c4c036a668f379428f7453e7394fc4bfa1563d7927df4162ae3413b409",
"md5": "cfe56d64ecfb06369c961cc0fffa4834",
"sha256": "7b413d2acc95aa003baf8da3af14e753528fa61267f8561f74b49062375cdc46"
},
"downloads": -1,
"filename": "groupcast-1.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cfe56d64ecfb06369c961cc0fffa4834",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4644,
"upload_time": "2025-07-11T18:41:31",
"upload_time_iso_8601": "2025-07-11T18:41:31.006670Z",
"url": "https://files.pythonhosted.org/packages/4a/fb/97c4c036a668f379428f7453e7394fc4bfa1563d7927df4162ae3413b409/groupcast-1.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "186679295b0fa5b0dc26851d988b8c822b35d3c629e902ba4b5eb39d33a4032d",
"md5": "c34bb772d746ae1775fd69657858fb98",
"sha256": "0cbc76a79c0776da9893649004073c6cb19930a225d81282cdf03f2ee46a146a"
},
"downloads": -1,
"filename": "groupcast-1.1.2.tar.gz",
"has_sig": false,
"md5_digest": "c34bb772d746ae1775fd69657858fb98",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4289,
"upload_time": "2025-07-11T18:41:32",
"upload_time_iso_8601": "2025-07-11T18:41:32.126275Z",
"url": "https://files.pythonhosted.org/packages/18/66/79295b0fa5b0dc26851d988b8c822b35d3c629e902ba4b5eb39d33a4032d/groupcast-1.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-11 18:41:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TzurSoffer",
"github_project": "Groupcast",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "groupcast"
}