Skip to content

Commit 5c1916a

Browse files
committed
docs: add docs on using asyncio with zarr
1 parent 01bc352 commit 5c1916a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

docs/user-guide/async.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Async Zarr
3+
==========
4+
5+
Zarr-Python 3 added a new asynchronous API for reading and writing data using `asyncio`.
6+
7+
The usage of the async API mirrors the synchronous API.
8+
9+
.. ipython:: python
10+
11+
import asyncio
12+
import numpy as np
13+
import zarr.api.asynchronous as async_zarr
14+
15+
# create a new group using the asynchronous API
16+
root = await async_zarr.group(attributes={'foo': 'bar'})
17+
root
18+
# create an array using the AsyncGroup
19+
z = await root.create_array(name='foo', shape=(100, ), chunks=(5, ), dtype='i4')
20+
z
21+
# set and get items
22+
await z.setitem((slice(None), ), np.arange(0, 100, dtype=z.dtype))
23+
# set a single item
24+
await z.setitem((7,), -99)
25+
# set a range to a constant value using a slice
26+
await z.setitem(slice(0, 3), -1)
27+
# get a slice of the array
28+
await z.getitem((slice(0, 5), ))
29+
# gather multiple items concurrently
30+
await asyncio.gather(z.getitem(slice(0, 5)), z.getitem(slice(6, 10)))
31+
32+
See the API docs for more details:
33+
34+
* :mod:`zarr.api.asynchronous`
35+
* :class:`zarr.AsyncArray`
36+
* :class:`zarr.AsyncGroup`

docs/user-guide/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ Advanced Topics
2323
:maxdepth: 1
2424

2525
performance
26+
async
2627
consolidated_metadata
2728
whatsnew_v3
2829
v3_todos
2930

3031

3132
.. Coming soon
32-
async
3333
extending

0 commit comments

Comments
 (0)