These code snippets demonstrate how to use the most common Python SDK functions.
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-keysapi_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 UnitlabClientapi_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.
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 UnitlabClientapi_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 UnitlabClientapi_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.