hdmf.container module

class hdmf.container.HERDManager

Bases: object

This class manages whether to set/attach an instance of HERD to the subclass.

Method to attach an instance of HERD in order to auto-add terms/references to data.


herd (HERD) – The external resources to be used for the container.

class hdmf.container.AbstractContainer(name)

Bases: object


name (str) – the name of this container

property data_type

Return the spec data type associated with this container.

classmethod get_fields_conf()
property read_io

The HDMFIO object used for reading the container.

This property will typically be None if this Container is not a root Container (i.e., if parent is not None). Use get_read_io instead if you want to retrieve the HDMFIO object used for reading from the parent container.


Get the io object used to read this container.

If self.read_io is None, this function will iterate through the parents and return the first io object found on a parent container


The HDMFIO object used to read this container. Returns None in case no io object is found, e.g., in case this container has not been read from file.

property name

The name of this Container


Traverse parent hierarchy and return first instance of the specified data_type


data_type (str) – the data_type to search for


Get a list of all child objects and their child objects recursively.

If the object has an object_id, the object will be added to “ret” to be returned. If that object has children, they will be added to the “stack” in order to be: 1) Checked to see if has an object_id, if so then add to “ret” 2) Have children that will also be checked

property all_objects

Get a LabelledDict that indexed all child objects and their children by object ID.

property fields

Subclasses use this class attribute to add properties to autogenerate. fields allows for lists and for dicts with the keys {‘name’, ‘child’, ‘required_name’, ‘doc’, ‘settable’}. 1. name: The name of the field property 2. child: A boolean value to set the parent/child relationship between the field property and the container. 3. required_name: The name the field property must have such that name matches required_name. 4. doc: Documentation of the field property 5. settable: If true, a setter function is created so that the field can be changed after creation.

property object_id

Changes the object ID of this Container and all of its children to a new UUID string.


recurse (bool) – whether or not to change the object ID of this container’s children

property modified

modified (bool) – whether or not this Container has been modified

property children

child (Container) – the child Container for this Container

classmethod type_hierarchy()
property container_source

The source of this Container

property parent

The parent Container of this Container


Reset the parent of this Container to None and remove the Container from the children of its parent.

Use with caution. This can result in orphaned containers and broken links.

class hdmf.container.Container(name)

Bases: AbstractContainer

A container that can contain other containers and has special functionality for printing.


name (str) – the name of this container

property css_style: str

CSS styles for the HTML representation.

property js_script: str

JavaScript for the HTML representation.

set_data_io(dataset_name: str, data_io_class: Type[DataIO], data_io_kwargs: dict | None = None, **kwargs)

Apply DataIO object to a dataset field of the Container.

  • dataset_name (str) – Name of dataset to wrap in DataIO

  • data_io_class (Type[DataIO]) – Class to use for DataIO, e.g. H5DataIO or ZarrDataIO

  • data_io_kwargs (dict) – keyword arguments passed to the constructor of the DataIO class.

  • **kwargs – DEPRECATED. Use data_io_kwargs instead. kwargs are passed to the constructor of the DataIO class.

data_type = 'Container'
namespace = 'hdmf-common'
class hdmf.container.Data(name, data)

Bases: AbstractContainer

A class for representing dataset containers

property data
property shape

Get the shape of the data represented by this container :return: Shape tuple :rtype: tuple of ints


Apply DataIO object to the data held by this Data object


dataio (DataIO) – the DataIO to apply to the data held by this Data

set_data_io(data_io_class: Type[DataIO], data_io_kwargs: dict) None

Apply DataIO object to the data held by this Data object.

  • data_io_class (Type[DataIO]) – The DataIO to apply to the data held by this Data.

  • data_io_kwargs (dict) – The keyword arguments to pass to the DataIO.


Transform data from the current underlying state.

This function can be used to permanently load data from disk, or convert to a different representation, such as a torch.Tensor


func (function) – a function to transform data


The extend_data method adds all the elements of the iterable arg to the end of the data of this Data container.


arg – The iterable to add to the end of this VectorData

data_type = 'Data'
namespace = 'hdmf-common'
class hdmf.container.DataRegion(name, data)

Bases: Data

abstract property data

The target data that this region applies to

abstract property region

The region that indexes into data e.g. slice or list of indices

class hdmf.container.MultiContainerInterface(name)

Bases: Container

Class that dynamically defines methods to support a Container holding multiple Containers of the same type.

To use, extend this class and create a dictionary as a class attribute with any of the following keys: * ‘attr’ to name the attribute that stores the Container instances * ‘type’ to provide the Container object type (type or list/tuple of types, type can be a docval macro) * ‘add’ to name the method for adding Container instances * ‘get’ to name the method for getting Container instances * ‘create’ to name the method for creating Container instances (only if a single type is specified)

If the attribute does not exist in the class, it will be generated. If it does exist, it should behave like a dict.

The keys ‘attr’, ‘type’, and ‘add’ are required.


name (str) – the name of this container

class hdmf.container.Row

Bases: object

A class for representing rows from a Table.

The Table class can be indicated with the __table__. Doing so will set constructor arguments for the Row class and ensure that Row.idx is set appropriately when a Row is added to the Table. It will also add functionality to the Table class for getting Row objects.

Note, the Row class is not needed for working with Table objects. This is merely convenience functionality for working with Tables.

property idx

The index of this row in its respective Table

property table

The Table this Row comes from

class hdmf.container.RowGetter(table)

Bases: object

A simple class for providing __getitem__ functionality that returns Row objects to a Table.

class hdmf.container.Table(columns, name, data=[])

Bases: Data

Subclasses should specify the class attribute __columns__.

This should be a list of dictionaries with the following keys:

  • name the column name

  • type the type of data in this column

  • doc a brief description of what gets stored in this column

For reference, this list of dictionaries will be used with docval to autogenerate the add_row method for adding data to this table.

If __columns__ is not specified, no custom add_row method will be added.

The class attribute __defaultname__ can also be set to specify a default name for the table class. If __defaultname__ is not specified, then name will need to be specified when the class is instantiated.

A Table class can be paired with a Row class for conveniently working with rows of a Table. This pairing must be indicated in the Row class implementation. See Row for more details.

property columns

values (dict) – the values for each column


Query a table


Produce a pandas DataFrame containing this table’s data.

classmethod from_dataframe(df, name=None, extra_ok=False)
Construct an instance of Table (or a subclass) from a pandas DataFrame. The columns of the dataframe

should match the columns defined on the Table subclass.

  • df (DataFrame) – input data

  • name (str) – the name of this container

  • extra_ok (bool) – accept (and ignore) unexpected columns on the input dataframe