๐Ÿ›ก๏ธUnitlab Python SDK

With Unitlab in your Python code

To get started, import the unitlab package and initialize a client with an API key. To obtain an API key, navigate to your user account page and follow the instructions to create a new key.

from unitlab import UnitlabClient

# You can find your API key at https://app.unitlab.ai/Unitlab/api-keys
api_key = "YOUR_API_KEY_HERE"
client = UnitlabClient(api_key)

Available methods

The following are some of the most common Python SDK methods:

projects                    Get a list of projects.
project                     Get project information.
project_members             Get project's members.
project_upload_data         Upload data samples to a project.
datasets                    Get a list of available datasets.
dataset_upload              Create a dataset with your own annotations.
dataset_download            Download the dataset's annotation.
dataset_update              Add more data to an existing dataset.
dataset_download_files      Download raw dataset files

Examples

Here are some examples of how to use the Python SDK functions

Get project list

from unitlab import UnitlabClient

api_key = "YOUR_API_KEY_HERE"

client = UnitlabClient(api_key)
client.projects()

This command will return a list of all your projects, including the project ID, ai_model, name, number_of_data, annotator progress, reviewer progress, creator, and created date.

[
    {
        "pk": "6c8801e5-7ffd-4dd4-81a2-190e1792c154",
        "ai_model": "Person Detection",
        "annotator_progress": 91.10,
        "created": "2024-02-22T11:29:48.723802",
        "creator": "YOUR_EMAIL_ADDRESS",
        "name": "Person Detection",
        "number_of_data": 988,
        "reviewer_progress": 67.81
    },
    {
        "pk": "2ae53739-95db-4a22-b018-846b19f2da05",
        "ai_model": "Vehicle Segmentation",
        "annotator_progress": 98.51,
        "created": "2024-02-15T18:35:48.193787",
        "creator": "YOUR_EMAIL_ADDRESS",
        "name": "Vehicle Segmentation",
        "number_of_data": 1007,
        "reviewer_progress": 89.37
    },
    {
        "pk": "46960ada-3119-4caf-be8e-ca633dbf9a42",
        "ai_model": "Human Pose Detection",
        "annotator_progress": 100,
        "created": "2024-02-15T16:55:32.386444",
        "creator": "YOUR_EMAIL_ADDRESS",
        "name": "Person Polygon Detection",
        "number_of_data": 52,
        "reviewer_progress": 100
    },
    {
        "pk": "245784fb-3b63-49cd-b2d1-6494095c9bb5",
        "ai_model": "Fashion Segmentation",
        "annotator_progress": 88,
        "created": "2024-01-23T17:46:18.134930",
        "creator": "YOUR_EMAIL_ADDRESS",
        "name": "Stuff Segmentation",
        "number_of_data": 2000,
        "reviewer_progress": null
    },
    ...
]

Get project members

from unitlab import UnitlabClient

api_key = "YOUR_API_KEY_HERE"
project_id = "YOUR_PROJECT_ID"

client = UnitlabClient(api_key)
client.project_members(project_id=project_id)

It will return a list of the project's members, including their IDs, emails, positions, and statistics.

[
    {
        "pk": "e1dd6cb9-1049-4ac1-ba44-41c54e8f7f9c",
        "email": "MEMBER_EMAIL",
        "position": "annotator",
        "progress": 82.13,
        "average_time": 10.45,
        "overall_time": 1692.0
    },
    {
        "pk": "e1dd6cb9-1049-4ac1-ba44-41c54e8f7f9c",
        "email": "MEMBER_EMAIL",
        "position": "annotator",
        "progress": 94.64,
        "average_time": 13.78,
        "overall_time": 2035.0
    },
    {
        "pk": "e1dd6cb9-1049-4ac1-ba44-41c54e8f7f9c",
        "email": "MEMBER_EMAIL",
        "position": "reviewer",
        "progress": 64.72,
        "average_time": 19.5,
        "overall_time": 1013.6
    },
    {
        "pk": "e1dd6cb9-1049-4ac1-ba44-41c54e8f7f9c",
        "email": "MEMBER_EMAIL",
        "position": "reviewer",
        "progress": 72.0,
        "average_time": 18.6,
        "overall_time": 1335.9
    }
]

Add data samples to a project.

To upload data samples to an existing project, provide the project ID and the directory containing the data samples and run the provided code.

from unitlab import UnitlabClient

api_key = "YOUR_API_KEY_HERE"
project_id = "YOUR_PROJECT_ID"
directory = "PATH_TO_DATA_SAMPLES"

client = UnitlabClient(api_key)
client.project_upload_data(project_id=project_id, directory=directory)

Download a dataset

You can easily download the results of labelled data using the Python SDK. Retrieve your dataset ID and execute the dataset_download method. It will download the annotated results.

from unitlab import UnitlabClient

api_key = "YOUR_API_KEY_HERE"
dataset_id = "YOUR_DATASET_ID"

client = UnitlabClient(api_key)
client.dataset_download(dataset_id=dataset_id)

Additional methods

The Python SDK provided by Unitlab offers a wealth of additional functions beyond those highlighted here. Users can utilize these methods according to their unique needs and preferences.

Last updated

Was this helpful?