Skip to content

link.data

Data()

Bases: BipObject

Utility class for data entities.

Data entities are the hierarchical backbone of Bip: Project > Item > Document > Version.

This utility class groups all the methods that are shared for these four entities.

Source code in client/bip/link/data.py
25
26
27
28
29
def __init__(self):
    super(Data, self).__init__()
    self.reserved = deepcopy(self.reserved)
    self.reserved.append("_project")
    self._project = None

project: Project property

Parent project.

Returns:

Name Type Description
Project Project

parent of the entity.

add_to(group)

Add the entity to a Group.

The Group's model must allow the current entity type.

Parameters:

Name Type Description Default
group Group

Group: The Group to which the entity is added.

required

Raises:

Type Description
ValueError

If the operation is forbidden by the GroupModel rules.

Source code in client/bip/link/data.py
39
40
41
42
43
44
45
46
47
48
49
50
def add_to(self, group: Group):
    """Add the entity to a Group.

    The Group's model must allow the current entity type.

    Args:
      group: Group: The Group to which the entity is added.

    Raises:
        ValueError: If the operation is forbidden by the GroupModel rules.
    """
    return group.add(self)

delete_attribute(definition)

Convenient class implementation of: bip.link.attribute.delete_attribute.

Warning

The signature of Data.delete_attribute() and bip.link.attribute.delete_attribute are different since Data.delete_attribute() passes itself to the function as entity=self.

Source code in client/bip/link/data.py
199
200
201
202
203
204
205
206
def delete_attribute(self, definition: Definition):
    """Convenient class implementation of: `bip.link.attribute.delete_attribute`.

    !!! warning
        The signature of `Data.delete_attribute()` and `bip.link.attribute.delete_attribute`
        are different since `Data.delete_attribute()` passes itself to the function as `entity=self`.
    """
    return _attribute.delete_attribute(definition, self)

get_attribute(definition=None, existing_only=False)

Convenient class implementation of the link.attribute getters.

  • If definition is provided, using bip.link.attribute.get_attribute.
  • Otherwise, using bip.link.attribute.get_all_attribute.

Warning

The signature of Data.get_attribute() and bip.link.attribute.get_attribute or bip.link.attribute.get_all_attribute are different since Data.get_attribute() passes itself to the function as entity=self.

Source code in client/bip/link/data.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
def get_attribute(
    self,
    definition: Optional[Union[str, Definition]] = None,
    existing_only: bool = False,
) -> Union[Attribute, List[Attribute]]:
    """Convenient class implementation of the `link.attribute` getters.

    - If `definition` is provided, using `bip.link.attribute.get_attribute`.
    - Otherwise, using `bip.link.attribute.get_all_attribute`.

    !!! warning
        The signature of `Data.get_attribute()` and `bip.link.attribute.get_attribute` or
        `bip.link.attribute.get_all_attribute` are different since `Data.get_attribute()`
        passes itself to the function as `entity=self`.
    """
    if definition:
        return _attribute.get_attribute(definition, self, existing_only)
    else:
        return _attribute.get_all_attribute(self, existing_only)

get_container(model)

Convenient shortcut for get_containers() returning a single Group.

Returns a single Group from a given GroupModel. This is useful when it is certain that there is only one Group per model that can contain the current Item.

Examples:

# In the case where
example = link.project.get("example")
shot0100 = example.get_item_by_slug("0100", 'shot', "demo-001")
sequence = shot0100.get_container(model="sequence")

Raises:

Type Description
ValueError

If the GroupModel accepts multiple memberships (an entity can be member of several Groups of the same GroupModel).

Returns:

Name Type Description
Group List[Group]

Found Group.

