@@ -9,30 +9,28 @@ API enables concurrent I/O and parallel processing using a managed thread pool.
99When operating in an async context, it can be used to provide asynchronous
1010access to Zarr data.
1111
12- The usage of the async API mirrors the synchronous API.
13-
14- .. ipython :: python
15-
16- import asyncio
17- import numpy as np
18- import zarr.api.asynchronous as async_zarr
19-
20- # create a new group using the asynchronous API
21- root = await async_zarr.create_group(attributes = {' foo' : ' bar' })
22- root
23- # create an array using the AsyncGroup
24- z = await root.create_array(name = ' foo' , shape = (100 , ), chunks = (5 , ), dtype = np.uint32)
25- z
26- # set and get items
27- await z.setitem((slice (None ), ), np.arange(0 , 100 , dtype = z.dtype))
28- # set a single item
29- await z.setitem((7 ,), - 99 )
30- # set a range to a constant value using a slice
31- await z.setitem(slice (0 , 3 ), - 1 )
32- # get a slice of the array
33- await z.getitem((slice (0 , 5 ), ))
34- # gather multiple items concurrently
35- await asyncio.gather(z.getitem(slice (0 , 5 )), z.getitem(slice (6 , 10 )))
12+ The usage of the async API mirrors the synchronous API::
13+
14+ >>> import asyncio
15+ >>> import numpy as np
16+ >>> import zarr.api.asynchronous as async_zarr
17+ >>>
18+ >>> # create a new group using the asynchronous API
19+ >>> root = await async_zarr.create_group(attributes={'foo': 'bar'})
20+ >>> root
21+ >>> # create an array using the AsyncGroup
22+ >>> z = await root.create_array(name='foo', shape=(100, ), chunks=(5, ), dtype=np.uint32)
23+ >>> z
24+ >>> # set and get items
25+ >>> await z.setitem((slice(None), ), np.arange(0, 100, dtype=z.dtype))
26+ >>> # set a single item
27+ >>> await z.setitem((7,), -99)
28+ >>> # set a range to a constant value using a slice
29+ >>> await z.setitem(slice(0, 3), -1)
30+ >>> # get a slice of the array
31+ >>> await z.getitem((slice(0, 5), ))
32+ >>> # gather multiple items concurrently
33+ >>> await asyncio.gather(z.getitem(slice(0, 5)), z.getitem(slice(6, 10)))
3634
3735See the API docs for more details:
3836
0 commit comments