Skip to content

User module

Queries

Set of User queries.

Source code in kili/entrypoints/queries/user/__init__.py
class QueriesUser:
    """Set of User queries."""

    # pylint: disable=too-many-arguments,dangerous-default-value

    def __init__(self, auth: KiliAuth):
        """Initialize the subclass.

        Args:
            auth: KiliAuth object
        """
        self.auth = auth

    @overload
    def users(
        self,
        api_key: Optional[str] = None,
        email: Optional[str] = None,
        organization_id: Optional[str] = None,
        fields: List[str] = ["email", "id", "firstname", "lastname"],
        first: Optional[int] = None,
        skip: int = 0,
        disable_tqdm: bool = False,
        *,
        as_generator: Literal[True],
    ) -> Generator[Dict, None, None]:
        ...

    @overload
    def users(
        self,
        api_key: Optional[str] = None,
        email: Optional[str] = None,
        organization_id: Optional[str] = None,
        fields: List[str] = ["email", "id", "firstname", "lastname"],
        first: Optional[int] = None,
        skip: int = 0,
        disable_tqdm: bool = False,
        *,
        as_generator: Literal[False] = False,
    ) -> List[Dict]:
        ...

    @typechecked
    def users(
        self,
        api_key: Optional[str] = None,
        email: Optional[str] = None,
        organization_id: Optional[str] = None,
        fields: List[str] = ["email", "id", "firstname", "lastname"],
        first: Optional[int] = None,
        skip: int = 0,
        disable_tqdm: bool = False,
        *,
        as_generator: bool = False,
    ) -> Iterable[Dict]:
        # pylint: disable=line-too-long
        """Get a generator or a list of users given a set of criteria.

        Args:
            api_key: Query an user by its API Key
            email: Email of the user
            organization_id: Identifier of the user's organization
            fields: All the fields to request among the possible fields for the users.
                See [the documentation](https://docs.kili-technology.com/reference/graphql-api#user) for all possible fields.
            first: Maximum number of users to return
            skip: Number of skipped users (they are ordered by creation date)
            disable_tqdm: If `True`, the progress bar will be disabled
            as_generator: If `True`, a generator on the users is returned.

        Returns:
            A result object which contains the query if it was successful,
                or an error message.

        Examples:
            ```
            # List all users in my organization
            >>> organization = kili.organizations()
            >>> organization_id = organizations[0]['id]
            >>> kili.users(organization_id=organization_id)
            ```
        """

        where = UserWhere(api_key=api_key, email=email, organization_id=organization_id)
        disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm)
        options = QueryOptions(disable_tqdm, first, skip)
        users_gen = UserQuery(self.auth.client)(where, fields, options)

        if as_generator:
            return users_gen
        return list(users_gen)

    @typechecked
    def count_users(
        self,
        organization_id: Optional[str] = None,
        api_key: Optional[str] = None,
        email: Optional[str] = None,
    ) -> int:
        """Get user count based on a set of constraints.

        Args:
            organization_id: Identifier of the user's organization.
            api_key: Filter by API Key.
            email: Filter by email.

        Returns:
            The number of organizations with the parameters provided.
        """
        where = UserWhere(api_key=api_key, email=email, organization_id=organization_id)
        return UserQuery(self.auth.client).count(where)

count_users(self, organization_id=None, api_key=None, email=None)

Get user count based on a set of constraints.

Parameters:

Name Type Description Default
organization_id Optional[str]

Identifier of the user's organization.

None
api_key Optional[str]

Filter by API Key.

None
email Optional[str]

Filter by email.

None

Returns:

Type Description
int

The number of organizations with the parameters provided.

