# collection

Python API: `depthai_nodes.message.collection`

## Classes

### Collection

Store a list of items of one runtime type in a DepthAI message.

The first item establishes the accepted type. Later assignments, appends, and extensions must contain instances of that type. An
initially empty collection infers its type when the first item is added.

Parameters

 * `items`: Initial list of items.

Raises

 * `TypeError`: If `items` is not a list or contains incompatible item types.

#### Methods

##### init

```python
def __init__(items: list[T]):
```

Initialize the collection and infer its runtime item type.

Parameters

 * `items` (`list[T]`): Initial items. An empty list defers type inference until the first insertion.

##### append

```python
def append(item: T):
```

Append one item, inferring the type if necessary.

Parameters

 * `item` (`T`): Item compatible with the type of the first item ever inserted.

Raises

 * `TypeError`: If the item is incompatible with the inferred runtime type.

##### copy

```python
def copy(self) -> Collection:
```

Copy items and preserve container timestamps and sequence number.

Returns

 * `Collection`: A new `Collection` with items copied through `copy_message`. This returns the base container even when called on
   a subclass; subclass-specific fields are not copied.

Raises

 * `TypeError`: If an item cannot be copied by `copy_message`.

##### extend

```python
def extend(items: list[T]):
```

Append items after validating the combined list.

Parameters

 * `items` (`list[T]`): Items to append. Existing contents remain unchanged if validation fails.

Raises

 * `TypeError`: If any item is incompatible with the inferred runtime type.

##### items.setter

```python
def items.setter(value: list[T]):
```

Replace the item list after checking runtime types.

Parameters

 * `value` (`list[T]`): Replacement list. An empty list preserves the previously inferred item type.

Raises

 * `TypeError`: If the value is not a list or contains items incompatible with the inferred type.

#### Attributes

##### item_cls

The inferred runtime type for items, once known.

##### items

Return the stored list of items.

The list is mutable. Direct list mutations bypass collection type checks; use `append()`, `extend()`, or assignment to `items`
when validation is needed.

## Attributes

### T
