h5py.alfven.org

HDF5 for Python Documentation

Table Of Contents

Previous topic

Datasets

Next topic

Special types in h5py

This Page

Attributes

Groups and datasets can have small bits of named information attached to them. This is the official way to store metadata in HDF5. Each of these objects has a small proxy object (AttributeManager) attached to it as <obj>.attrs. Attributes have the following properties:

  • They may be created from any scalar or NumPy array
  • Each attribute must be small (recommended < 64k for HDF5 1.6)
  • There is no partial I/O (i.e. slicing); the entire attribute must be read.

They support the same dictionary API as groups.

Reference

class AttributeManager
__getitem__(name) → NumPy scalar or ndarray
Retrieve an attribute given a string name.
__setitem__(name, value)
Set an attribute. Value must be convertible to a NumPy scalar or array.
__delitem__(name)
Delete an attribute.
create(name, data, shape=None, dtype=None)

Create an attribute, initializing it to the given value.

name
Name of the new attribute (required)
data
An array to initialize the attribute. Required.
shape
Shape of the attribute. Overrides data.shape if both are given. The total number of points must be unchanged.
dtype
Data type of the attribute. Overrides data.dtype if both are given. Must be conversion-compatible with data.dtype.
modify(name, value)

Change the value of an attribute while preserving its type.

Differs from __setitem__ in that the type of an existing attribute is preserved. Useful for interacting with externally generated files.

If the attribute doesn't exist, it will be automatically created.

__len__()
Number of attributes
__iter__()
Yields the names of attributes
__contains__(name)
See if the given attribute is present
keys()
Get a list of attribute names
iterkeys()
Get an iterator over attribute names
values()
Get a list with all attribute values
itervalues()
Get an iterator over attribute values
items()
Get an list of (name, value) pairs for all attributes.
iteritems()
Get an iterator over (name, value) pairs
get(name, default)
Return the specified attribute, or default if it doesn't exist.