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.0.0.tar.gz (3.4 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.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for groupcast-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4c708eb694aa1640290dbcdaa92c4eaf9d20ec7e68c36fb4844c71ce7976a7a5
MD5 cf37fa242f4779ed5095fcb4bb028ccd
BLAKE2b-256 9cf276773da25e6a1b2cece29c7947367d4649bbbba3bbc825422f7fe80de881

See more details on using hashes here.

File details

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

File metadata

  • Download URL: groupcast-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 138487a0a971ff8b2368942c2b893ef871cae40fd79c0e194b5259d1d317d1d2
MD5 9a33e70e2e5ec7893b662f72691440bf
BLAKE2b-256 0742fdae1c7618f7d804aaf36b941c04b496df4f596dcf2b896d40871b14064e

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