Skip to content

Organization module

Queries

Set of Organization queries

Source code in kili/queries/organization/__init__.py
class QueriesOrganization:
    """
    Set of Organization queries
    """

    # pylint: disable=too-many-arguments,too-many-locals

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

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

    # pylint: disable=dangerous-default-value
    @typechecked
    def organizations(
        self,
        email: Optional[str] = None,
        organization_id: Optional[str] = None,
        fields: List[str] = ["id", "name"],
        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 organizations that match a set of criteria.

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

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

        Examples:
            >>> kili.organizations(organization_id=organization_id, fields=['users.email'])
            [{'users': [{'email': 'john@doe.com'}]}]
        """

        where = OrganizationWhere(
            email=email,
            organization_id=organization_id,
        )
        options = QueryOptions(disable_tqdm, first, skip, as_generator)
        return OrganizationQuery(self.auth.client)(where, fields, options)

    @typechecked
    def count_organizations(
        self, email: Optional[str] = None, organization_id: Optional[str] = None
    ) -> int:
        """Count organizations that match a set of criteria.

        Args:
            email: Email of a user of the organization
            organization_id: Identifier of the organization

        Returns:
            A result object which contains the query if it was successful,
                or an error message.
        """
        where = OrganizationWhere(
            email=email,
            organization_id=organization_id,
        )
        return OrganizationQuery(self.auth.client).count(where)

    @typechecked
    def organization_metrics(
        self,
        organization_id: str,
        start_date: Optional[datetime] = None,
        end_date: Optional[datetime] = None,
    ):
        """Get organization metrics.

        Args:
            organization_id: Identifier of the organization
            start_date: Start date of the metrics computation
            end_date: End date of the metrics computation

        Returns:
            A result object which contains the query if it was successful,
                or an error message.
        """
        if start_date is None:
            start_date = datetime.now()
        if end_date is None:
            end_date = datetime.now()
        where = OrganizationMetricsWhere(
            organization_id=organization_id, start_date=start_date, end_date=end_date
        )
        return OrganizationQuery(self.auth.client).metrics(where)

count_organizations(self, email=None, organization_id=None)

Count organizations that match a set of criteria.

Parameters:

Name Type Description Default
email Optional[str]

Email of a user of the organization

None
organization_id Optional[str]

Identifier of the organization

None

Returns:

Type Description
int

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

Source code in kili/queries/organization/__init__.py
@typechecked
def count_organizations(
    self, email: Optional[str] = None, organization_id: Optional[str] = None
) -> int:
    """Count organizations that match a set of criteria.

    Args:
        email: Email of a user of the organization
        organization_id: Identifier of the organization

    Returns:
        A result object which contains the query if it was successful,
            or an error message.
    """
    where = OrganizationWhere(
        email=email,
        organization_id=organization_id,
    )
    return OrganizationQuery(self.auth.client).count(where)

organization_metrics(self, organization_id, start_date=None, end_date=None)

Get organization metrics.

Parameters:

Name Type Description Default
organization_id str

Identifier of the organization

required
start_date Optional[datetime.datetime]

Start date of the metrics computation

None
end_date Optional[datetime.datetime]

End date of the metrics computation

None

Returns:

Type Description

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

Source code in kili/queries/organization/__init__.py
@typechecked
def organization_metrics(
    self,
    organization_id: str,
    start_date: Optional[datetime] = None,
    end_date: Optional[datetime] = None,
):
    """Get organization metrics.

    Args:
        organization_id: Identifier of the organization
        start_date: Start date of the metrics computation
        end_date: End date of the metrics computation

    Returns:
        A result object which contains the query if it was successful,
            or an error message.
    """
    if start_date is None:
        start_date = datetime.now()
    if end_date is None:
        end_date = datetime.now()
    where = OrganizationMetricsWhere(
        organization_id=organization_id, start_date=start_date, end_date=end_date
    )
    return OrganizationQuery(self.auth.client).metrics(where)

organizations(self, email=None, organization_id=None, fields=['id', 'name'], first=None, skip=0, disable_tqdm=False, as_generator=False)

Get a generator or a list of organizations that match a set of criteria.

Parameters:

Name Type Description Default
email

Email of a user of the organization

None
organization_id

Identifier of the organization

None
fields List[str]

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

['id', 'name']
first Optional[int]

Maximum number of organizations to return.

None
skip int

Number of skipped organizations (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 organizations is returned.

False

Returns:

Type Description
Iterable[Dict]

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

Examples:

>>> kili.organizations(organization_id=organization_id, fields=['users.email'])
[{'users': [{'email': 'john@doe.com'}]}]
Source code in kili/queries/organization/__init__.py
@typechecked
def organizations(
    self,
    email: Optional[str] = None,
    organization_id: Optional[str] = None,
    fields: List[str] = ["id", "name"],
    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 organizations that match a set of criteria.

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

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

    Examples:
        >>> kili.organizations(organization_id=organization_id, fields=['users.email'])
        [{'users': [{'email': 'john@doe.com'}]}]
    """

    where = OrganizationWhere(
        email=email,
        organization_id=organization_id,
    )
    options = QueryOptions(disable_tqdm, first, skip, as_generator)
    return OrganizationQuery(self.auth.client)(where, fields, options)