Source code in kili/entrypoints/queries/user/__init__.py
@typechecked
def count_users(
    self,
    organization_id: Optional[str] = None,
    api_key: Optional[str] = None,
    email: Optional[str] = None,
) -> int:
    """Get user count based on a set of constraints.

    Args:
        organization_id: Identifier of the user's organization.
        api_key: Filter by API Key.
        email: Filter by email.

    Returns:
        The number of organizations with the parameters provided.
    """
    where = UserWhere(api_key=api_key, email=email, organization_id=organization_id)
    return UserQuery(self.auth.client).count(where)

users(self, api_key=None, email=None, organization_id=None, fields=['email', 'id', 'firstname', 'lastname'], first=None, skip=0, disable_tqdm=False, *, as_generator=False)

Get a generator or a list of users given a set of criteria.

Parameters:

Name Type Description Default
api_key Optional[str]

Query an user by its API Key

None
email Optional[str]

Email of the user

None
organization_id Optional[str]

Identifier of the user's organization

None
fields List[str]

All the fields to request among the possible fields for the users. See the documentation for all possible fields.

['email', 'id', 'firstname', 'lastname']
first Optional[int]

Maximum number of users to return

None
skip int

Number of skipped users (they are ordered by creation date)

0
disable_tqdm bool

If True, the progress bar will be disabled

False
as_generator bool

If True, a generator on the users is returned.

False

Returns:

Type Description
Iterable[Dict]

A result object which contains the query if it was successful, or an error message.

Examples:

# List all users in my organization
>>> organization = kili.organizations()
>>> organization_id = organizations[0]['id]
>>> kili.users(organization_id=organization_id)
Source code in kili/entrypoints/queries/user/__init__.py
@typechecked
def users(
    self,
    api_key: Optional[str] = None,
    email: Optional[str] = None,
    organization_id: Optional[str] = None,
    fields: List[str] = ["email", "id", "firstname", "lastname"],
    first: Optional[int] = None,
    skip: int = 0,
    disable_tqdm: bool = False,
    *,
    as_generator: bool = False,
) -> Iterable[Dict]:
    # pylint: disable=line-too-long
    """Get a generator or a list of users given a set of criteria.

    Args:
        api_key: Query an user by its API Key
        email: Email of the user
        organization_id: Identifier of the user's organization
        fields: All the fields to request among the possible fields for the users.
            See [the documentation](https://docs.kili-technology.com/reference/graphql-api#user) for all possible fields.
        first: Maximum number of users to return
        skip: Number of skipped users (they are ordered by creation date)
        disable_tqdm: If `True`, the progress bar will be disabled
        as_generator: If `True`, a generator on the users is returned.

    Returns:
        A result object which contains the query if it was successful,
            or an error message.

    Examples:
        ```
        # List all users in my organization
        >>> organization = kili.organizations()
        >>> organization_id = organizations[0]['id]
        >>> kili.users(organization_id=organization_id)
        ```
    """

    where = UserWhere(api_key=api_key, email=email, organization_id=organization_id)
    disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm)
    options = QueryOptions(disable_tqdm, first, skip)
    users_gen = UserQuery(self.auth.client)(where, fields, options)

    if as_generator:
        return users_gen
    return list(users_gen)

Mutations

Set of User mutations.