Source code in client/bip/link/data.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def get_container(self, model: Union[str, GroupModel]) -> List[Group]:
    """Convenient shortcut for `get_containers()` returning a single Group.

    Returns a single Group from a given GroupModel. This is useful when it is certain that
    there is only one Group per model that can contain the current Item.

    Examples:
        ```python
        # In the case where
        example = link.project.get("example")
        shot0100 = example.get_item_by_slug("0100", 'shot', "demo-001")
        sequence = shot0100.get_container(model="sequence")
        ```

    Raises:
        ValueError: If the GroupModel accepts multiple memberships (an entity can be member of
            several Groups of the same GroupModel).

    Returns:
        Group: Found Group.
    """

    if isinstance(model, str):
        model = self._project.get_group_model(slug=model)

    if not model.unique_members:
        raise ValueError(
            f"The model {model} accepts multiple memberships. "
            f'It is not possible to use "get_container()" with it.'
        )

    result = _group.get_containers(self, model)
    if result:
        return result[0]

get_containers(model=None)

Convenient class implementation of: bip.link.group.get_containers.

Warning

The signature of Project.get_containers() and bip.link.group.get_containers are different since Project.get_containers() passes itself to the function as project=self.

Info

This method only returns Groups that contains the Project. For getting the Groups that are owned (children) by the Project, get_group() or get_groups() must be used.

Source code in client/bip/link/data.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def get_containers(self, model: Optional[Union[str, GroupModel]] = None) -> List[Group]:
    """Convenient class implementation of: `bip.link.group.get_containers`.

    !!! warning
        The signature of `Project.get_containers()` and `bip.link.group.get_containers`
        are different since `Project.get_containers()` passes itself to the function as `project=self`.

    !!! info
        This method only returns Groups that contains the Project.
        For getting the Groups that are owned (children) by the Project, `get_group()` or `get_groups()` must be used.
    """

    return _group.get_containers(self, model)

get_definition(slug=None, uid=None)

Convenient class implementation of: bip.link.attribute.get_definition.

Info

This method only returns Definitions that are compatible with the Project entity. For getting all the Project Definitions, get_all_definitions() must be used.

Warning

The signature of Data.get_definition() and bip.link.attribute.get_definition are different since Data.get_definition() passes itself to the function as project=self.

Source code in client/bip/link/data.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def get_definition(
    self, slug: Optional[str] = None, uid: Optional[str] = None
) -> Definition:
    """Convenient class implementation of: `bip.link.attribute.get_definition`.

    !!! info
        This method only returns Definitions that are compatible with the Project entity.
        For getting all the Project Definitions, `get_all_definitions()` must be used.

    !!! warning
        The signature of `Data.get_definition()` and `bip.link.attribute.get_definition`
        are different since `Data.get_definition()` passes itself to the function as `project=self`.
    """
    return _attribute.get_definition(self._project, slug, uid, sub_entity=self)

get_definitions()

Convenient class implementation of: bip.link.attribute.get_definitions.

Info

This method only returns Definitions that are compatible with the Project entity. For getting all the Project Definitions, get_all_definitions() must be used.

Warning

The signature of Data.get_definitions() and bip.link.attribute.get_definitions are different since Data.get_definitions() passes itself to the function as project=self.

Source code in client/bip/link/data.py
223
224
225
226
227
228
229
230
231
232
233
234
def get_definitions(self) -> List[Definition]:
    """Convenient class implementation of: `bip.link.attribute.get_definitions`.

    !!! info
        This method only returns Definitions that are compatible with the Project entity.
        For getting all the Project Definitions, `get_all_definitions()` must be used.

    !!! warning
        The signature of `Data.get_definitions()` and `bip.link.attribute.get_definitions`
        are different since `Data.get_definitions()` passes itself to the function as `project=self`.
    """
    return _attribute.get_definitions(self._project, sub_entity=self)

get_group(model, slug=None, uid=None)

Get a child Group from a GroupModel.

The model can be provided as GroupModel object or a slug (str).

The method uses the GroupModel.get_group()

Info

