Sessions¶
Interaction with qalx
should be performed in the context of a session. This ensures that all the actions are configured and authenticated consistently.
We can create a QalxSession object and then use that to perform operations on the platform.
Let’s create a session.
>>> from pyqalx import QalxSession
>>> qalx = QalxSession()
We can now use the item
property on the qalx
object to add some data:
>>> item_1 = qalx.item.add(data={"some":"data", "number":1})
>>> item_2 = qalx.item.add(data={"some":"data", "number":2})
>>> item_3 = qalx.item.add(data={"some":"data", "number":3})
>>> truth = qalx.item.add(data={"news":True})
>>> fake = qalx.item.add(data={"news":False})
This will add five items to qalx and leave us with five Item entities. We can use these to make sets of data.
>>> set_1 = qalx.set.add(items={"number":item_1, "news":fake})
>>> set_2 = qalx.set.add(items={"number":item_2, "news":truth})
>>> set_3 = qalx.set.add(items={"number":item_3, "news":truth})
Now we’ve added some sets. What if we now change some data in the original items.
>>> item_1.data.some = 'thing'
We save the update to qalx:
>>> item_1 = qalx.item.save(item_1)
Now let’s make a queue and add these sets:
>>> q = qalx.queue.get_or_create("my-session-docs-queue")
>>> Set.add_to_queue(payload=set_1, queue=q)
>>> Set.add_to_queue(payload=set_2, queue=q)
>>> Set.add_to_queue(payload=set_3, queue=q)
Now any bots that are set up to read from this queue will messages about these sets.
For more details on reading items back from qalx
see Searching and Sorting.