Skip to main content

Dynamic method broadcasting to groups of objects

Project description

Groupcast

The Groupcast library provides a simple interface for managing and interacting with a group of objects as if they were a single entity. It supports method broadcasting, property access, and basic list-like behavior (indexing, iteration, and length).

Features

  • Broadcast method calls to all objects in the group.

  • Aggregate attribute/property access from all objects.

  • Behaves like a list: supports len(), indexing ([]), and iteration.

  • Flexible construction: either provide a list of objects directly, or provide input data and a constructor class.

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)

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.

Attribute Access

When accessing an attribute or method:

  • If it's a non-callable (e.g., a property or attribute), a list of values is returned from all objects.

  • If it's a method, a new function is returned that will call the method on all objects with the provided arguments and return a list of results.

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.0.tar.gz (3.7 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.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: groupcast-1.1.0.tar.gz
  • Upload date:
  • Size: 3.7 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.0.tar.gz
Algorithm Hash digest
SHA256 97da86b9d06e28c77c24574136aa9b7acb3129aadf98e0cf9d1c0f66402b4424
MD5 87f28093050fd73b83fbb1ca65675ce1
BLAKE2b-256 12265b3d5f4daa0cdf94a0ede3ebc31f8ea603390b29eb264a2ccf955c602dff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: groupcast-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37ad74d63efa0181e9f36a57224030978eadcd37892cca283fd0ef434664364d
MD5 5236a651fccde902f3c13ee32ac327bd
BLAKE2b-256 dc850a4ab0c0c34d20f41e44a4f9e22a50d5827e88b3cf2ba1e5019981930e18

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