Skip to content

Group

Representing a Datatailr Group.

This class provides methods to interact with the Datatailr Group API. It allows you to create, update, delete, and manage groups within the Datatailr platform.

Attributes:

Name Type Description
name str

The name of the group.

members list

A list of members in the group.

group_id int

The unique identifier for the group.

Static Methods

add(name: str) -> 'Group': Create a new group with the specified name. get(name: str) -> 'Group': Retrieve a group by its name. list() -> list: List all groups available in the Datatailr platform. remove(name: str) -> None: Remove a group by its name. exists(name: str) -> bool: Check if a group exists by its name.

Instance Methods

add_users(usernames: list) -> None: Add users to the group. remove_users(usernames: list) -> None: Remove users from the group.

group_id property

The unique numeric identifier of the group.

members property

List of user IDs that are members of this group.

name property

The name of the group.

__init__(name)

Create a Group instance by fetching group data from the platform.

Parameters:

Name Type Description Default
name str

The name of an existing group.

required

Raises:

Type Description
ValueError

If a group with the given name does not exist.

add(name) staticmethod

Create a new group on the Datatailr platform.

Parameters:

Name Type Description Default
name str

The name for the new group.

required

Returns:

Type Description
Optional[Group]

The newly created Group, or None if the operation failed.

add_users(usernames)

Add one or more users to this group.

Parameters:

Name Type Description Default
usernames list

A list of usernames to add.

required

Raises:

Type Description
ValueError

If the group name is not set.

exists(name) staticmethod

Check whether a group with the given name exists.

Parameters:

Name Type Description Default
name str

The group name to look up.

required

Returns:

Type Description
bool

True if the group exists, False otherwise.

from_dict(data) classmethod

Construct a Group instance from a dictionary.

Parameters:

Name Type Description Default
data dict

A dictionary with keys "name", "members", and "group_id".

required

Returns:

Type Description
Group

A Group instance populated from the dictionary.

Raises:

Type Description
ValueError

If required keys are missing from data.

get(name_or_id) staticmethod

Retrieve an existing group by name or numeric ID.

Parameters:

Name Type Description Default
name_or_id Union[str, int]

The group name (str) or group ID (int).

required

Returns:

Type Description
Group

The matching Group instance.

Raises:

Type Description
ValueError

If no group with the given name or ID exists.

is_member(user)

Check whether a user belongs to this group.

Parameters:

Name Type Description Default
user

A User instance or a user ID (int).

required

Returns:

Type Description
bool

True if the user is a member, False otherwise.

Raises:

Type Description
ValueError

If the group name is not set.

ls() staticmethod

List all groups on the Datatailr platform.

Returns:

Type Description
list

A list of Group instances.

remove(name) staticmethod

Remove (delete) a group from the platform.

Parameters:

Name Type Description Default
name str

The name of the group to remove.

required

remove_users(usernames)

Remove one or more users from this group.

Parameters:

Name Type Description Default
usernames list

A list of usernames to remove.

required

Raises:

Type Description
ValueError

If the group name is not set.