From d1c5c70b4c6c3c8a897fb7e1b395c2a285e657bc Mon Sep 17 00:00:00 2001 From: Deshraj Yadav Date: Fri, 9 Aug 2024 00:27:54 -0700 Subject: [PATCH] [Mem0] Add support for getting all users in python client (#1672) --- docs/platform/quickstart.mdx | 53 ++++++++++++++++++++++++++++++++++++ mem0/client/main.py | 8 ++++++ pyproject.toml | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index d16b60a3..d5b1a88f 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -230,6 +230,59 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \ ``` + +### 4.3 Get all users + +Get all users, agents, and sessions for which memories exist. + + + +```python Python +client.users() +``` + +```javascript JavaScript +client.users() + .then(users => console.log(users)) + .catch(error => console.error(error)); +``` + +```bash cURL +curl -X GET "https://api.mem0.ai/v1/entities/" \ + -H "Authorization: Token your-api-key" +``` + + +```json Output +[ + { + "id": "1", + "name": "user123", + "created_at": "2024-07-17T16:47:23.899900-07:00", + "updated_at": "2024-07-17T16:47:23.899918-07:00", + "total_memories": 5, + "owner": "alex", + "organization": "alex-org", + "metadata": {"foo": "bar"}, + "type": "user" + }, + { + "id": "2", + "name": "travel-agent", + "created_at": "2024-07-01T17:59:08.187250-07:00", + "updated_at": "2024-07-01T17:59:08.187266-07:00", + "total_memories": 10, + "owner": "alex", + "organization": "alex-org", + "metadata": {"agent_id": "123"}, + "type": "agent" + } +] +``` + + + + ### 4.3 Get All Memories Fetch all memories for a user, agent, or session using the getAll() method. diff --git a/mem0/client/main.py b/mem0/client/main.py index 058a9e57..33fae583 100644 --- a/mem0/client/main.py +++ b/mem0/client/main.py @@ -237,6 +237,14 @@ class MemoryClient: capture_client_event("client.history", self) return response.json() + @api_error_handler + def users(self): + """Get all users, agents, and sessions for which memories exist.""" + response = self.client.get("/entities/") + response.raise_for_status() + capture_client_event("client.users", self) + return response.json() + def reset(self): """Reset the client. (Not implemented) diff --git a/pyproject.toml b/pyproject.toml index 8ded7512..c8c2283f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mem0ai" -version = "0.0.14" +version = "0.0.15" description = "Long-term memory for AI Agents" authors = ["Mem0 "] exclude = [