This method only returns Groups that are owned (children) by the Project. For getting the Groups that contains the Project, get_containers() must be used.

Parameters:

Name Type Description Default
model Union[GroupModel, str]

Union[GroupModel, str]: GroupModel (or its slug) to search into.

required
slug Optional[str]

Optional[str]: Slug of a Group. If specified, uid can be left blank. (Default value = None)

None
uid Optional[str]

Optional[str]: Uid of a Group. If specified, slug can be left blank. (Default value = None)

None

Raises:

Type Description
LookupError

No matching GroupModel or Group found.

ValueError

No slug nor uid provided.

Returns:

Name Type Description
Group Group

Matching group.

Source code in client/bip/link/data.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def get_group(
    self,
    model: Union[GroupModel, str],
    slug: Optional[str] = None,
    uid: Optional[str] = None,
) -> Group:
    """Get a child Group from a GroupModel.

    The model can be provided as GroupModel object or a slug (`str`).

    The method uses the `GroupModel.get_group()`

    !!! info
        This method only returns Groups that are owned (children) by the Project.
        For getting the Groups that contains the Project, `get_containers()`  must be used.

    Args:
      model: Union[GroupModel, str]: GroupModel (or its slug) to search into.
      slug: Optional[str]: Slug of a Group. If specified, `uid` can be left blank. (Default value = None)
      uid: Optional[str]: Uid of a Group. If specified, `slug` can be left blank.  (Default value = None)

    Raises:
        LookupError: No matching GroupModel or Group found.
        ValueError: No slug nor uid provided.

    Returns:
        Group: Matching group.
    """
    if isinstance(model, str):
        name = model
        model = self._project.get_group_model(name)

        if not model:
            raise LookupError(f"Unknown GroupModel: {name}")

    return _group.get_child(self, model, slug, uid)

get_groups(model=None)

Get the children Groups from a GroupModel.

The model can be provided as GroupModel object or a slug (str).

The method uses the GroupModel.get_groups()

Info

This method only returns Groups that are owned (children) by the Project. For getting the Groups that contains the Project, get_containers() must be used.

Parameters:

Name Type Description Default
model Optional[Union[GroupModel, str]]

Union[GroupModel, str]: GroupModel (or its slug) to search into.

None

Raises:

Type Description
LookupError

No matching GroupModel or Group found.

Returns:

Name Type Description
list List[Group]

Collection of Groups.

Source code in client/bip/link/data.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def get_groups(self, model: Optional[Union[GroupModel, str]] = None) -> List[Group]:
    """Get the children Groups from a GroupModel.

    The model can be provided as GroupModel object or a slug (`str`).

    The method uses the `GroupModel.get_groups()`

    !!! info
        This method only returns Groups that are owned (children) by the Project.
        For getting the Groups that contains the Project, `get_containers()`  must be used.

    Args:
      model: Union[GroupModel, str]: GroupModel (or its slug) to search into.

    Raises:
        LookupError: No matching GroupModel or Group found.

    Returns:
        list: Collection of Groups.
    """
    if model and isinstance(model, str):
        name = model
        model = self._project.get_group_model(name)

        if not model:
            raise LookupError(f"Unknown GroupModel: {name}")

    return _group.get_children(self, model)

set_attribute(definition, value)

Convenient class implementation of: bip.link.attribute.set_attribute.

Warning

The signature of Data.set_attribute() and bip.link.attribute.set_attribute are different since Data.set_attribute() passes itself to the function as entity=self.

Source code in client/bip/link/data.py
190
191
192
193
194
195
196
197
def set_attribute(self, definition: Union[str, Definition], value):
    """Convenient class implementation of: `bip.link.attribute.set_attribute`.

    !!! warning
        The signature of `Data.set_attribute()` and `bip.link.attribute.set_attribute`
        are different since `Data.set_attribute()` passes itself to the function as `entity=self`.
    """
    return _attribute.set_attribute(definition, self, value)