Encord Objects

PropertyType

An enumeration.

class encord.objects.common.PropertyType(value)
  • RADIO = 'radio'
  • TEXT = 'text'
  • CHECKLIST = 'checklist'
class PropertyType(StringEnum):
    RADIO = "radio"
    TEXT = "text"
    CHECKLIST = "checklist"

Shape

An enumeration.

class encord.objects.common.Shape(value)
  • BOUNDING_BOX = 'bounding_box'
  • POLYGON = 'polygon'
  • POINT = 'point'
  • SKELETON = 'skeleton'
  • POLYLINE = 'polyline'
  • ROTATABLE_BOUNDING_BOX = 'rotatable_bounding_box'
  • BITMASK = 'bitmask'
class Shape(StringEnum):
    BOUNDING_BOX = "bounding_box"
    POLYGON = "polygon"
    POINT = "point"
    SKELETON = "skeleton"
    POLYLINE = "polyline"
    ROTATABLE_BOUNDING_BOX = "rotatable_bounding_box"
    BITMASK = "bitmask"

DeidentifyRedactTextMode

An enumeration.

class encord.objects.common.DeidentifyRedactTextMode(value)
  • REDACT_ALL_TEXT = 'REDACT_ALL_TEXT'
  • REDACT_NO_TEXT = 'REDACT_NO_TEXT'
  • REDACT_SENSITIVE_TEXT = 'REDACT_SENSITIVE_TEXT'
class DeidentifyRedactTextMode(Enum):
    REDACT_ALL_TEXT = "REDACT_ALL_TEXT"
    REDACT_NO_TEXT = "REDACT_NO_TEXT"
    REDACT_SENSITIVE_TEXT = "REDACT_SENSITIVE_TEXT"

SaveDeidentifiedDicomConditionType

An enumeration.

class encord.objects.common.SaveDeidentifiedDicomConditionType(value)
  • NOT_SUBSTR = 'NOT_SUBSTR'
  • IN = 'IN'
class SaveDeidentifiedDicomConditionType(Enum):
    NOT_SUBSTR = "NOT_SUBSTR"
    IN = "IN"

SaveDeidentifiedDicomConditionIn

class encord.objects.common.SaveDeidentifiedDicomConditionIn(value, dicom_tag, condition_type=SaveDeidentifiedDicomConditionType.IN)
  • value: List[str]
  • dicom_tag: str
  • condition_type: encord.objects.common.SaveDeidentifiedDicomConditionType = 'IN'
@dataclass
class SaveDeidentifiedDicomConditionIn:
    value: List[str]
    dicom_tag: str
    condition_type: SaveDeidentifiedDicomConditionType = SaveDeidentifiedDicomConditionType.IN

def to_dict(self) -> Dict[str, Any]:
        return {
            "value": self.value,
            "dicom_tag": self.dicom_tag,
            "condition_type": self.condition_type.value,
        }

to_dict

to_dict()

Return type:

Dict[str, Any]

    def to_dict(self) -> Dict[str, Any]:
        return {
            "value": self.value,
            "dicom_tag": self.dicom_tag,
            "condition_type": self.condition_type.value,
        }

SaveDeidentifiedDicomConditionNotSubstr

class encord.objects.common.SaveDeidentifiedDicomConditionNotSubstr(value, dicom_tag, condition_type=SaveDeidentifiedDicomConditionType.NOT_SUBSTR)
  • value: str
  • dicom_tag: str
  • condition_type: encord.objects.common.SaveDeidentifiedDicomConditionType = 'NOT_SUBSTR'
@dataclass
class SaveDeidentifiedDicomConditionNotSubstr:
    value: str
    dicom_tag: str
    condition_type: SaveDeidentifiedDicomConditionType = SaveDeidentifiedDicomConditionType.NOT_SUBSTR

def to_dict(self) -> Dict[str, Any]:
        return {
            "value": self.value,
            "dicom_tag": self.dicom_tag,
            "condition_type": self.condition_type.value,
        }

to_dict

to_dict()

Return type:

Dict[str, Any]

    def to_dict(self) -> Dict[str, Any]:
        return {
            "value": self.value,
            "dicom_tag": self.dicom_tag,
            "condition_type": self.condition_type.value,
        }

