File: attributes.rst

package info (click to toggle)
zarr 3.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,816 kB
  • sloc: python: 21,300; makefile: 215; javascript: 15
file content (30 lines) | stat: -rw-r--r-- 807 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.. _user-guide-attrs:

Working with attributes
=======================

Zarr arrays and groups support custom key/value attributes, which can be useful for
storing application-specific metadata. For example::

   >>> import zarr
   >>> store = zarr.storage.MemoryStore()
   >>> root = zarr.create_group(store=store)
   >>> root.attrs['foo'] = 'bar'
   >>> z = root.create_array(name='zzz', shape=(10000, 10000), dtype='int32')
   >>> z.attrs['baz'] = 42
   >>> z.attrs['qux'] = [1, 4, 7, 12]
   >>> sorted(root.attrs)
   ['foo']
   >>> 'foo' in root.attrs
   True
   >>> root.attrs['foo']
   'bar'
   >>> sorted(z.attrs)
   ['baz', 'qux']
   >>> z.attrs['baz']
   42
   >>> z.attrs['qux']
   [1, 4, 7, 12]

Internally Zarr uses JSON to store array attributes, so attribute values must be
JSON serializable.