---
title: DataBin (latest version)
description: API reference for qiskit.primitives.DataBin in the latest version of qiskit
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.primitives.DataBin
---

# DataBin

*class* `qiskit.primitives.DataBin(*, shape=(), **data)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/data_bin.py#L33-L171)

Bases: `ShapedMixin`

The main data return from a single pub out of [`PubResult`](/docs/api/qiskit/qiskit.primitives.PubResult "qiskit.primitives.PubResult").

You access the data within this object either by attribute access (`data_bin.my_field`) or by [`dict`](https://docs.python.org/3/library/stdtypes.html#dict)-like string keys (`data_bin["my_field"]`). This class behaves as a Python immutable mapping, so you can (for example) query the available keys with [`keys()`](#qiskit.primitives.DataBin.keys "qiskit.primitives.DataBin.keys"), and iterate through both keys and values with [`items()`](#qiskit.primitives.DataBin.items "qiskit.primitives.DataBin.items").

This class will have different attributes and keys, depending on the primitive used and the pub submitted. These “special” attributes will have names that match the keys. For example, if you submitted a `SamplerV2` job, typically the attributes and keys are the names of the [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") objects that were in the circuit defining this pub.

All of the attributes and keys have the same shape associated with them, which is the n-dimensional shape of the corresponding pub. The attributes and keys will typically either be [`BitArray`](/docs/api/qiskit/qiskit.primitives.BitArray "qiskit.primitives.BitArray") or [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) instances, depending on the primitive used and the input pub.

Users do not typically construct this class themselves. Instead, you receive it as the [`PubResult.data`](/docs/api/qiskit/qiskit.primitives.PubResult#data "qiskit.primitives.PubResult.data") field for a single pub’s result out of a complete execution.

Examples:

```python
import numpy as np
from qiskit.primitives import DataBin, BitArray

data = DataBin(
    alpha=BitArray.from_samples(["0010"]),
    beta=np.array([1.2])
)

print("alpha data:", data.alpha)
print("beta data:", data.beta)
```

```python
alpha data: BitArray(<shape=(), num_shots=1, num_bits=2>)
beta data: [1.2]
```

**Parameters**

- **data** – Name/value data to place in the data bin.
- **shape** (*ShapeInput*) – The leading shape common to all entries in the data bin. This defaults to the trivial leading shape of `()` that is compatible with all objects.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If a name overlaps with a method name on this class.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If some value is inconsistent with the provided shape.

## Attributes

### ndim

### shape

### size

## Methods

### items

`items()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/data_bin.py#L153-L155)

Return a view of field names and values

**Return type**

[*ItemsView*](https://docs.python.org/3/library/collections.abc.html#collections.abc.ItemsView)\[[str](https://docs.python.org/3/library/stdtypes.html#str), [*Any*](https://docs.python.org/3/library/typing.html#typing.Any)]

### keys

`keys()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/data_bin.py#L145-L147)

Return a view of field names.

**Return type**

[*KeysView*](https://docs.python.org/3/library/collections.abc.html#collections.abc.KeysView)\[[str](https://docs.python.org/3/library/stdtypes.html#str)]

### values

`values()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/data_bin.py#L149-L151)

Return a view of values.

**Return type**

[*ValuesView*](https://docs.python.org/3/library/collections.abc.html#collections.abc.ValuesView)\[[*Any*](https://docs.python.org/3/library/typing.html#typing.Any)]
