Skip to content

Project Version module

Queries

Set of ProjectVersion queries.

Source code in kili/queries/project_version/__init__.py
class QueriesProjectVersion:
    """Set of ProjectVersion 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
    @Compatible(['v2'])
    @typechecked
    def project_version(
            self,
            first: Optional[int] = 100,
            skip: Optional[int] = 0,
            fields: List[str] = [
                'createdAt',
                'id',
                'content',
                'name',
                'project',
                'projectId'],
            project_id: str = None,
            disable_tqdm: bool = False,
            as_generator: bool = False) -> Union[List[dict], Generator[dict, None, None]]:
        # pylint: disable=line-too-long
        """Get a generator or a list of project versions respecting a set of criteria.

        Args:
            fields: All the fields to request among the possible fields for the project versions
                See [the documentation](https://cloud.kili-technology.com/docs/python-graphql-api/graphql-api/#projectVersions) for all possible fields.
            first: Number of project versions to query
            project_id: Filter on Id of project
            skip: Number of project versions to skip (they are ordered by their date
                of creation, first to last).
            disable_tqdm: If `True`, the progress bar will be disabled
            as_generator: If `True`, a generator on the project versions is returned.

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

        count_args = {"project_id": project_id}
        disable_tqdm = disable_tqdm or as_generator
        payload_query = {
            'where': {
                'projectId': project_id,
            },
        }
        project_versions_generator = row_generator_from_paginated_calls(
            skip,
            first,
            self.count_project_versions,
            count_args,
            self._query_project_versions,
            payload_query,
            fields,
            disable_tqdm
        )

        if as_generator:
            return project_versions_generator
        return list(project_versions_generator)

    def _query_project_versions(self,
                                skip: int,
                                first: int,
                                payload: dict,
                                fields: List[str]):

        payload.update({'skip': skip, 'first': first})
        _gql_project_version = gql_project_version(
            fragment_builder(fields, ProjectVersionType))
        result = self.auth.client.execute(_gql_project_version, payload)
        return format_result('data', result)

    @Compatible(['v2'])
    @typechecked
    def count_project_versions(self, project_id: str) -> int:
        """Count the number of project versions.

        Args:
            project_id: Filter on ID of project

        Returns:
            The number of project versions with the parameters provided
        """
        variables = {
            'where': {'projectId': project_id},
        }
        result = self.auth.client.execute(GQL_PROJECT_VERSION_COUNT, variables)
        count = format_result('data', result)
        return count

count_project_versions(self, project_id)

Count the number of project versions.

Parameters:

Name Type Description Default
project_id str

Filter on ID of project

required

Returns:

Type Description
int

The number of project versions with the parameters provided

Source code in kili/queries/project_version/__init__.py
@Compatible(['v2'])
@typechecked
def count_project_versions(self, project_id: str) -> int:
    """Count the number of project versions.

    Args:
        project_id: Filter on ID of project

    Returns:
        The number of project versions with the parameters provided
    """
    variables = {
        'where': {'projectId': project_id},
    }
    result = self.auth.client.execute(GQL_PROJECT_VERSION_COUNT, variables)
    count = format_result('data', result)
    return count

project_version(self, first=100, skip=0, fields=['createdAt', 'id', 'content', 'name', 'project', 'projectId'], project_id=None, disable_tqdm=False, as_generator=False)

Get a generator or a list of project versions respecting a set of criteria.

Parameters:

Name Type Description Default
fields List[str]

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

['createdAt', 'id', 'content', 'name', 'project', 'projectId']
first Optional[int]

Number of project versions to query

100
project_id str

Filter on Id of project

None
skip Optional[int]

Number of project versions to skip (they are ordered by their date of creation, first to last).

0
disable_tqdm bool

If True, the progress bar will be disabled

False
as_generator bool

If True, a generator on the project versions is returned.

False

Returns:

Type Description
Union[List[dict], Generator[dict, NoneType]]

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

Source code in kili/queries/project_version/__init__.py
@Compatible(['v2'])
@typechecked
def project_version(
        self,
        first: Optional[int] = 100,
        skip: Optional[int] = 0,
        fields: List[str] = [
            'createdAt',
            'id',
            'content',
            'name',
            'project',
            'projectId'],
        project_id: str = None,
        disable_tqdm: bool = False,
        as_generator: bool = False) -> Union[List[dict], Generator[dict, None, None]]:
    # pylint: disable=line-too-long
    """Get a generator or a list of project versions respecting a set of criteria.

    Args:
        fields: All the fields to request among the possible fields for the project versions
            See [the documentation](https://cloud.kili-technology.com/docs/python-graphql-api/graphql-api/#projectVersions) for all possible fields.
        first: Number of project versions to query
        project_id: Filter on Id of project
        skip: Number of project versions to skip (they are ordered by their date
            of creation, first to last).
        disable_tqdm: If `True`, the progress bar will be disabled
        as_generator: If `True`, a generator on the project versions is returned.

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

    count_args = {"project_id": project_id}
    disable_tqdm = disable_tqdm or as_generator
    payload_query = {
        'where': {
            'projectId': project_id,
        },
    }
    project_versions_generator = row_generator_from_paginated_calls(
        skip,
        first,
        self.count_project_versions,
        count_args,
        self._query_project_versions,
        payload_query,
        fields,
        disable_tqdm
    )

    if as_generator:
        return project_versions_generator
    return list(project_versions_generator)

Mutations

Set of ProjectVersion mutations.

Source code in kili/mutations/project_version/__init__.py
class MutationsProjectVersion:
    """Set of ProjectVersion mutations."""

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

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

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

    @Compatible(['v2'])
    @typechecked
    def update_properties_in_project_version(
            self,
            project_version_id: str,
            content: Optional[str]):
        """Update properties of a project version.

        Args:
            project_version_id: Identifier of the project version
            content: Link to download the project version

        Returns:
            A result object which indicates if the mutation was successful.

        Examples:
            >>> kili.update_properties_in_project_version(
                    project_version_id=project_version_id,
                    content='test')
        """
        variables = {
            'content': content,
            'id': project_version_id,
        }
        result = self.auth.client.execute(
            GQL_UPDATE_PROPERTIES_IN_PROJECT_VERSION, variables)
        return format_result('data', result)

update_properties_in_project_version(self, project_version_id, content)

Update properties of a project version.

Parameters:

Name Type Description Default
project_version_id str

Identifier of the project version

required
content Optional[str]

Link to download the project version

required

Returns:

Type Description

A result object which indicates if the mutation was successful.

Examples:

>>> kili.update_properties_in_project_version(
        project_version_id=project_version_id,
        content='test')
Source code in kili/mutations/project_version/__init__.py
@Compatible(['v2'])
@typechecked
def update_properties_in_project_version(
        self,
        project_version_id: str,
        content: Optional[str]):
    """Update properties of a project version.

    Args:
        project_version_id: Identifier of the project version
        content: Link to download the project version

    Returns:
        A result object which indicates if the mutation was successful.

    Examples:
        >>> kili.update_properties_in_project_version(
                project_version_id=project_version_id,
                content='test')
    """
    variables = {
        'content': content,
        'id': project_version_id,
    }
    result = self.auth.client.execute(
        GQL_UPDATE_PROPERTIES_IN_PROJECT_VERSION, variables)
    return format_result('data', result)