Source code in kili/entrypoints/mutations/user/__init__.py
class MutationsUser:
    """Set of User mutations."""

    # pylint: disable=too-many-arguments

    def __init__(self, auth: KiliAuth):
        """Initialize the subclass.

        Args:
            auth: KiliAuth object
        """
        self.auth = auth

    @typechecked
    def create_user(
        self,
        email: str,
        password: str,
        organization_role: str,
        firstname: Optional[str] = None,
        lastname: Optional[str] = None,
    ):
        """Add a user to your organization.

        Args:
            email: Email of the new user, used as user's unique identifier.
            password: On the first sign in, he will use this password and be able to change it.
            organization_role: One of "ADMIN", "USER".
            firstname: First name of the new user.
            lastname: Last name of the new user.

        Returns:
            A result object which indicates if the mutation was successful,
                or an error message.
        """
        variables = {
            "data": {
                "email": email,
                "password": password,
                "organizationRole": organization_role,
            }
        }
        if firstname is not None:
            variables["data"]["firstname"] = firstname
        if lastname is not None:
            variables["data"]["lastname"] = lastname
        result = self.auth.client.execute(GQL_CREATE_USER, variables)
        return format_result("data", result)

    @typechecked
    def update_password(
        self, email: str, old_password: str, new_password_1: str, new_password_2: str
    ):
        """Allow to modify the password that you use to connect to Kili. \
        This resolver only works for on-premise installations without Auth0.

        Args:
            email: Email of the person whose password has to be updated.
            old_password: The old password
            new_password_1: The new password
            new_password_2: A confirmation field for the new password

        Returns:
            A result object which indicates if the mutation was successful,
                or an error message.
        """
        variables = {
            "data": {
                "oldPassword": old_password,
                "newPassword1": new_password_1,
                "newPassword2": new_password_2,
            },
            "where": {"email": email},
        }
        result = self.auth.client.execute(GQL_UPDATE_PASSWORD, variables)
        return format_result("data", result)

    def reset_password(self, email: str):
        """Reset password.

        !!! warning "Method removed"
            This method is not available anymore.
            Please use the Kili App instead to reset your password.
        """
        raise RemovedMethodError(
            "reset_password() is not available anymore. Please use the Kili App instead to reset"
            " your password."
        )

    @typechecked
    def update_properties_in_user(
        self,
        email: str,
        firstname: Optional[str] = None,
        lastname: Optional[str] = None,
        organization_id: Optional[str] = None,
        organization_role: Optional[str] = None,
        activated: Optional[bool] = None,
    ):
        """Update the properties of a user.

        Args:
            email: The email is the identifier of the user.
            firstname:Change the first name of the user.
            lastname: Change the last name of the user.
            organization_id: Change the organization the user is related to.
            organization_role: Change the role of the user.
                One of "ADMIN", "TEAM_MANAGER", "REVIEWER", "LABELER".
            activated: In case we want to deactivate a user, but keep it.


        Returns:
            A result object which indicates if the mutation was successful,
                or an error message.
        """
        variables: Dict[str, Any] = {
            "email": email,
        }
        if firstname is not None:
            variables["firstname"] = firstname
        if lastname is not None:
            variables["lastname"] = lastname
        if organization_id is not None:
            variables["organizationId"] = organization_id
        if organization_role is not None:
            variables["organizationRole"] = organization_role
        if activated is not None:
            variables["activated"] = activated
        result = self.auth.client.execute(GQL_UPDATE_PROPERTIES_IN_USER, variables)
        return format_result("data", result)

create_user(self, email, password, organization_role, firstname=None, lastname=None)

Add a user to your organization.

Parameters:

Name Type Description Default
email str

Email of the new user, used as user's unique identifier.

required
password str

On the first sign in, he will use this password and be able to change it.

required
organization_role str

One of "ADMIN", "USER".

required
firstname Optional[str]

First name of the new user.

None
lastname Optional[str]

Last name of the new user.

None

Returns:

Type Description

A result object which indicates if the mutation was successful, or an error message.

Source code in kili/entrypoints/mutations/user/__init__.py
@typechecked
def create_user(
    self,
    email: str,
    password: str,
    organization_role: str,
    firstname: Optional[str] = None,
    lastname: Optional[str] = None,
):
    """Add a user to your organization.

    Args:
        email: Email of the new user, used as user's unique identifier.
        password: On the first sign in, he will use this password and be able to change it.
        organization_role: One of "ADMIN", "USER".
        firstname: First name of the new user.
        lastname: Last name of the new user.

    Returns:
        A result object which indicates if the mutation was successful,
            or an error message.
    """
    variables = {
        "data": {
            "email": email,
            "password": password,
            "organizationRole": organization_role,
        }
    }
    if firstname is not None:
        variables["data"]["firstname"] = firstname
    if lastname is not None:
        variables["data"]["lastname"] = lastname
    result = self.auth.client.execute(GQL_CREATE_USER, variables)
    return format_result("data", result)

