> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Users

> SDK methods to list, retrieve, and manage users within a TrueFoundry tenant.

## Methods

<Accordion title="list">
  List all users of tenant filtered by query and showInvalidUsers. Pagination is available based on query parameters.

  #### Parameters

  <ParamField body="limit" type="typing.Optional[int]">
    Number of items per page
  </ParamField>

  <ParamField body="offset" type="typing.Optional[int]">
    Number of items to skip
  </ParamField>

  <ParamField body="query" type="typing.Optional[str]" />

  <ParamField body="show_invalid_users" type="typing.Optional[bool]">
    Show Deactivated users
  </ParamField>

  #### Returns

  <ResponseField name="SyncPager[User, ListUsersResponse]" type="SyncPager[User, ListUsersResponse]">
    [🔗 ListUsersResponse](/docs/truefoundry_sdk/types#listusersresponse)

    Returns all users of tenant and also the response includes paginated data.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.list(
      limit=10,
      offset=10,
      query="value",
      show_invalid_users="value",
  )

  # Iterate through results
  for item in response:
      print(item.name)

  # Or paginate page by page
  for page in response.iter_pages():
      for item in page:
          print(item.name)
  ```
</Accordion>

<Accordion title="pre_register_users">
  This endpoint allows tenant administrators to register users within their tenant.

  #### Parameters

  <ParamField body="email" type="str" required>
    Email of the user
  </ParamField>

  <ParamField body="send_invite_email" type="typing.Optional[bool]">
    Send invite email if user does not exist
  </ParamField>

  <ParamField body="skip_if_user_exists" type="typing.Optional[bool]">
    Fail if user exists
  </ParamField>

  <ParamField body="dry_run" type="typing.Optional[bool]">
    Dry run
  </ParamField>

  <ParamField body="accept_invite_client_url" type="typing.Optional[str]">
    Url to redirect when invite is accepted
  </ParamField>

  #### Returns

  <ResponseField name="RegisterUsersResponse" type="RegisterUsersResponse">
    [🔗 RegisterUsersResponse](/docs/truefoundry_sdk/types#registerusersresponse)

    The users have been successfully registered.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.pre_register_users(
      email="value",
      send_invite_email="value",
      skip_if_user_exists="value",
      dry_run=False,
      accept_invite_client_url="value",
  )
  ```
</Accordion>

<Accordion title="update_roles">
  This endpoint allows tenant administrators to update the roles of a user within their tenant.

  #### Parameters

  <ParamField body="email" type="str" required>
    Email of the user
  </ParamField>

  <ParamField body="roles" type="typing.Sequence[str]" required>
    Role names for the user
  </ParamField>

  <ParamField body="resource_type" type="typing.Optional[str]">
    Resource Type
  </ParamField>

  #### Returns

  <ResponseField name="UpdateUserRolesResponse" type="UpdateUserRolesResponse">
    [🔗 UpdateUserRolesResponse](/docs/truefoundry_sdk/types#updateuserrolesresponse)

    The user roles have been successfully updated.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.update_roles(
      email="value",
      roles="value",
      resource_type="value",
  )
  ```
</Accordion>

<Accordion title="get">
  Get User associated with provided User id

  #### Parameters

  <ParamField body="id" type="str" required>
    User Id
  </ParamField>

  #### Returns

  <ResponseField name="GetUserResponse" type="GetUserResponse">
    [🔗 GetUserResponse](/docs/truefoundry_sdk/types#getuserresponse)

    Returns the User associated with provided User id
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.get(
      id="id_value",
  )
  ```
</Accordion>

<Accordion title="delete">
  Delete user if they are not a collaborator in any resource and not part of any team other than everyone.

  #### Parameters

  <ParamField body="id" type="str" required>
    User Id
  </ParamField>

  <ParamField body="tenant_name" type="typing.Optional[str]">
    Tenant name
  </ParamField>

  #### Returns

  <ResponseField name="DeleteUserResponse" type="DeleteUserResponse">
    [🔗 DeleteUserResponse](/docs/truefoundry_sdk/types#deleteuserresponse)

    User has been successfully deleted.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.delete(
      id="id_value",
      tenant_name="value",
  )
  ```
</Accordion>

<Accordion title="invite_user">
  Invite a user to the tenant

  #### Parameters

  <ParamField body="accept_invite_client_url" type="str" required>
    Url to redirect when invite is accepted
  </ParamField>

  <ParamField body="email" type="str" required>
    Email of user
  </ParamField>

  #### Returns

  <ResponseField name="InviteUserResponse" type="InviteUserResponse">
    [🔗 InviteUserResponse](/docs/truefoundry_sdk/types#inviteuserresponse)

    User has been successfully invited.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.invite_user(
      accept_invite_client_url="value",
      email="value",
  )
  ```
</Accordion>

<Accordion title="deactivate">
  Deactivate user associated with the provided email within the tenant.

  #### Parameters

  <ParamField body="email" type="str" required>
    Email of the user
  </ParamField>

  <ParamField body="tenant_name" type="typing.Optional[str]">
    Tenant name
  </ParamField>

  #### Returns

  <ResponseField name="DeactivateUserResponse" type="DeactivateUserResponse">
    [🔗 DeactivateUserResponse](/docs/truefoundry_sdk/types#deactivateuserresponse)

    User has been successfully deactivated.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.deactivate(
      email="value",
      tenant_name="value",
  )
  ```
</Accordion>

<Accordion title="activate">
  Activate user associated with the provided email within the tenant.

  #### Parameters

  <ParamField body="email" type="str" required>
    Email of the user
  </ParamField>

  <ParamField body="tenant_name" type="typing.Optional[str]">
    Tenant name
  </ParamField>

  #### Returns

  <ResponseField name="ActivateUserResponse" type="ActivateUserResponse">
    [🔗 ActivateUserResponse](/docs/truefoundry_sdk/types#activateuserresponse)

    User has been successfully activated.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.activate(
      email="value",
      tenant_name="value",
  )
  ```
</Accordion>

<Accordion title="change_password">
  Change password for the authenticated user. Requires clientId and loginId in the request body.

  #### Parameters

  <ParamField body="login_id" type="str" required>
    login id of the user(email)
  </ParamField>

  <ParamField body="new_password" type="str" required>
    New password
  </ParamField>

  <ParamField body="old_password" type="str" required>
    Old password
  </ParamField>

  #### Returns

  <ResponseField name="ChangePasswordResponse" type="ChangePasswordResponse">
    [🔗 ChangePasswordResponse](/docs/truefoundry_sdk/types#changepasswordresponse)

    Password has been changed successfully.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.change_password(
      login_id="value",
      new_password="value",
      old_password="value",
  )
  ```
</Accordion>

<Accordion title="get_resources">
  Get all resources associated with a user.

  #### Parameters

  <ParamField body="id" type="str" required>
    User Id
  </ParamField>

  #### Returns

  <ResponseField name="GetUserResourcesResponse" type="GetUserResourcesResponse">
    [🔗 GetUserResourcesResponse](/docs/truefoundry_sdk/types#getuserresourcesresponse)

    Returns all resources for the user.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.get_resources(
      id="id_value",
  )
  ```
</Accordion>

<Accordion title="get_permissions">
  Get all role bindings associated with a user, including team-inherited bindings.

  #### Parameters

  <ParamField body="id" type="str" required>
    User Id
  </ParamField>

  #### Returns

  <ResponseField name="GetUserPermissionsResponse" type="GetUserPermissionsResponse">
    [🔗 GetUserPermissionsResponse](/docs/truefoundry_sdk/types#getuserpermissionsresponse)

    Returns role bindings for the user (including team-inherited).
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.get_permissions(
      id="id_value",
  )
  ```
</Accordion>

<Accordion title="get_teams">
  Get all teams associated with a user, including their role in each team.

  #### Parameters

  <ParamField body="id" type="str" required>
    User Id
  </ParamField>

  #### Returns

  <ResponseField name="GetUserTeamsResponse" type="GetUserTeamsResponse">
    [🔗 GetUserTeamsResponse](/docs/truefoundry_sdk/types#getuserteamsresponse)

    Returns all teams for the user with their roles.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.users.get_teams(
      id="id_value",
  )
  ```
</Accordion>
