def export_v2(
    endpoint: Endpoint,
    *,
    max_retries: int = 50,
    interval: float = 0.1,
    expect_forbidden: bool = False,
    wait_result: bool = True,
    download_result: bool = True,
    **kwargs,
) -> Union[bytes, str]:
    """Export datasets|annotations|backups using the second version of export API

    Args:
        endpoint (Endpoint): Export endpoint, will be called only to initialize export process
        max_retries (int, optional): Number of retries when checking process status. Defaults to 30.
        interval (float, optional): Interval in seconds between retries. Defaults to 0.1.
        expect_forbidden (bool, optional): Should export request be forbidden or not. Defaults to False.
        download_result (bool, optional): Download exported file. Defaults to True.

    Returns:
        bytes: The content of the file if downloaded locally.
        str: If `wait_result` or `download_result` were False.
    """
    # initialize background process and ensure that the first request returns 403 code if request should be forbidden
    rq_id = initialize_export(endpoint, expect_forbidden=expect_forbidden, **kwargs)

    if not wait_result:
        return rq_id

    # check status of background process
    if download_result:
        return wait_and_download_v2(
            endpoint.api_client,
            rq_id,
            max_retries=max_retries,
            interval=interval,
        )

    background_request, _ = wait_background_request(
        endpoint.api_client, rq_id, max_retries=max_retries, interval=interval
    )
    return background_request.id
Export datasets|annotations|backups using the second version of export API

    Args:
        endpoint (Endpoint): Export endpoint, will be called only to initialize export process
        max_retries (int, optional): Number of retries when checking process status. Defaults to 30.
        interval (float, optional): Interval in seconds between retries. Defaults to 0.1.
        expect_forbidden (bool, optional): Should export request be forbidden or not. Defaults to False.
        download_result (bool, optional): Download exported file. Defaults to True.

    Returns:
        bytes: The content of the file if downloaded locally.
        str: If `wait_result` or `download_result` were False.
    
tests/python/rest_api/utils.py