# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ...core.api_error import ApiError
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.jsonable_encoder import jsonable_encoder
from ...core.pydantic_utilities import pydantic_v1
from ...core.request_options import RequestOptions
from ...types.export import Export
from ...types.export_convert import ExportConvert
from ...types.export_create import ExportCreate

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class ExportsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def create_export(
        self,
        id: int,
        *,
        export_type: typing.Optional[str] = None,
        download_all_tasks: typing.Optional[str] = None,
        download_resources: typing.Optional[bool] = None,
        ids: typing.Optional[typing.Union[int, typing.Sequence[int]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[bytes]:
        """
        <Note>If you have a large project it's recommended to use export snapshots, this easy export endpoint might have timeouts.</Note>
        Export annotated tasks as a file in a specific format.
        For example, to export JSON annotations for a project to a file called `annotations.json`,
        run the following from the command line:

        ```bash
        curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON -H 'Authorization: Token abc123' --output 'annotations.json'
        ```

        To export all tasks, including skipped tasks and others without annotations, run the following from the command line:

        ```bash
        curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON&download_all_tasks=true -H 'Authorization: Token abc123' --output 'annotations.json'
        ```

        To export specific tasks with IDs of 123 and 345, run the following from the command line:

        ```bash
        curl -X GET https://localhost:8080/api/projects/{id}/export?ids[]=123\&ids[]=345 -H 'Authorization: Token abc123' --output 'annotations.json'
        ```

        You must provide a project ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_type : typing.Optional[str]
            Selected export format (JSON by default)

        download_all_tasks : typing.Optional[str]
            If true, download all tasks regardless of status. If false, download only annotated tasks.

        download_resources : typing.Optional[bool]
            If true, download all resource files such as images, audio, and others relevant to the tasks.

        ids : typing.Optional[typing.Union[int, typing.Sequence[int]]]
            Specify a list of task IDs to retrieve only the details for those tasks.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.Iterator[bytes]
            Exported data

        Examples
        --------
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.create_export(
            id=1,
            export_type="string",
            download_all_tasks="string",
            download_resources=True,
            ids=1,
        )
        """
        with self._client_wrapper.httpx_client.stream(
            f"api/projects/{jsonable_encoder(id)}/export",
            method="GET",
            params={
                "export_type": export_type,
                "download_all_tasks": download_all_tasks,
                "download_resources": download_resources,
                "ids": ids,
            },
            request_options=request_options,
        ) as _response:
            if 200 <= _response.status_code < 300:
                for _chunk in _response.iter_bytes():
                    yield _chunk
                return
            _response.read()
            try:
                _response_json = _response.json()
            except JSONDecodeError:
                raise ApiError(status_code=_response.status_code, body=_response.text)
            raise ApiError(status_code=_response.status_code, body=_response_json)

    def list_formats(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[str]:
        """
        Before exporting annotations, you can check with formats are supported by the specified project. For more information about export formats, see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).

        You must provide a project ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[str]
            Export formats

        Examples
        --------
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.list_formats(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/export/formats", method="GET", request_options=request_options
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(typing.List[str], _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def list(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Export]:
        """
        Returns a list of export file (snapshots) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Included in the response is information about each snapshot, such as who created it and what format it is in.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[Export]


        Examples
        --------
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.list(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/", method="GET", request_options=request_options
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(typing.List[Export], _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def create(
        self, id: int, *, request: ExportCreate, request_options: typing.Optional[RequestOptions] = None
    ) -> ExportCreate:
        """
        Create a new export request to start a background task and generate an export file (snapshot) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        A snapshot is a static export of your project's data and annotations at a specific point in time. It captures the current state of your tasks, annotations, and other relevant data, allowing you to download and review them later. Snapshots are particularly useful for large projects as they help avoid timeouts during export operations by processing the data asynchronously.

        For more information, see the [Label Studio documentation on exporting annotations](https://labelstud.io/guide/export.html).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        request : ExportCreate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ExportCreate


        Examples
        --------
        from label_studio_sdk import ExportCreate
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.create(
            id=1,
            request=ExportCreate(),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/",
            method="POST",
            json=request,
            request_options=request_options,
            omit=OMIT,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(ExportCreate, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> Export:
        """
        Retrieve information about a specific export file (snapshot).

        You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).

        You will also need the project ID. This can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Export


        Examples
        --------
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.get(
            id=1,
            export_pk="export_pk",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            method="GET",
            request_options=request_options,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(Export, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def delete(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete an export file by specified export ID.

        You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.delete(
            id=1,
            export_pk="export_pk",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            method="DELETE",
            request_options=request_options,
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def convert(
        self,
        id: int,
        export_pk: str,
        *,
        request: ExportConvert,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExportConvert:
        """
        You can use this to convert an export snapshot into the selected format.

        To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).

        You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).

        The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        request : ExportConvert

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ExportConvert


        Examples
        --------
        from label_studio_sdk import ExportConvert
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.convert(
            id=1,
            export_pk="export_pk",
            request=ExportConvert(
                export_type="export_type",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/convert",
            method="POST",
            json=request,
            request_options=request_options,
            omit=OMIT,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(ExportConvert, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def download(
        self,
        id: int,
        export_pk: str,
        *,
        export_type: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Download an export snapshot as a file in a specified format. To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).

        You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).

        The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        export_type : typing.Optional[str]
            Selected export format

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk.client import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.exports.download(
            id=1,
            export_pk="export_pk",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/download",
            method="GET",
            params={"exportType": export_type},
            request_options=request_options,
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncExportsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def create_export(
        self,
        id: int,
        *,
        export_type: typing.Optional[str] = None,
        download_all_tasks: typing.Optional[str] = None,
        download_resources: typing.Optional[bool] = None,
        ids: typing.Optional[typing.Union[int, typing.Sequence[int]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[bytes]:
        """
        <Note>If you have a large project it's recommended to use export snapshots, this easy export endpoint might have timeouts.</Note>
        Export annotated tasks as a file in a specific format.
        For example, to export JSON annotations for a project to a file called `annotations.json`,
        run the following from the command line:

        ```bash
        curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON -H 'Authorization: Token abc123' --output 'annotations.json'
        ```

        To export all tasks, including skipped tasks and others without annotations, run the following from the command line:

        ```bash
        curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON&download_all_tasks=true -H 'Authorization: Token abc123' --output 'annotations.json'
        ```

        To export specific tasks with IDs of 123 and 345, run the following from the command line:

        ```bash
        curl -X GET https://localhost:8080/api/projects/{id}/export?ids[]=123\&ids[]=345 -H 'Authorization: Token abc123' --output 'annotations.json'
        ```

        You must provide a project ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_type : typing.Optional[str]
            Selected export format (JSON by default)

        download_all_tasks : typing.Optional[str]
            If true, download all tasks regardless of status. If false, download only annotated tasks.

        download_resources : typing.Optional[bool]
            If true, download all resource files such as images, audio, and others relevant to the tasks.

        ids : typing.Optional[typing.Union[int, typing.Sequence[int]]]
            Specify a list of task IDs to retrieve only the details for those tasks.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.AsyncIterator[bytes]
            Exported data

        Examples
        --------
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.create_export(
            id=1,
            export_type="string",
            download_all_tasks="string",
            download_resources=True,
            ids=1,
        )
        """
        async with self._client_wrapper.httpx_client.stream(
            f"api/projects/{jsonable_encoder(id)}/export",
            method="GET",
            params={
                "export_type": export_type,
                "download_all_tasks": download_all_tasks,
                "download_resources": download_resources,
                "ids": ids,
            },
            request_options=request_options,
        ) as _response:
            if 200 <= _response.status_code < 300:
                async for _chunk in _response.aiter_bytes():
                    yield _chunk
                return
            await _response.aread()
            try:
                _response_json = _response.json()
            except JSONDecodeError:
                raise ApiError(status_code=_response.status_code, body=_response.text)
            raise ApiError(status_code=_response.status_code, body=_response_json)

    async def list_formats(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[str]:
        """
        Before exporting annotations, you can check with formats are supported by the specified project. For more information about export formats, see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).

        You must provide a project ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[str]
            Export formats

        Examples
        --------
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.list_formats(
            id=1,
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/export/formats", method="GET", request_options=request_options
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(typing.List[str], _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def list(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Export]:
        """
        Returns a list of export file (snapshots) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Included in the response is information about each snapshot, such as who created it and what format it is in.

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[Export]


        Examples
        --------
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.list(
            id=1,
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/", method="GET", request_options=request_options
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(typing.List[Export], _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def create(
        self, id: int, *, request: ExportCreate, request_options: typing.Optional[RequestOptions] = None
    ) -> ExportCreate:
        """
        Create a new export request to start a background task and generate an export file (snapshot) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        A snapshot is a static export of your project's data and annotations at a specific point in time. It captures the current state of your tasks, annotations, and other relevant data, allowing you to download and review them later. Snapshots are particularly useful for large projects as they help avoid timeouts during export operations by processing the data asynchronously.

        For more information, see the [Label Studio documentation on exporting annotations](https://labelstud.io/guide/export.html).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        request : ExportCreate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ExportCreate


        Examples
        --------
        from label_studio_sdk import ExportCreate
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.create(
            id=1,
            request=ExportCreate(),
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/",
            method="POST",
            json=request,
            request_options=request_options,
            omit=OMIT,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(ExportCreate, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> Export:
        """
        Retrieve information about a specific export file (snapshot).

        You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).

        You will also need the project ID. This can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Export


        Examples
        --------
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.get(
            id=1,
            export_pk="export_pk",
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            method="GET",
            request_options=request_options,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(Export, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def delete(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete an export file by specified export ID.

        You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.delete(
            id=1,
            export_pk="export_pk",
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
            method="DELETE",
            request_options=request_options,
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def convert(
        self,
        id: int,
        export_pk: str,
        *,
        request: ExportConvert,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExportConvert:
        """
        You can use this to convert an export snapshot into the selected format.

        To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).

        You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).

        The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        request : ExportConvert

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ExportConvert


        Examples
        --------
        from label_studio_sdk import ExportConvert
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.convert(
            id=1,
            export_pk="export_pk",
            request=ExportConvert(
                export_type="export_type",
            ),
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/convert",
            method="POST",
            json=request,
            request_options=request_options,
            omit=OMIT,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(ExportConvert, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def download(
        self,
        id: int,
        export_pk: str,
        *,
        export_type: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Download an export snapshot as a file in a specified format. To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).

        You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).

        The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).

        Parameters
        ----------
        id : int
            A unique integer value identifying this project.

        export_pk : str
            Primary key identifying the export file.

        export_type : typing.Optional[str]
            Selected export format

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk.client import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )
        await client.projects.exports.download(
            id=1,
            export_pk="export_pk",
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/download",
            method="GET",
            params={"exportType": export_type},
            request_options=request_options,
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
