> ## Documentation Index
> Fetch the complete documentation index at: https://docs.labelbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick start

> Short introduction towards Labelbox Python SDK, geared mainly for new users.

<CardGroup>
  <Card title="Open in Colab" icon="infinity" iconType="solid" horizontal href="https://colab.research.google.com/github/Labelbox/labelbox-notebooks/blob/main/basics/quick_start.ipynb" />

  <Card title="Open in GitHub" icon="github" iconType="solid" horizontal href="https://github.com/Labelbox/labelbox-notebooks/blob/main/basics/quick_start.ipynb" />
</CardGroup>

This short introduction to Labelbox Python SDK is designed mainly for new users. The example will introduce you to Labelbox Python SDK concepts that you will use commonly. We will demonstrate a simple but common workflow of importing an image data row, setting up a project, and exporting.

## Example: Import data rows to exporting from project

### Before you start

We must first install the `Labelbox` library and then import the SDK module. It is recommended to install `"labelbox[data]"` over `labelbox` to obtain all the correct dependencies. We will also be importing the Python UUID library to generate universal unique IDs for the variety of objects that will be created with this notebook.

<CodeGroup>
  ```shell Shell theme={null}
  pip install -q "labelbox[data]"
  ```
</CodeGroup>

<CodeGroup>
  ```python Python theme={null}
  import labelbox as lb
  import uuid
  ```
</CodeGroup>

Replace the value of `API_KEY` with a valid [API key](/reference/create-api-key) to connect to the Labelbox client.

<CodeGroup>
  ```python Python theme={null}
  API_KEY = None
  client = lb.Client(API_KEY)
  ```
</CodeGroup>

## Step 1: Create dataset and import data row

Below, we will create a <Tooltip tip="dataset - A collection of data rows from a single domain or source. When you import a set of data rows to Labelbox, it is stored as a dataset. You can use batches to submit a subset of data rows from a dataset to a labeling project.">dataset</Tooltip> and then attach a publicly hosted image <Tooltip tip="data row - The internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset (e.g., the URL to your cloud-hosted file, metadata, media attributes, annotation information, attachments, etc).">data row</Tooltip>. Typically, you would import data rows hosted on a cloud provider (*recommended*) or import them locally. For more information, visit our [import image data section](/reference/image) in our developer guides. You can find your dataset inside the [*Catalog*](/docs/catalog-overview) section of Labelbox.

<CodeGroup>
  ```python Python theme={null}
  # Create dataset from client
  dataset = client.create_dataset(name="Quick Start Example Dataset")

  global_key = str(uuid.uuid4()) # Unique user specified ID

  # Data row structure

  image_data_rows = [{
    "row_data": "https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg",
    "global_key": global_key,
    "media_type": "IMAGE",
  }]

  # Bulk import data row

  task = dataset.create_data_rows(image_data_rows) # List of data rows
  task.wait_till_done()
  print(task.errors) # Print any errors
  ```
</CodeGroup>

## Step 2: Creating an ontology

Before sending our data row to a labeling project, we must create an <Tooltip tip="ontology - A collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. When you are in the editor, the ontology is what appears in the &#x22;Tools&#x22; panel.">ontology</Tooltip>. The example below will create a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](/reference/ontology) inside our developer guides.

<CodeGroup>
  ```python Python theme={null}
  # Bounding box feature
  object_features = [
      lb.Tool(
          tool=lb.Tool.Type.BBOX,
          name="regulatory-sign",
          color="#ff0000",
      )
  ]

  # Checklist feature
  classification_features = [
      lb.Classification(
          class_type=lb.Classification.Type.CHECKLIST,
          name="Quality Issues",
          options=[
              lb.Option(value="blurry", label="Blurry"),
              lb.Option(value="distorted", label="Distorted"),
          ],
      )
  ]

  # Builder function
  ontology_builder = lb.OntologyBuilder(tools=object_features,
                                        classifications=classification_features)

  # Create ontology
  ontology = client.create_ontology(
      "Ontology from new features",
      ontology_builder.asdict(),
      media_type=lb.MediaType.Image,
  )
  ```
</CodeGroup>

## Step 3: Creating a project and attaching our ontology

Now that we have made our ontology, we are ready to create a <Tooltip tip="project - The labeling environment in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre- labeled data.">project</Tooltip> where we can label our data row.

<CodeGroup>
  ```python Python theme={null}
  # Create a new project
  project = client.create_project(
      name="Quick Start Example Project",
      media_type=lb.MediaType.Image,
  )

  # Attach created ontology

  project.connect_ontology(ontology)
  ```
</CodeGroup>

## Step 4: Sending our data row to our project by creating a batch

With our project created, we can send our data rows by creating a <Tooltip tip="batch - A curated selection of data rows you can send to a project for labeling. You can create a batch from Catalog.">batch</Tooltip>. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row. For more information on batches, review the [batches section](/reference/batch#create-a-batch) of our developer guides.

<CodeGroup>
  ```python Python theme={null}
  project.create_batch(
      name="Quick Start Example Batch" + str(uuid.uuid4()),
      global_keys=[
          global_key
      ],  # Global key we used earlier in this guide to create our dataset
      priority=5,
  )
  ```
</CodeGroup>

## Step 5: Exporting from our project

We have now successfully set up a project for labeling using only the SDK!

From here, you can either label our data row directly inside the [labeling queue](/docs/labeling-queue) or [import annotations](/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](/reference/export-overview) developer guide.

<CodeGroup>
  ```python Python theme={null}
  # Start export from project
  export_task = project.export()
  export_task.wait_till_done()

  # Stream the export using a callback function

  def json_stream_handler(output: labelbox.BufferedJsonConverterOutput):
  print(output.json)

  export_task.get_buffered_stream(stream_type=labelbox.StreamType.RESULT).start(stream_handler=json_stream_handler)

  # Collect all exported data into a list

  export_json = [data_row.json for data_row in export_task.get_buffered_stream()]
  ```
</CodeGroup>

## Clean up

This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown.

<CodeGroup>
  ```python Python theme={null}
  # project.delete()
  # client.delete_unused_ontology(ontology.uid)
  # dataset.delete()
  ```
</CodeGroup>
