Community SDK Installation

Zep provides SDKs for Python, TypeScript, and Go.

Python

This is the guide for installing sdks for Zep Community Edition (>=v1.0.0).

If you are using Zep Cloud, please refer to the Zep Cloud SDK Installation guide.

If you are using an older version of Zep Open Source, please refer to Legacy SDK Installation guide and consider upgrading to the latest version.

1pip install zep-python

TypeScript

1npm install @getzep/zep-js

Initialize Client

The default base URL for the Zep client is http://localhost:8000.

Zep also offers an async client for Python. To use the async client, import AsyncZep instead of Zep.

1import os
2from zep_python.client import Zep
3
4API_KEY = os.environ.get('ZEP_API_KEY')
5BASE_URL = os.environ.get('ZEP_BASE_URL')
6
7client = Zep(
8 api_key=API_KEY,
9 base_url=BASE_URL
10)

The Python SDK Supports Async Use

In order to use async client, you will need to import AsyncZep instead of Zep.

1from zep_python.client import AsyncZep

Usage Example

1import uuid
2from zep_python.client import AsyncZep
3from zep_python.types import Message
4
5client = AsyncZep(
6 api_key=API_KEY,
7 base_url=BASE_URL,
8)
9
10user_id = uuid.uuid4().hex # A new user identifier
11new_user = await client.user.add(
12 user_id=user_id,
13 email="[email protected]",
14 first_name="Jane",
15 last_name="Smith",
16 metadata={"foo": "bar"},
17)
18
19# create a chat session
20session_id = uuid.uuid4().hex # A new session identifier
21session = await client.memory.add_session(
22 session_id=session_id,
23 user_id=user_id,
24 metadata={"foo" : "bar"}
25)
26
27# Add a memory to the session
28await client.memory.add_memory(
29 session_id=session_id,
30 messages=[
31 Message(
32 role_type = "user", # One of ("system", "assistant", "user", "function", "tool")
33 role = "Researcher", # Optional, a use case specific string representing the role of the user
34 content = "Who was Octavia Butler?", # The message content
35 )
36 ],
37)
38
39# Get session memory
40memory = await client.memory.get(session_id=session_id)
41messages = memory.messages # List of messages in the session (quantity determined by optional lastn parameter in memory.get)
42relevant_facts = memory.relevant_facts # List of facts relevant to the recent messages in the session
43
44# Search user facts across all sessions
45search_response = await client.memory.search_sessions(
46 user_id=user_id,
47 search_scope="facts",
48 text="What science fiction books did I recently read?",
49)
50facts = [r.fact for r in search_response.results]