|
1 | 1 | # Labelbox Python SDK
|
| 2 | +[](https://github.com/Labelbox/labelbox-python/releases) |
| 3 | +[](https://github.com/labelbox/labelbox-python/actions) |
| 4 | +[](https://pepy.tech/project/labelbox) |
| 5 | +[](https://libraries.io/github/labelbox/labelbox-python) |
| 6 | +[](https://github.com/labelbox/labelbox-python/issues) |
| 7 | +[](https://docs.labelbox.com/changelog) |
| 8 | +[](https://opensource.org/licenses/Apache-2.0) |
| 9 | +[](https://twitter.com/labelbox) |
| 10 | +[](https://www.linkedin.com/company/labelbox/) |
2 | 11 |
|
3 |
| -Labelbox is the enterprise-grade training data solution with fast AI enabled labeling tools, labeling automation, human workforce, data management, a powerful API for integration & SDK for extensibility. Visit [Labelbox](http://labelbox.com/) for more information. |
4 | 12 |
|
5 |
| -The Labelbox Python API offers a simple, user-friendly way to interact with the Labelbox back-end. |
| 13 | +Labelbox is a cloud-based data-centric AI platform designed to help teams create high-quality training data for their AI models. It provides a suite of tools and features that streamline the process of data curation, labeling, model output evaluation for computer vision and large language models. Visit [Labelbox](http://labelbox.com/) for more information. |
6 | 14 |
|
7 |
| -## Table of Contents |
8 | 15 |
|
9 |
| -- [Labelbox Python SDK](#labelbox-python-sdk) |
10 |
| - - [Table of Contents](#table-of-contents) |
11 |
| - - [Requirements](#requirements) |
12 |
| - - [Installation](#installation) |
13 |
| - - [Note for Windows users](#note-for-windows-users) |
14 |
| - - [Documentation](#documentation) |
15 |
| - - [Authentication](#authentication) |
16 |
| - - [Contribution](#contribution) |
17 |
| - - [Testing](#testing) |
| 16 | +The Python SDK provides a convenient way to interact with Labelbox programmatically, offering advantages over REST or GraphQL APIs: |
18 | 17 |
|
19 |
| -## Requirements |
| 18 | +* **Simplified interactions:** The SDK abstracts away the complexities of API calls, making it easier to work with Labelbox. |
| 19 | +* **Object-oriented approach:** The SDK provides an object-oriented interface, allowing you to interact with Labelbox entities (projects, datasets, labels, etc.) as Python objects. |
| 20 | +* **Extensibility:** The SDK can be extended to support custom data formats and operations. |
20 | 21 |
|
21 |
| -- Use Python 3.7, 3.8, 3.9 and 3.10 |
22 |
| -- [Create an account](http://app.labelbox.com/) |
23 |
| -- [Generate an API key](https://docs.labelbox.com/docs/create-an-api-key) |
| 22 | +## Table of Contents |
| 23 | +- [Installation](#installation) |
| 24 | +- [Code Architecture](#code-architecture) |
| 25 | +- [Contribution Guidelines](#contribution-guidelines) |
| 26 | +- [Develop with AI Assistance](#develop-with-ai-assistance) |
| 27 | +- [Documentation](#documentation) |
24 | 28 |
|
25 | 29 | ## Installation
|
| 30 | + |
26 | 31 |
|
27 |
| -Prerequisite: Install pip |
28 |
| - |
29 |
| -`pip` is a package manager for Python. **On macOS**, you can set it up to use the default python3 install via - |
30 |
| - |
31 |
| -``` |
32 |
| -curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py |
33 |
| -python3 get-pip.py |
34 |
| -``` |
35 |
| - |
36 |
| -If the installation completes with a warning re: pip not being in your path, you'll need to add it by modifying your shell config (`.zshrc`, `.bashrc` or similar). You might have to modify the command below depending on the version of python3 on your machine. |
| 32 | +Welcome to the quick start guide for integrating Labelbox into your Python projects. Whether you're looking to incorporate advanced data labeling into your workflow or simply explore the capabilities of the Labelbox Python SDK, this guide will walk you through the two main methods of setting up Labelbox in your environment: via a package manager and by building it locally. |
37 | 33 |
|
38 |
| -``` |
39 |
| -export PATH=/Users/<your-macOS-username>/Library/Python/3.8/bin:$PATH |
40 |
| -``` |
| 34 | +### Install using pip |
41 | 35 |
|
42 |
| -Install SDK locally, using Python's Pip manager |
| 36 | +To get started with the least amount of hassle, follow these simple steps to install the Labelbox Python SDK using pip, Python's package manager. |
43 | 37 |
|
44 |
| -``` |
45 |
| -pip3 install -e . |
46 |
| -``` |
| 38 | +1. **Ensure pip is installed:** First, make sure you have `pip` installed on your system. It's the tool we'll use to install the SDK. |
| 39 | + |
| 40 | +2. **Sign up for Labelbox:** If you haven't already, create a free account at [Labelbox](http://app.labelbox.com/) to access its features. |
47 | 41 |
|
48 |
| -Install dependencies |
| 42 | +3. **Generate your API key:** Log into Labelbox and navigate to [Account > API Keys](https://docs.labelbox.com/docs/create-an-api-key) to generate an API key. You'll need this for programmatic access to Labelbox. |
49 | 43 |
|
50 |
| -``` |
51 |
| -pip3 install -r requirements.txt |
52 |
| -``` |
| 44 | +4. **Install the SDK:** Open your terminal or command prompt and run the following command to install the Labelbox Python SDK: |
| 45 | + |
| 46 | + ```bash |
| 47 | + pip install labelbox |
| 48 | + ``` |
53 | 49 |
|
54 |
| -To install dependencies required for data processing modules use: |
| 50 | +5. **Install optional dependencies:** For enhanced functionality, such as data processing, you can install additional dependencies with: |
| 51 | + |
| 52 | + ```bash |
| 53 | + pip install "labelbox[data]" |
| 54 | + ``` |
55 | 55 |
|
56 |
| -``` |
57 |
| -pip install "labelbox[data]" |
58 |
| -``` |
| 56 | + This includes essential libraries like Shapely, GeoJSON, NumPy, Pillow, and OpenCV-Python, enabling you to handle a wide range of data types and perform complex operations. |
59 | 57 |
|
60 |
| -## Documentation |
61 |
| - |
62 |
| -- [Visit our docs](https://docs.labelbox.com/reference) to learn how the SDK works |
63 |
| -- Checkout our [notebook examples](examples/) to follow along with interactive tutorials |
64 |
| -- view our [API reference](https://labelbox-python.readthedocs.io/en/latest/index.html). |
65 |
| - |
66 |
| -## Authentication |
| 58 | +### Building and installing locally |
67 | 59 |
|
68 |
| -Labelbox uses API keys to validate requests. You can create and manage API keys on [Labelbox](https://app.labelbox.com/account/api-keys). Pass your API key as an environment variable. Then, import and initialize the API Client. |
| 60 | +For those who prefer or require a more hands-on approach, such as contributing to the SDK or integrating it into a complex project, building the SDK locally is the way to go. |
69 | 61 |
|
70 |
| -``` |
71 |
| -user@machine:~$ export LABELBOX_API_KEY="<your local api key here>" |
72 |
| -user@machine:~$ python3 |
73 | 62 |
|
74 |
| -from labelbox import Client |
75 |
| -client = Client() |
76 |
| -``` |
| 63 | +#### Steps for local installation |
77 | 64 |
|
78 |
| -- Update api_key and endpoint if not using the production cloud deployment |
| 65 | +1. **Clone the SDK repository:** First, clone the Labelbox SDK repository from GitHub to your local machine. |
79 | 66 |
|
80 |
| -``` |
81 |
| -# On prem |
82 |
| -client = Client( endpoint = "<local deployment>") |
| 67 | +2. **Install required dependencies:** To ensure all dependencies are met, run: |
83 | 68 |
|
84 |
| -# Local |
85 |
| -client = Client(api_key=os.environ['LABELBOX_TEST_API_KEY_LOCAL'], endpoint="http://localhost:8080/graphql") |
| 69 | + ```bash |
| 70 | + pip install -r requirements.txt |
| 71 | + ``` |
86 | 72 |
|
87 |
| -# Staging |
88 |
| -client = Client(api_key=os.environ['LABELBOX_TEST_API_KEY_LOCAL'], endpoint="https://api.lb-stage.xyz/graphql") |
89 |
| -``` |
| 73 | +3. **Install the SDK locally:** Navigate to the root directory of the cloned repository and run: |
90 | 74 |
|
91 |
| -## Contribution |
| 75 | + ```bash |
| 76 | + pip install -e . |
| 77 | + ``` |
92 | 78 |
|
93 |
| -Please consult `CONTRIB.md` |
| 79 | + For additional data processing capabilities, remember to install the `data` extra as mentioned in the easy installation section. |
94 | 80 |
|
95 |
| -## Testing |
96 | 81 |
|
97 |
| -1. Update the `Makefile` with your `local`, `staging`, `prod` API key. Ensure that docker has been installed on your system. Make sure the key is not from a free tier account. |
98 |
| -2. To test on `local`: |
| 82 | +## Code architecture |
| 83 | +The Labelbox Python SDK is designed to provide a clean and intuitive interface for interacting with the Labelbox API. It primarily uses GraphQL for communication, with some REST API calls for specific functionalities. The SDK wraps the GraphQL API calls and provides object-oriented representations of Labelbox entities like projects, datasets, and labels. This allows developers to interact with Labelbox in a more Pythonic way, making code easier to read and maintain. |
99 | 84 |
|
100 |
| -``` |
101 |
| -user@machine:~$ export LABELBOX_TEST_API_KEY_LOCAL="<your local api key here>" |
102 |
| -make test-local # with an optional flag: PATH_TO_TEST=tests/integration/...etc LABELBOX_TEST_API_KEY_LOCAL=specify_here_or_export_me |
103 |
| -``` |
| 85 | +Key files and classes include: |
104 | 86 |
|
105 |
| -3. To test on `staging`: |
| 87 | +- **`labelbox/client.py`:** Contains the `Client` class, which provides methods for interacting with the Labelbox API. |
| 88 | +- **`labelbox/orm/model.py`:** Defines the data model for Labelbox entities like projects, datasets, and labels. |
| 89 | +- **`labelbox/schema/*.py`:** Contains classes representing specific Labelbox entities and their attributes. |
| 90 | +- **`labelbox/data/annotation_types/*.py`:** Defines classes for different annotation types, such as bounding boxes, polygons, and classifications. |
| 91 | +- **`labelbox/data/serialization/*.py`:** Provides converters for different data formats. |
106 | 92 |
|
107 |
| -``` |
108 |
| -user@machine:~$ export LABELBOX_TEST_API_KEY_STAGING="<your staging api key here>" |
109 |
| -make test-staging # with an optional flag: PATH_TO_TEST=tests/integration/...etc LABELBOX_TEST_API_KEY_STAGING=specify_here_or_export_me |
110 |
| -``` |
| 93 | +The SDK wraps the GraphQL APIs and provides a Pythonic interface for interacting with Labelbox. |
111 | 94 |
|
112 |
| -4. To test on `prod`: |
| 95 | +## Contribution guidelines |
| 96 | +We encourage developers to contribute to the Labelbox Python SDK and help improve its functionality and usability. Please refer to the [CONTRIB.md](CONTRIB.md) file in the root folder of the repository for detailed information on how to contribute. |
113 | 97 |
|
114 |
| -``` |
115 |
| -user@machine:~$ export LABELBOX_TEST_API_KEY_PROD="<your prod api key here>" |
116 |
| -make test-prod # with an optional flag: PATH_TO_TEST=tests/integration/...etc LABELBOX_TEST_API_KEY_PROD=specify_here_or_export_me |
117 |
| -``` |
| 98 | +## Develop with AI assistance |
| 99 | +### Use the codebase as context for large language models |
| 100 | +Using the [GPT repository loader](https://github.com/mpoon/gpt-repository-loader), we have created `lbx_prompt.txt` that contains data from all `.py` and `.md` files. The file has about 730k tokens. We recommend using Gemini 1.5 Pro with 1 million context length window. |
118 | 101 |
|
119 |
| -5. If you make any changes and need to rebuild the image used for testing, force a rebuild with the `-B` flag |
120 |
| - |
121 |
| -``` |
122 |
| -make -B {build|test-staging|test-prod} |
123 |
| -``` |
| 102 | +## Documentation |
| 103 | +The Labelbox Python SDK is well-documented to help developers get started quickly and use the SDK effectively. Here are some resources: |
124 | 104 |
|
125 |
| -6. Testing against Delegated Access will be skipped unless the local env contains the key: |
126 |
| -DA_GCP_LABELBOX_API_KEY. These tests will be included when run against a PR. If you would like to test it manually, please reach out to the Devops team for information on the key. |
| 105 | +- [Official documentation](https://docs.labelbox.com/docs/overview) |
| 106 | +- [Notebook examples](https://github.com/Labelbox/labelbox-python/tree/master/examples) |
| 107 | +- [Python SDK reference docs](https://labelbox-python.readthedocs.io/en/latest/) |
0 commit comments