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.5.1.tar.gz (50.9 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.5.1-py3-none-any.whl (70.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for uai_annotation_requests-0.5.1.tar.gz
Algorithm Hash digest
SHA256 13ca6bc1f5c7a916391b9e73cbf8c94ece05edc6830d4142e4344b9b7150edfe
MD5 9ed899cf113ca0cd7d9f751548aa2c10
BLAKE2b-256 e92db0bcf78231ebadf62534dbe871b3d36512bb06bd1394014d42956a0aed34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uai_annotation_requests-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 168aa08fa038902f9d7aff0bb4838fb1d2ae536aeb94a8971b54575b833ae138
MD5 51c367df15cb22015b576b3fe7577efa
BLAKE2b-256 fb7f1839ac07c8c2623bb67a45e776b36fe88dea6bdd899690053bba49694d66

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