Skip to content

Commit bd24e01

Browse files
committed
add documentation
1 parent e60ea73 commit bd24e01

File tree

1 file changed

+51
-14
lines changed

1 file changed

+51
-14
lines changed

python/doc/source/plasma.rst

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,46 @@ follows:
9898
def random_object_id():
9999
return plasma.ObjectID(np.random.bytes(20))
100100
101+
Putting and Getting Python Objects
102+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101103

102-
Creating an Object
103-
^^^^^^^^^^^^^^^^^^
104+
Plasma supports two APIs for creating and accessing objects: A high level
105+
API that allows storing and retrieving Python objects and a low level
106+
API that allows creating, writing and sealing buffers and operating on
107+
the binary data directly. In this section we describe the high level API.
108+
109+
This is how you can put and get a Python object:
110+
111+
.. code-block:: python
112+
113+
# Create a python object.
114+
object_id = client.put("hello, world")
115+
116+
# Get the object.
117+
client.get(object_id)
118+
119+
This works with all Python objects supported by the Arrow Python object
120+
serialization.
121+
122+
You can also get multiple objects at the same time (which can be more
123+
efficient since it avoids IPC round trips):
124+
125+
.. code-block:: python
126+
127+
# Create multiple python objects.
128+
object_id1 = client.put(1)
129+
object_id2 = client.put(2)
130+
object_id3 = client.put(3)
131+
132+
# Get the objects.
133+
client.get([object_id1, object_id2, object_id3])
134+
135+
Furthermore, it is possible to provide a timeout for the get call. If the
136+
object is not available within the timeout, the special object
137+
`pyarrow.ObjectNotAvailable` will be returned.
138+
139+
Creating an Object Buffer
140+
^^^^^^^^^^^^^^^^^^^^^^^^^
104141

105142
Objects are created in Plasma in two stages. First, they are **created**, which
106143
allocates a buffer for the object. At this point, the client can write to the
@@ -111,7 +148,7 @@ give the object's maximum size in bytes.
111148

112149
.. code-block:: python
113150
114-
# Create an object.
151+
# Create an object buffer.
115152
object_id = plasma.ObjectID(20 * b"a")
116153
object_size = 1000
117154
buffer = memoryview(client.create(object_id, object_size))
@@ -129,11 +166,11 @@ immutable, and making it available to other Plasma clients.
129166
client.seal(object_id)
130167
131168
132-
Getting an Object
133-
^^^^^^^^^^^^^^^^^
169+
Getting an Object Buffer
170+
^^^^^^^^^^^^^^^^^^^^^^^^
134171

135172
After an object has been sealed, any client who knows the object ID can get
136-
the object.
173+
the object buffer.
137174

138175
.. code-block:: python
139176
@@ -143,11 +180,11 @@ the object.
143180
144181
# Get the object in the second client. This blocks until the object has been sealed.
145182
object_id2 = plasma.ObjectID(20 * b"a")
146-
[buffer2] = client2.get([object_id])
183+
[buffer2] = client2.get_buffers([object_id])
147184
148-
If the object has not been sealed yet, then the call to client.get will block
149-
until the object has been sealed by the client constructing the object. Using
150-
the ``timeout_ms`` argument to get, you can specify a timeout for this (in
185+
If the object has not been sealed yet, then the call to client.get_buffers will
186+
block until the object has been sealed by the client constructing the object.
187+
Using the ``timeout_ms`` argument to get, you can specify a timeout for this (in
151188
milliseconds). After the timeout, the interpreter will yield control back.
152189

153190
.. code-block:: shell
@@ -223,7 +260,7 @@ To read the object, first retrieve it as a ``PlasmaBuffer`` using its object ID.
223260
.. code-block:: python
224261
225262
# Get the arrow object by ObjectID.
226-
[buf2] = client.get([object_id])
263+
[buf2] = client.get_buffers([object_id])
227264
228265
To convert the ``PlasmaBuffer`` back into an Arrow ``Tensor``, first create a
229266
pyarrow ``BufferReader`` object from it. You can then pass the ``BufferReader``
@@ -310,13 +347,13 @@ Since we store the Pandas DataFrame as a PyArrow ``RecordBatch`` object,
310347
to get the object back from the Plasma store, we follow similar steps
311348
to those specified in `Getting Arrow Objects from Plasma`_.
312349

313-
We first have to convert the ``PlasmaBuffer`` returned from ``client.get``
314-
into an Arrow ``BufferReader`` object.
350+
We first have to convert the ``PlasmaBuffer`` returned from
351+
``client.get_buffers`` into an Arrow ``BufferReader`` object.
315352

316353
.. code-block:: python
317354
318355
# Fetch the Plasma object
319-
[data] = client.get([object_id]) # Get PlasmaBuffer from ObjectID
356+
[data] = client.get_buffers([object_id]) # Get PlasmaBuffer from ObjectID
320357
buffer = pa.BufferReader(data)
321358
322359
From the ``BufferReader``, we can create a specific ``RecordBatchStreamReader``

0 commit comments

Comments
 (0)