User management
Helpers for resolving, looking up, and creating users. These live undercognee.modules.users.methods and are async, so await them.
Methods
get_default_user()
remember(), recall(), etc. without passing user=.
The default email comes from DEFAULT_USER_EMAIL (falls back to default_user@example.com); the password comes from DEFAULT_USER_PASSWORD. When that is unset the user is created with no password — usable by every SDK and CLI call, but not loginable over POST /api/v1/auth/login. There is no fallback password; see Default user credentials. The auto-created default user is a superuser. See the Users concept page for the environment variables.
get_user()
EntityNotFoundError if no user matches.
get_user_by_email()
User object, or None if no user has that email — use this for existence checks (see below).
get_user_id_by_email()
requester may see that user: the requester themselves, members of the requester’s tenants, or, for a requester in no tenant, users in no tenant. Otherwise it returns None, whether or not the address exists, so the lookup cannot be used to probe which emails are registered across tenants.
Over HTTP,
POST /api/v1/users/get-user-id applies the same rule with the authenticated caller as requester and returns 404 for any address outside that scope.
create_user()
fastapi_users.exceptions.UserAlreadyExists if a user with that email already exists.
There is no global “list all users” helper. To enumerate the users in a tenant, use
get_users_in_tenant(tenant_id, user) from cognee.modules.users.tenants.methods; the requesting user must have user-management permission on that tenant. It returns a list of dicts with id, email, and roles.Examples
Check if a user exists before creating
Check if a user exists before creating
get_user_by_email() returns None when no user matches, so you can check existence without a try/except:UserAlreadyExists:Get the default user and pass it to operations
Get the default user and pass it to operations
user= is omitted, so calling get_default_user() explicitly is only needed when you want the User object itself.Create an agent user owned by a parent
Create an agent user owned by a parent
Pass See Users for how parent/child permission inheritance works.
parent_user_id so the parent user inherits permissions on datasets the agent creates: