Skip to main content

Dynamic method broadcasting to groups of objects

Project description

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

class Example:
    def __init__(self, x):
        self.x = x
    def double(self):
        return self.x * 2
inputs = [1, 2, 3]
group = groupcast.Group(inputs=inputs, class_=Example) 
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 inputs and class_:

    • Creates a list of objects by passing each element of inputs to the class_ constructor.
  2. Using objects directly:

    • Pass in a list of pre-created objects.

If neither objects nor both inputs and class_ are 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:
group.changeExecutionMode(parallel=True) # now runs in parallel
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
EX: group.append(input=4, class_=Example) will add a new Example object initialized with the value 4

You can append using either an input and 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)

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

groupcast-1.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

groupcast-1.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file groupcast-1.1.1.tar.gz.

File metadata

  • Download URL: groupcast-1.1.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for groupcast-1.1.1.tar.gz
Algorithm Hash digest
SHA256 88109e8cdcef276396491dd370695dbf7bb5616599fdde175e128410dab859de
MD5 8f25f84ea5f70880cab8f60ae21b288b
BLAKE2b-256 fdfa4cd651fbd4724e75c5b77123752499bc4f125ef8dd9e46aa227d8b0e8693

See more details on using hashes here.

File details

Details for the file groupcast-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: groupcast-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for groupcast-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 676fb69478b0e14695db15bbfcc567258d3d3ced7d3970bd2242aec20d8bf61c
MD5 e1c1df8dd6bcfe28df93501fbeccd4e3
BLAKE2b-256 161feabec73f38597ba0b515e37ad9c5577912982a1c7e0e644cc21e6485b21b

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