Welcome to The Hasty Python API Library’s documentation!
Installation Guide
pip install hasty
Quick Start
Authentication
In order to communicate with your Hasty server via the API, you must provide valid API Key. The Key can be generated on Edit Workspace page (Hasty -> Edit Workspace -> API Accounts)
You will need to create a service account, define it’s role and finally generate API Key:

Create a Hasty API Client instance
This example shows how to create establish your initial connection to Hasty:
from hasty import Client
API_KEY = "bNZ09SA2hFSZGHa6jfMK2Ywo7GoActTXNCvJR1wEkVDtKvl9EMTLRvknwmwUz7Hjl1jPwxYBkyGF8BcWV3y9rg"
h = Client(api_key=API_KEY)
Managing projects
Below you can find an example of how the projects can be created, retrieved, updated or removed. Please note, that every project should belong to some workspace.
# Get workspaces that the user account can have access to
workspaces = h.get_workspaces()
print(workspaces)
>> ['Workspace(id="57d9a50e-73a2-47c5-a130-a652fa98d244", name="Hasty Python Library Workspace")']
# Create new project
default_workspace = workspaces[0]
new_project = h.create_project(workspace = default_workspace,
name = "My Awesome Project",
description = "Awesome description")
print(new_project)
>> Project(id="75472e11-d6f2-403c-80f6-f0fc83c97041", name="My Awesome Project")
# Get Projects
print(h.get_projects())
>> ['Project(id="75472e11-d6f2-403c-80f6-f0fc83c97041", name="My Awesome Project")']
# Get project by id
h.get_project(new_project.id)
>> Project(id="75472e11-d6f2-403c-80f6-f0fc83c97041", name="My Awesome Project")
# Edit project
new_project.edit(name="Super Awesome Project", description="Amazing description")
# Delete project
new_project.delete()
Managing images
Images in hasty stored in datasets. Similar to folders on your computer, every image should have a unique image name inside the dataset. You can upload image from local file or using url.
# Create dataset
train_dataset = new_project.create_dataset("train")
print(train_dataset)
>> Dataset(id="7a55886d-e695-4693-9a3d-7addd75c5e74", name="train")
# Upload image from file
image = new_project.upload_from_file(dataset=train_dataset,
filepath='../Datasets/African Wildlife/rhino/001.jpg')
print(image)
>> Image(id="b58860f1-8da0-4c94-bff7-b7476c3c8f50", dataset_name="train", name="001.jpg")
# Upload from URL
image = new_project.upload_from_url(dataset=train_dataset,
filename='4.jpg',
url='https://www.gstatic.com/webp/gallery/4.jpg')
print(image)
>> Image(id="2dae09ce-ca8a-416f-90e2-a4024515ae95", dataset_name=None, name="4.jpg")
# Retrieve the list of projects images
images = new_project.get_images()
print(images)
>> ['Image(id="b58860f1-8da0-4c94-bff7-b7476c3c8f50", dataset_name="train", name="001.jpg")',
'Image(id="2dae09ce-ca8a-416f-90e2-a4024515ae95", dataset_name="train", name="4.jpg")']
Managing label classes
Every label in hasty should belongs to some label class.
# Create label classes
rhino_class = new_project.create_label_class(name="rhino", color="#6a3d9a", class_type="object")
sky_class = new_project.create_label_class(name="sky", color="#6a3d9a", class_type="background")
# Edit label class
sky_class.edit(name="sky", color="#f0e928", class_type="background")
# Get label classes
label_classes = new_project.get_label_classes()
print(label_classes)
>> ['LabelClass(id="1201c994-c0dc-4efa-9892-f9d030320c5d", name="rhino", color="#6a3d9a", type="object", norder=10.0)',
'LabelClass(id="2c8097bc-6dbf-4753-9485-683aff6171f9", name="sky", color="#f0e928", type="background", norder=11.0)']
# Delete label class
sky_class.delete()
Managing labels
# Create label
image.create_label(label_class=rhino_class, bbox=[20, 30, 300, 400])
lbl.edit(label_class=rhino_class, bbox=[120, 130, 300, 400])
lbl.delete()
Python API
Client
- class hasty.Client(api_key, base_url='https://api.hasty.ai')
Client for Hasty API
- __init__(api_key, base_url='https://api.hasty.ai')
Initialize the client
- api_key
Your API key
- get_workspaces()
Returns the list of workspaces that the user can have an access to :returns: A list of
Workspace
objects.
- create_project(workspace: Union[str, Workspace], name: str, description: Optional[str] = None) Project
Creates new project
Project
- Parameters
workspace (
Workspace
, str) – Workspace object or id which the project should belongs toname (str) – Name of the project
description (str, optional) – Project description
Project
- class hasty.Project(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property description
type: string
- property workspace_id
type: string
- edit(name, description)
Edits projects properties
- Parameters
name (str) – Name of the project
description (str, optional) – Project description
- delete()
Removes project
- get_dataset(dataset_id: str)
Get dataset by id, returns ~hasty.Dataset object
- Parameters
dataset_id (str) – Dataset id
- create_dataset(name: str, norder: float = 0)
Creates a new dataset, returns ~hasty.Dataset object
- Parameters
name (str) – Name of the dataset
norder (float, optional) – Order in the list
- get_images(dataset=None, image_status=None)
Retrieves the list of projects images.
- Parameters
dataset (str, ~hasty.Dataset, list of str, list of ~hasty.Dataset) – filter images by dataset
image_status (str, list of str) –
Filters images by status, valid values are:
”NEW”
”DONE”,
”SKIPPED”
”IN PROGRESS”
”TO REVIEW”
”AUTO-LABELLED”
- get_image(image_id)
Retrieves the image by its id.
- Parameters
image_id (str) – Image ID
- upload_from_file(dataset, filepath, external_id: Optional[str] = None)
Uploads image from the given filepath
- Parameters
dataset (~hasty.Dataset, str) – Dataset object or id that the image should belongs to
filepath (str) – Local path
external_id (str) – External ID (optional)
- upload_from_url(dataset: Union[Dataset, str], filename: str, url: str, copy_original: bool = True, external_id: Optional[str] = None)
Uploads image from a given URL
- Parameters
dataset (~hasty.Dataset, str) – Dataset object or id that the image should belongs to
filename (str) – Filename of the image
url (str) – Image url
copy_original (str) – If True Hasty makes a copy of the image. Default True.
external_id (str) – External ID (optional)
- get_label_classes()
Get label classes, list of
LabelClass
objects.
- get_label_class(label_class_id: str)
Get label class by id, returns ~hasty.LabelClass object
- Parameters
label_class_id (str) – Label class id
- create_label_class(name: str, color: Optional[str] = None, class_type: str = 'object', norder: Optional[float] = None, external_id: Optional[str] = None)
Create label class, returns
LabelClass
object.- Parameters
name (str) – Label class name
color (str, optional) – Color in HEX format #0f0f0faa
class_type (str, optional) – Class type [object or background] (default object)
norder (float, optional) – Order in the Hasty tool
external_id (str, optional) – External Identifier
- get_tag_class(tag_class_id: str)
Get tag class by id, returns ~hasty.TagClass object
- Parameters
tag_class_id (str) – Tag class id
- create_tag_class(name: str, norder: Optional[float] = None)
Create tag class, returns
TagClass
object.- Parameters
name (str) – Tag class name
norder (float, optional) – Order in the Hasty tool
- create_attribute(name: str, attribute_type: str, description: Optional[str] = None, norder: Optional[float] = None, values: Optional[List[str]] = None)
Create attribute, returns
Attribute
object.- Parameters
name (str) – Attribute name
attribute_type (str) – Attribute type [‘SELECTION’, ‘MULTIPLE-SELECTION’, ‘TEXT’, ‘INT’, ‘FLOAT’, ‘BOOL’]
description (str, optional) – Attrbute description
norder (float, optional) – Order in the Hasty tool
values (list of str) – List of values for SELECTION and MULTIPLE-SELECTION attribute type
- get_attribute_classes()
- Get attributes - class mapping. Returns list of dict with a keys:
attribute_id - Attribute ID
class_id - Class ID
attribute_order - Order of attributes within the class
class_order - Order of classes within the attribute
- set_attribute_classes(attribute_classes)
Set attribute - class mapping
- Parameters
attribute_classes (dict) –
ID (- class_id - Class) –
ID –
class (- attribute_order - Order of attributes within the) –
attribute (- class_order - Order of classes within the) –
- delete_attribute_classes(attribute_classes)
Removes attribute - class mapping
- Parameters
attribute_classes (dict) –
ID (- class_id - Class) –
ID –
class (- attribute_order - Order of attributes within the) –
attribute (- class_order - Order of classes within the) –
- export(name: str, export_format: str, dataset: Optional[Union[Dataset, str, List[Dataset], List[str]]] = None, image_status: Union[str, List[str]] = 'DONE', sign_urls: bool = False, semantic_format: str = 'gs_asc', labels_order: Optional[List[str]] = None)
Initiate export job. Returns
ExportJob
object.- Parameters
name (str) – Name of the export file
export_format (str) – Export format one of [“json_v1.1”, “semantic_png”, “json_coco”, “images”]
dataset (~hasty.Dataset, str, list of ~hasty.Dataset, list of str) – List of the datasets to export
image_status (list of str, str) – List of the image statuses to export. Default DONE
sign_urls (bool) – Whether to generate sign urls for images. Default False
semantic_format (str) – Format for semantic_png export. [“gs_desc”, “gs_asc”, “class_color”]
labels_order (list of str) – Draw order for semantic_png export [“z_index”, “class_type”, “class_order”]
- get_instance_segmentor()
Returns instance segmentation model. Returns
InstanceSegmentor
object.
- get_semantic_segmentor()
Returns semantic segmentation model. Returns
SemanticSegmentor
object.
- get_attributer()
Returns active attributer model for the project. Returns
Attributer
object.
- get_automated_labeling_jobs()
Get automated labeling jobs, list of
AutomatedLabelingJob
objects.
- get_automated_labeling_job(job_id: str)
Get automated labeling jobs, list of
AutomatedLabelingJob
objects.- Parameters
job_id (str) – Automated labeling job id
- create_automated_labeling_job(experiment_id: str, confidence_threshold: float = 0.8, max_detections_per_image: int = 100, num_images: int = 0, masker_threshold: float = 0.5, dataset_id: Optional[str] = None)
Create automated labeling job, returns
AutomatedLabelingJob
object.- Parameters
experiment_id (str) – ID of an experiment, that would be used for automated labeling
confidence_threshold (float, optional) – Confidence threshold of the predictions that should be applied (default 0.8)
max_detections_per_image (int, optional) – Max number of labels that should be created, default 100
num_images (int, optional) – Total number of images that should be used for automated labeling (default all)
masker_threshold (float, optional) – Threshold for mask head (default 0.5)
dataset_id (str, optional) – Filter images by dataset
Dataset
- class hasty.Dataset(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property norder
type: float
- edit(name: str, norder: float)
Edit dataset properties
- Parameters
name (str) – Name of the dataset
norder (float) – Order in the list
- delete()
Removes dataset
Image
- class hasty.Image(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property dataset_id
type: string
- property dataset_name
type: string
- property width
type: int
- property height
type: int
- property status
type: string
- property public_url
type: string
- property external_id
type: string
- get_labels()
Returns image labels (list of ~hasty.Label objects)
- create_label(label_class: Union[LabelClass, str], bbox: Optional[List[int]] = None, polygon: Optional[List[List[int]]] = None, mask: Optional[List[int]] = None, z_index: Optional[int] = None, external_id: Optional[str] = None)
Create label
- Parameters
label_class (LabelClass, str) – Label class or label class ID of the label
bbox (list of int) – Coordinates of bounding box [x_min, y_min, x_max, y_max]
polygon (list) – List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]]
mask (list of int) – RLE Encoded binary mask, (order right -> down)
z_index (int) – Z index of the label. A label with greater value is in front of a label with a lower one.
external_id (str, optional) – External Identifier
- create_labels(labels)
Create multiple labels. Returns a list of ~hasty.Label objects
- Parameters
labels (list of dict) – List of labels, keys: class_id: Label class ID of the label bbox: Coordinates of bounding box [x_min, y_min, x_max, y_max] polygon: List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]] mask: RLE Encoded binary mask, (order right -> down) z_index: Z index of the label. external_id: External Identifier
- edit_labels(labels)
Updates multiple labels. Returns a list of ~hasty.Label objects
- Parameters
labels (list of dict) – List of labels, keys: label_id: Label id class_id: Label class ID of the label bbox: Coordinates of bounding box [x_min, y_min, x_max, y_max] polygon: List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]] mask: RLE Encoded binary mask, (order right -> down) z_index: Z index of the label. external_id: External identifier
- delete_labels(label_ids: List[str])
Removes multiple labels
- Parameters
label_ids (list of str) – Returns list of ids
- set_status(status: str)
Set image status
- Parameters
status – New status one of [“NEW”, “DONE”, “SKIPPED”, “IN PROGRESS”, “TO REVIEW”]
- download(filepath: str)
Downloads image to file
- Parameters
filepath (str) – Local path
- rename(new_name: str)
Rename image
- Parameters
new_name (str) – New image name
- delete()
Removes image
- get_tags()
Returns image tags (list of ~hasty.Tag objects)
LabelClass
- class hasty.LabelClass(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property color
type: string
- property class_type
type: string
- property norder
type: float
- property external_id
type: string
- edit(name, color=None, class_type='object', norder=None, external_id=None)
Edit label class properties
- Parameters
name (str) – Label class name
color (str, optional) – Color in HEX format #0f0f0faa
class_type (str, optional) – Class type [object or background] (default object)
norder (float, optional) – Order in the Hasty tool
external_id (str, optional) – External identifier
- delete()
Deletes label class
TagClass
- class hasty.TagClass(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property norder
type: float
- edit(name, norder=None)
Edit tag class properties
- Parameters
name (str) – Taп class name
norder (float, optional) – Order in the Hasty tool
- delete()
Deletes tag class
Attribute
- class hasty.Attribute(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property attribute_type
type: string
- property description
type: string
- property norder
type: float
- property values
type: Dict
- edit(name: str, attribute_type: str, description: Optional[str] = None, norder: Optional[float] = None, values: Optional[List[str]] = None)
Edit attribute properties
- Parameters
Args –
name (str) – Attribute name
attribute_type (str) – Attribute type [‘SELECTION’, ‘MULTIPLE-SELECTION’, ‘TEXT’, ‘INT’, ‘FLOAT’, ‘BOOL’]
description (str, optional) – Attrbute description
norder (float, optional) – Order in the Hasty tool
values (list of str) – List of values for SELECTION and MULTIPLE-SELECTION attribute type
- delete()
Deletes attribute
Label
- class hasty.Label(requester, data, obj_params=None)
- property id
type: string
- property project_id
type: string
- property image_id
type: string
- property class_id
type: string
- property bbox
type: string
- property polygon
type: string
- property mask
type: string
- property z_index
type: string
- property external_id
type: string
- edit(label_class, bbox=None, polygon=None, mask=None, z_index=None, external_id=None)
Update label properties
- Parameters
label_class (LabelClass, str) – Label class or label class ID of the label
bbox (list of int) – Coordinates of bounding box [x_min, y_min, x_max, y_max]
polygon (list) – List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]]
mask (list of int) – RLE Encoded binary mask, (order right -> down)
z_index (float) – Z index of the label. A label with greater value is in front of a label with a lower one.
external_id (str, optional) – External Identifier
- delete()
Delete label
- get_attributes()
Get attributes values, list of
LabelAttribute
objects.
- set_attribute(attribute, value)
Set label attribute
- Parameters
attribute (~hasty.Attribute, str) –
value (str, float, int, bool, list of str) –
Tag
Attributer
- class hasty.Attributer(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, bboxes: Optional[List[List[str]]] = None, confidence_threshold: float = 0.5)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
bboxes (list of list of int) – List of bounding boxes [x_min, y_min, x_max, y_max]
confidence_threshold (float) – Confidence threshold [0, 1) (default 0.5)
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
attribute_id (str): Attribute id
lov_ids (list of str): List of attribute values
- Return type
List of List of dict
Detector
- class hasty.Detector(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, confidence_threshold: float = 0.5, max_detections_per_image: int = 100)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
confidence_threshold (float) – Confidence threshold [0, 1) (default 0.5)
max_detections_per_image (int) – Maximum detections per image (default 100)
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
score (float): Confidence score
class_id (str): Label class ID
- Return type
List of dict
InstanceSegmentor
- class hasty.InstanceSegmentor(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, confidence_threshold: float = 0.5, max_detections_per_image: int = 100)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
confidence_threshold (float) – Confidence threshold [0, 1) (default 0.5)
max_detections_per_image (int) – Maximum detections per image (default 100)
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
mask (list of int): RLE Encoded binary mask, (order right -> down)
score (float): Confidence score
class_id (str): Label class ID
- Return type
List of dict
SemanticSegmentor
- class hasty.SemanticSegmentor(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, min_size: float = 0.0)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
min_size (float) – Ignore prediction with an area less then min_size
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
mask (list of int): RLE Encoded binary mask, (order right -> down)
class_id (str): Label class ID
- Return type
List of dict
Label Utils
- hasty.label_utils.rle_encoding(x: array)
Encode binary mask to RLE
- Parameters
x (np.array) – numpy array of shape (height, width), 1 - mask, 0 - background
Returns run length as list
- hasty.label_utils.rle_decode(mask_rle: List[int], shape: Tuple[int])
Decodes mask from RLE format to binary mask. Returns numpy array, 1 - mask, 0 - background
- Parameters
mask_rle (list) – run-length as string formated (start length)
shape (tuple) – (width, height) of array to return
- hasty.label_utils.yolo2hasty(yolo_bbox: List[float], image_width: int, image_height: int)
Converts normalized YOLO bbox format (Xn_center, Yn_center, Wn, Hn) to Hasty format (x_min, y_min, x_max, y_max)
- Parameters
yolo_bbox (list of floats) – Normalized coordinates [X_center, Y_center, W, H] example [0.3, 0.4, 0.1, 0.25]
image_width (int) – Image width
image_height (int) – Image height
- hasty.label_utils.polygon2box(polygon: List[List[int]])
Converts polygon to bounding box [x_min, y_min, x_max, y_max]
- Parameters
polygon – List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]]