reset_password(self, email)

Reset password.

Method removed

This method is not available anymore. Please use the Kili App instead to reset your password.

Source code in kili/entrypoints/mutations/user/__init__.py
def reset_password(self, email: str):
    """Reset password.

    !!! warning "Method removed"
        This method is not available anymore.
        Please use the Kili App instead to reset your password.
    """
    raise RemovedMethodError(
        "reset_password() is not available anymore. Please use the Kili App instead to reset"
        " your password."
    )

update_password(self, email, old_password, new_password_1, new_password_2)

Allow to modify the password that you use to connect to Kili. This resolver only works for on-premise installations without Auth0.

Parameters:

Name Type Description Default
email str

Email of the person whose password has to be updated.

required
old_password str

The old password

required
new_password_1 str

The new password

required
new_password_2 str

A confirmation field for the new password

required

Returns:

Type Description

A result object which indicates if the mutation was successful, or an error message.

Source code in kili/entrypoints/mutations/user/__init__.py
@typechecked
def update_password(
    self, email: str, old_password: str, new_password_1: str, new_password_2: str
):
    """Allow to modify the password that you use to connect to Kili. \
    This resolver only works for on-premise installations without Auth0.

    Args:
        email: Email of the person whose password has to be updated.
        old_password: The old password
        new_password_1: The new password
        new_password_2: A confirmation field for the new password

    Returns:
        A result object which indicates if the mutation was successful,
            or an error message.
    """
    variables = {
        "data": {
            "oldPassword": old_password,
            "newPassword1": new_password_1,
            "newPassword2": new_password_2,
        },
        "where": {"email": email},
    }
    result = self.auth.client.execute(GQL_UPDATE_PASSWORD, variables)
    return format_result("data", result)

update_properties_in_user(self, email, firstname=None, lastname=None, organization_id=None, organization_role=None, activated=None)

Update the properties of a user.

Parameters:

Name Type Description Default
email str

The email is the identifier of the user.

required
firstname Optional[str]

Change the first name of the user.

None
lastname Optional[str]

Change the last name of the user.

None
organization_id Optional[str]

Change the organization the user is related to.

None
organization_role Optional[str]

Change the role of the user. One of "ADMIN", "TEAM_MANAGER", "REVIEWER", "LABELER".

None
activated Optional[bool]

In case we want to deactivate a user, but keep it.

None

Returns:

Type Description

A result object which indicates if the mutation was successful, or an error message.

Source code in kili/entrypoints/mutations/user/__init__.py
@typechecked
def update_properties_in_user(
    self,
    email: str,
    firstname: Optional[str] = None,
    lastname: Optional[str] = None,
    organization_id: Optional[str] = None,
    organization_role: Optional[str] = None,
    activated: Optional[bool] = None,
):
    """Update the properties of a user.

    Args:
        email: The email is the identifier of the user.
        firstname:Change the first name of the user.
        lastname: Change the last name of the user.
        organization_id: Change the organization the user is related to.
        organization_role: Change the role of the user.
            One of "ADMIN", "TEAM_MANAGER", "REVIEWER", "LABELER".
        activated: In case we want to deactivate a user, but keep it.


    Returns:
        A result object which indicates if the mutation was successful,
            or an error message.
    """
    variables: Dict[str, Any] = {
        "email": email,
    }
    if firstname is not None:
        variables["firstname"] = firstname
    if lastname is not None:
        variables["lastname"] = lastname
    if organization_id is not None:
        variables["organizationId"] = organization_id
    if organization_role is not None:
        variables["organizationRole"] = organization_role
    if activated is not None:
        variables["activated"] = activated
    result = self.auth.client.execute(GQL_UPDATE_PROPERTIES_IN_USER, variables)
    return format_result("data", result)