Skip to main content

Understand.ai Python Client SDK for requesting annotations.

Project description

UAI Annotation Requests

Summary

UAI Annotation Requests API: The API lets a client request annotations from UAI, track the progress of the work and fetch the result annotations.

Table of Contents

Example Usage

Example

Below is an example of how an annotation request with data can be submitted to UAI for annotation.

from uai_annotation_requests import UaiAnnotationRequests
from uai_annotation_requests_util import uai_oauth2, uai_upload_data

with UaiAnnotationRequests(
    uai_oauth2=uai_oauth2("<client_id>", "<client_secret>"),
) as uar_client:

    res = uar_client.annotation_request.create(project_id="<id>", clips=[
        {
            "clip_reference_id": "clip_reference_01",
            "display_name": "my first clip",
        },
    ], request_reference_id="request_reference_01", priority=0, display_name="my annotation request")

    # Handle response
    print(res)

    # Upload data directory for each defined clip
    # The upload step here is only relevant for projects
    # That are uploading archived data to UAI where no
    # bucket integration is configured.
    for clip in res.clips:
        uai_upload_data(res, clip, path_to_data)

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
uai_oauth2 oauth2 uai_oauth2 helper or OAuth2 token

To authenticate with the API the uai_oauth2 parameter must be set when initializing the SDK client instance. The uai_oauth2 parameter accepts either the uai_oauth2 helper login function or an OAuth2 token. For example:

from uai_annotation_requests import UaiAnnotationRequests
from uai_annotation_requests_util import uai_oauth2

with UaiAnnotationRequests(
    uai_oauth2=uai_oauth2(client_id="<UAI_CLIENT_ID>", client_secret="<UAI_CLIENT_SECRET>"),
) as uar_client:

    res = uar_client.annotation_request.create(project_id="<id>", clips=[
        {
            "clip_reference_id": "clip_reference_01",
            "display_name": "my first clip",
        },
    ], request_reference_id="request_reference_01", priority=0, display_name="my annotation request")

    # Handle response
    print(res)

Available Resources and Operations

Available methods

annotation_request

clips

  • get_clips - Get clips in the project filtered by clip reference ids and states.

For example, querying for clips with state 'Exported' lists all the clips that have annotations to fetch.

Combinding the filters state and isExportDownloaded makes it possible to list all the clips that are exported and haven't yet been downloaded by the client, ex: ?state=Exported&isExportDownloade=false

The clip must be in state Exported.

Error Handling

UaiAnnotationRequestsError is the base class for all HTTP error responses. It has the following properties:

Property Type Description
err.message str Error message
err.status_code int HTTP response status code eg 404
err.headers httpx.Headers HTTP response headers
err.body str HTTP body. Can be empty string if no body is returned.
err.raw_response httpx.Response Raw HTTP response
err.data Optional. Some errors may contain structured data. See Error Classes.

Example

import uai_annotation_requests
from uai_annotation_requests import UaiAnnotationRequests, models


with UaiAnnotationRequests(
    uai_oauth2="<YOUR_UAI_OAUTH2_HERE>",
) as uar_client:
    res = None
    try:

        res = uar_client.annotation_request.get(project_id="<id>", field=uai_annotation_requests.FilterField.REQUEST_REFERENCE_ID, value="<value>")

        # Handle response
        print(res)


    except models.UaiAnnotationRequestsError as e:
        # The base class for HTTP error responses
        print(e.message)
        print(e.status_code)
        print(e.body)
        print(e.headers)
        print(e.raw_response)

        # Depending on the method different errors may be thrown
        if isinstance(e, models.AnnotationRequestNotFoundDTO):
            print(e.data.message)  # str

Error Classes

Primary error:

Less common errors (7)

Network errors:

Inherit from UaiAnnotationRequestsError:

  • AnnotationRequestNotFoundDTO: A message providing details that the annotation request was not found. Status code 404. Applicable to 2 of 8 methods.*
  • AnnotationRequestExportNotReadyDTO: A message providing details on why the annotations export is not available. Status code 404. Applicable to 1 of 8 methods.*
  • ResponseValidationError: Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the cause attribute.

* Check the method documentation to see if the error is applicable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uai_annotation_requests-0.6.0.tar.gz (51.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uai_annotation_requests-0.6.0-py3-none-any.whl (71.2 kB view details)

Uploaded Python 3

File details

Details for the file uai_annotation_requests-0.6.0.tar.gz.

File metadata

  • Download URL: uai_annotation_requests-0.6.0.tar.gz
  • Upload date:
  • Size: 51.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.11.13 Linux/6.6.97+

File hashes

Hashes for uai_annotation_requests-0.6.0.tar.gz
Algorithm Hash digest
SHA256 2d7d9f3c276ea0a9112a52a1a8decb44cdf522c9ca9d2ff679641e65ff00b53d
MD5 c98c59d4c115cf3d1ef7c696b101896f
BLAKE2b-256 19137a1a5921bdc957d371ae6add04674bcd26d8104caaa70820a2f71640a441

See more details on using hashes here.

File details

Details for the file uai_annotation_requests-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for uai_annotation_requests-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d3d61ebaf873ec8aa5a2aba8d08fe32b73fd2d15671cdadcad637dfc38ec3bf
MD5 b693b6c3e06f9c6af849ede70deb28b3
BLAKE2b-256 249d478ec0c85b1808f4e3f2b731f71fbfd175ae0cf0fe3559c8a82cba43e2b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page