ProjectDataset

class encord.objects.project.ProjectDataset(dataset_hash, title, description)
  • dataset_hash: str
  • title: str
  • description: str

from_dict

static from_dict(d)

Return type:

ProjectDataset

from_list

classmethod from_list(l)

Return type:

List[ProjectDataset]

Attribute

Base class for shared Attribute fields

class encord.objects.attributes.Attribute(uid, feature_node_hash, name, required, dynamic)
  • name: str
  • required: bool
  • dynamic: bool
  • The dynamic member is part of every attribute. However it can only be true for top level (not nested) attributes that are part of an encord.objects.ontology_object.Object.

property options: Sequence[encord.objects.attributes.OptionType]

Return type:

Sequence[~OptionType]

property title: str

Return type:

str

get_property_type

abstract static: get_property_type()

Return type:

PropertyType

to_dict

to_dict()

Return type:

Dict[str, Any]

from_dict

static from_dict(d)

Return type:

Attribute

RadioAttribute

class encord.objects.attributes.RadioAttribute(uid, feature_node_hash, name, required, dynamic, options=None)

property options: Sequence[encord.objects.options.NestableOption]

Return type:

Sequence[NestableOption]

property children: Sequence[encord.objects.ontology_element.OntologyElement]

Return type:

Sequence[OntologyElement]

get_property_type()

static get_property_type()

Return type:

PropertyType

add_option

add_option(label, value=None, local_uid=None, feature_node_hash=None)

Parameters:

  • label (str) – user-visible name of the option
  • value (Optional[str]) – internal unique value; optional; normally mechanically constructed from the label
  • local_uid (Optional[int]) – integer identifier of the option. Normally auto-generated; omit this unless the aim is to create an exact clone of existing ontology
  • feature_node_hash (Optional[str]) – global identifier of the option. Normally auto-generated; omit this unless the aim is to create an exact clone of existing ontology

Return type:

NestableOption - a NestableOption instance attached to the attribute. This can be further specified by adding nested attributes.

ChecklistAttribute

class encord.objects.attributes.ChecklistAttribute(uid, feature_node_hash, name, required, dynamic, options=None)

get_property_type()

static get_property_type()

Return type:

PropertyType

property options: Sequence[encord.objects.attributes.OptionType]

Return type:

Sequence[FlatOption]

property children: Sequence[encord.objects.ontology_element.OntologyElement]

Return type:

Sequence[OntologyElement]

add_option

add_option(label, value=None, local_uid=None, feature_node_hash=None)

Parameters:

  • label (str) – user-visible name of the option.

  • value (Optional[str]) – internal unique value; optional; normally mechanically constructed from the label.

  • local_uid (Optional[int]) – integer identifier of the option. Normally auto-generated; omit this unless the aim is to create an exact clone of existing ontology.

  • feature_node_hash (Optional[str]) – global identifier of the option. Normally auto-generated; omit this unless the aim is to create an exact clone of existing ontology.

Return type:

FlatOption - a FlatOption instance attached to the attribute.

TextAttribute

class encord.objects.attributes.TextAttribute(uid, feature_node_hash, name, required, dynamic)
  • name: str
  • required: bool
  • dynamic: bool
  • The dynamic member is part of every attribute. However it can only be true for top level (not nested) attributes that are part of an encord.objects.ontology_object.Object.

uid: List[int]
feature_node_hash: str

get_property_type()

static get_property_type()

Return type:

PropertyType

short_uuid_str

Used as a condensed uuid.

encord.objects.utils.short_uuid_str()

Return type:

str

def short_uuid_str() -> str:
    """This is being used as a condensed uuid."""
    return base64.b64encode(uuid.uuid4().bytes[:6]).decode("utf-8")

check_type

encord.objects.utils.check_type(obj, type_)

Return type:

None

def check_type(obj: Any, type_: Optional[Type[Any]]) -> None:
    if not does_type_match(obj, type_):
        raise TypeError(f"Expected {type_}, got {type(obj)}")

does_type_match

encord.objects.utils.does_type_match(obj, type_)

Return type:

Boolean

