summary: "Pymemri is a python client for the memri Personal online datastore (pod). This client can be used to build integrators in python. Integrators connect the information in your Pod. They <b>import your data from external services</b> using <i>Importers</i> (Gmail, WhatsApp, etc.), <b>connect new data to the existing data</b> using <i>indexers</i> (face recognition, spam detection, object detection), and <b>execute actions</b> (sending messages, uploading files)."
description: "Pymemri is a python client for the memri Personal online datastore (pod). This client can be used to build integrators in python. Integrators connect the information in your Pod. They <b>import your data from external services</b> using <i>Importers</i> (Gmail, WhatsApp, etc.), <b>connect new data to the existing data</b> using <i>indexers</i> (face recognition, spam detection, object detection), and <b>execute actions</b> (sending messages, uploading files)."
nb_path: "nbs/index.ipynb"
---
<!--
...
...
@@ -69,7 +71,7 @@ description: "Pymemri is a python client for the memri Personal online datastore
<h1id="Quickstart">Quickstart<aclass="anchor-link"href="#Quickstart"></a></h1><p>To use the pymemri <ahref="/pymemri/pod.client#PodClient"><code>PodClient</code></a>, we first need to have a pod running. The quickest way to do this is to install from the <ahref="https://gitlab.memri.io/memri/pod">pod repo</a>, and run <code>./examples/run_development.sh</code> from within that repo.</p>
<h1id="Quickstart">Quickstart<aclass="anchor-link"href="#Quickstart"></a></h1><p>To use the pymemri <ahref="/pymemri/pod.client.html#PodClient"><code>PodClient</code></a>, we first need to have a pod running. The quickest way to do this is to install from the <ahref="https://gitlab.memri.io/memri/pod">pod repo</a>, and run <code>./examples/run_development.sh</code> from within that repo.</p>
<p>In the near future, Pod will support searching by user defined properties as well. This will allow for the following. <strong>warning, this is currently not supported</strong></p>
"In the near future, Pod will support searching by user defined properties as well. This will allow for the following. **warning, this is currently not supported**"
print(f"Failed to start importer on {url}:\n{res.status_code}: {res.text}")
else:
print("Starting importer")
exceptrequests.exceptions.RequestExceptionase:
print("Error with calling importer {e}")
```
%% Cell type:markdown id: tags:
Pymemri communicates with the pod via the `PodClient`. The PodClient requires you to provide a [database key](https://gitlab.memri.io/memri/pod/-/blob/dev/docs/HTTP_API.md#user-content-api-authentication-credentials) and an [owner key](https://gitlab.memri.io/memri/pod/-/blob/dev/docs/HTTP_API.md#user-content-api-authentication-credentials). During development, you don't have to worry about these keys, you can just omit the keys when initializing the `PodClient`, which creates a new user by defining random keys. When you are using the app, setting the keys in the pod, and passing them when calling an integrator is handled for you by the app itself.
%% Cell type:code id: tags:
``` python
client=PodClient()
success=client.test_connection()
assertsuccess
```
%% Output
Succesfully connected to pod
%% Cell type:markdown id: tags:
## Creating Items and Edges
%% Cell type:markdown id: tags:
Now that we have access to the pod, we can create items here and upload them to the pod. All items are defined in the schema of the pod. When Initializing an Item, always make sure to use the from_data classmethod to initialize.
[{'item': Person (#347b3bc8ff2ccadfe132f5e82d770cf1), 'name': 'sender'}]
[{'item': Person (#68ccb3db65306d68be32d13099c3a170), 'name': 'sender'}]
%% Cell type:markdown id: tags:
If we use the normal `client.get` (without `expanded=False`), we also get items directly connected to the Item.
%% Cell type:code id: tags:
``` python
email_from_db=client.get(email_item.id)
```
%% Cell type:code id: tags:
``` python
assertisinstance(email_from_db.sender[0],Person)
```
%% Cell type:markdown id: tags:
# Fetching and updating Items
%% Cell type:markdown id: tags:
## Normal Items
%% Cell type:markdown id: tags:
We can use the client to fetch data from the database. This is in particular useful for indexers, which often use data in the database as input for their models. The simplest form of querying the database is by querying items in the pod by their id (unique identifier).
When we don't know the ids of the items we want to fetch, we can also search by property. We can use this for instance when we want to query all items from a particular type to perform some indexing on. We can get all `Person` Items from the db by:
In the near future, Pod will support searching by user defined properties as well. This will allow for the following. **warning, this is currently not supported**
To work with files, the `PodClient` has a file api. The file api works by posting a blob to the `upload_file` endpoint, and creating an Item with a property with the same sha256 as the sha used in the endpoint.
%% Cell type:code id: tags:
``` python
from pymemri.data.photo import *
```
%% Cell type:code id: tags:
``` python
x = np.random.randint(0, 255+1, size=(640, 640), dtype=np.uint8)
photo = IPhoto.from_np(x)
file = photo.file[0]
succes = client.create(file)
succes2 = client.upload_photo(x)
assert succes
assert succes2
```
%% Cell type:code id: tags:
``` python
data = client.get_file(file.sha256)
arr = np.frombuffer(data, dtype=np.uint8)
assert (arr.reshape(640,640) == x).all()
```
%% Cell type:markdown id: tags:
### Photo API
%% Cell type:markdown id: tags:
For photos we do this automatically using `PodClient.create` on a Photo and `PodClient.get_photo`:
%% Cell type:code id: tags:
``` python
x = np.random.randint(0, 255+1, size=(640, 640), dtype=np.uint8)