A User represents an individual interacting with your application. Each User can have multiple Sessions associated with them, allowing you to track and manage the interactions of a user over time.

The unique identifier for each user is their UserID. This can be any string value - for example, it could be a username, an email address, or a UUID. You can also store additional data related to the user in the metadata field.

The User object and its associated Sessions provide a powerful way to manage and understand the behavior of individuals using your application. By associating Sessions with Users, you can track the progression of conversations and interactions over time, providing valuable context and history.

In the following sections, you will learn how to manage Users and their associated Sessions.

Users Enable Simple User Privacy Management

By associating a User with a Session, you can delete all Sessions and session artifacts associated with a User with a single API call.

The User model

You can associate rich business context with a User:

  • user_id: A unique identifier of the user that maps to your internal User ID.
  • email: The user’s email.
  • first_name: The user’s first name.
  • last_name: The user’s last name.
  • metadata: Any additional data associated with the user.

Adding a User

You can add a new user by providing the user details.

1from zep_cloud.client import AsyncZep
2
3client = AsyncZep(api_key=API_KEY)
4
5new_user = await client.user.add(
6 user_id=user_id,
7 email="[email protected]",
8 first_name="Jane",
9 last_name="Smith",
10 metadata={"foo": "bar"},
11)

Learn how to associate Sessions with Users

Getting a User

You can retrieve a user by their ID.

1user = await client.user.get("user123")

Updating a User

You can update a user’s details by providing the updated user details.

1updated_user = await client.user.update(
2 user_id=user_id,
3 email="[email protected]",
4 first_name="Jane",
5 last_name="Smith",
6 metadata={"foo": "updated_bar"},
7)

Deleting a User

You can delete a user by their ID.

1await client.user.delete("user123")

Getting a User’s Sessions

You can retrieve all Sessions for a user by their ID.

1sessions = await client.user.get_sessions("user123")

Listing Users

You can list all users, with optional limit and cursor parameters for pagination.

1# List the first 10 users
2result = await client.user.list_ordered(page_size=10, page_number=1)