def does_type_match(obj: Any, type_: Optional[Type[Any]]) -> bool:
    return True if type_ is None else isinstance(obj, type_)

checked_cast

encord.objects.utils.checked_cast(obj, type_)

Return type:

~T

def checked_cast(obj: Any, type_: Optional[Type[T]]) -> T:
    check_type(obj, type_)
    return cast(T, obj)

filter_by_type

encord.objects.utils.filter_by_type(objects, type_)

Return type:

List[~T]https://docs.encord.com/reference/sdk-ref-ontology-structure#t

def filter_by_type(objects: Iterable[Any], type_: Optional[Type[T]]) -> List[T]:
    return [object_ for object_ in objects if does_type_match(object_, type_)]

is_valid_email

Verify that an email address is a valid.

encord.objects.utils.is_valid_email(email)

Return type:

Boolean

def is_valid_email(email: str) -> bool:
    """
    Validate that an email is a valid one
    """
    regex = r"[^@]+@[^@]+\.[^@]+"
    return bool(re.match(regex, email))

check_email

encord.objects.utils.check_email(email)

Return type:

None

def check_email(email: str) -> None:
    if not is_valid_email(email):
        raise ValueError("Invalid email address")

Source

Common Object source.

from __future__ import annotations

import base64
import re
import uuid
from typing import Any, Iterable, List, Optional, Type, TypeVar, cast


def short_uuid_str() -> str:
    """This is being used as a condensed uuid."""
    return base64.b64encode(uuid.uuid4().bytes[:6]).decode("utf-8")


def _lower_snake_case(s: str):
    return s.lower().replace(" ", "_")


def check_type(obj: Any, type_: Optional[Type[Any]]) -> None:
    if not does_type_match(obj, type_):
        raise TypeError(f"Expected {type_}, got {type(obj)}")


def does_type_match(obj: Any, type_: Optional[Type[Any]]) -> bool:
    return True if type_ is None else isinstance(obj, type_)


T = TypeVar("T")


def checked_cast(obj: Any, type_: Optional[Type[T]]) -> T:
    check_type(obj, type_)
    return cast(T, obj)


def filter_by_type(objects: Iterable[Any], type_: Optional[Type[T]]) -> List[T]:
    return [object_ for object_ in objects if does_type_match(object_, type_)]


def is_valid_email(email: str) -> bool:
    """
    Validate that an email is a valid one
    """
    regex = r"[^@]+@[^@]+\.[^@]+"
    return bool(re.match(regex, email))


def check_email(email: str) -> None:
    if not is_valid_email(email):
        raise ValueError("Invalid email address")

ProjectDataset

class encord.objects.project.ProjectDataset(dataset_hash, title, description)
  • dataset_hash: str
  • title: str
  • description: str
@dataclass
class ProjectDataset:
    dataset_hash: str
    title: str
    description: str

@staticmethod
    def from_dict(d: dict) -> ProjectDataset:
        return ProjectDataset(
            dataset_hash=d["dataset_hash"],
            title=d["title"],
            description=d["description"],
        )


@classmethod
    def from_list(cls, l: list) -> List[ProjectDataset]:
        return [cls.from_dict(i) for i in l]

from_dict

static from_dict(d)

Return type:

ProjectDataset

    @staticmethod
    def from_dict(d: dict) -> ProjectDataset:
        return ProjectDataset(
            dataset_hash=d["dataset_hash"],
            title=d["title"],
            description=d["description"],
        )

from_list

classmethod from_list(l)

Return type:

ListProjectDataset

    @classmethod
    def from_list(cls, l: list) -> List[ProjectDataset]:
        return [cls.from_dict(i) for i in l]

Source

from __future__ import annotations

from dataclasses import dataclass
from typing import List


@dataclass
class ProjectDataset:
    dataset_hash: str
    title: str
    description: str

@staticmethod
    def from_dict(d: dict) -> ProjectDataset:
        return ProjectDataset(
            dataset_hash=d["dataset_hash"],
            title=d["title"],
            description=d["description"],
        )

@classmethod
    def from_list(cls, l: list) -> List[ProjectDataset]:
        return [cls.from_dict(i) for i in l]