Skip to content

Commit 556fd04

Browse files
author
Val Brodsky
committed
Add lbox-clients
1 parent bbe3718 commit 556fd04

File tree

8 files changed

+141
-14
lines changed

8 files changed

+141
-14
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import mimetypes
55
import os
66
import random
7-
import sys
87
import time
98
import urllib.parse
109
from collections import defaultdict
@@ -18,6 +17,7 @@
1817
import labelbox.exceptions
1918
from labelbox import utils
2019
from labelbox.adv_client import AdvClient
20+
from labelbox.client import SDK_VERSION
2121
from labelbox.orm import query
2222
from labelbox.orm.db_object import DbObject
2323
from labelbox.orm.model import Entity, Field
@@ -81,14 +81,6 @@
8181

8282
logger = logging.getLogger(__name__)
8383

84-
_LABELBOX_API_KEY = "LABELBOX_API_KEY"
85-
86-
87-
def python_version_info():
88-
version_info = sys.version_info
89-
90-
return f"{version_info.major}.{version_info.minor}.{version_info.micro}-{version_info.releaselevel}"
91-
9284

9385
class Client:
9486
"""A Labelbox client.
@@ -126,6 +118,7 @@ def __init__(
126118
self._data_row_metadata_ontology = None
127119
self._request_client = RequestClient(
128120
api_key,
121+
sdk_version=SDK_VERSION,
129122
endpoint=endpoint,
130123
enable_experimental=enable_experimental,
131124
app_url=app_url,

libs/lbox-clients/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# python generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# venv
10+
.venv

libs/lbox-clients/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# https://github.com/ucyo/python-package-template/blob/master/Dockerfile
2+
FROM python:3.8-slim as rye
3+
4+
ENV LANG="C.UTF-8" \
5+
LC_ALL="C.UTF-8" \
6+
PATH="/home/python/.local/bin:/home/python/.rye/shims:$PATH" \
7+
PIP_NO_CACHE_DIR="false" \
8+
RYE_VERSION="0.34.0" \
9+
RYE_INSTALL_OPTION="--yes" \
10+
LABELBOX_TEST_ENVIRON="prod"
11+
12+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
13+
ca-certificates \
14+
curl \
15+
inotify-tools \
16+
make \
17+
# cv2
18+
libsm6 \
19+
libxext6 \
20+
ffmpeg \
21+
libfontconfig1 \
22+
libxrender1 \
23+
libgl1-mesa-glx \
24+
libgeos-dev \
25+
gcc \
26+
&& rm -rf /var/lib/apt/lists/*
27+
28+
RUN groupadd --gid 1000 python && \
29+
useradd --uid 1000 --gid python --shell /bin/bash --create-home python
30+
31+
USER 1000
32+
WORKDIR /home/python/
33+
34+
RUN curl -sSf https://rye.astral.sh/get | bash -
35+
36+
COPY --chown=python:python . /home/python/labelbox-python/
37+
WORKDIR /home/python/labelbox-python
38+
39+
RUN rye config --set-bool behavior.global-python=true && \
40+
rye config --set-bool behavior.use-uv=true && \
41+
rye pin 3.8 && \
42+
rye sync
43+
44+
CMD rye run unit && rye integration

libs/lbox-clients/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# lbox-example
2+
3+
This is an example module which can be cloned and reused to develop modules under the `lbox` namespace.
4+
5+
## Module Status: Experimental
6+
7+
**TLDR: This module may be removed or altered at any given time and there is no offical support.**
8+
9+
Please see [here](https://docs.labelbox.com/docs/product-release-phases) for the formal definition of `Experimental`.

libs/lbox-clients/pyproject.toml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[project]
2+
name = "lbox-example"
3+
version = "0.1.0"
4+
description = "This module contains client sdk uses to conntect to the Labelbox API and backends"
5+
authors = [
6+
{ name = "Labelbox", email = "engineering@labelbox.com" }
7+
]
8+
dependencies = [
9+
"requests>=2.22.0",
10+
"google-api-core>=1.22.1",
11+
]
12+
readme = "README.md"
13+
requires-python = ">= 3.8"
14+
15+
classifiers=[
16+
# How mature is this project?
17+
"Development Status :: 2 - Alpha",
18+
# Indicate who your project is intended for
19+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
20+
"Topic :: Software Development :: Libraries",
21+
"Intended Audience :: Developers",
22+
"Intended Audience :: Science/Research",
23+
"Intended Audience :: Education",
24+
# Pick your license as you wish
25+
"License :: OSI Approved :: Apache Software License",
26+
# Specify the Python versions you support here.
27+
"Programming Language :: Python :: 3",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
30+
"Programming Language :: Python :: 3.10",
31+
"Programming Language :: Python :: 3.11",
32+
"Programming Language :: Python :: 3.12",
33+
]
34+
keywords = ["ml", "ai", "labelbox", "labeling", "llm", "machinelearning", "edu"]
35+
36+
[project.urls]
37+
Homepage = "https://labelbox.com/"
38+
Documentation = "https://labelbox-python.readthedocs.io/en/latest/"
39+
Repository = "https://github.com/Labelbox/labelbox-python"
40+
Issues = "https://github.com/Labelbox/labelbox-python/issues"
41+
Changelog = "https://github.com/Labelbox/labelbox-python/blob/develop/libs/labelbox/CHANGELOG.md"
42+
43+
[build-system]
44+
requires = ["hatchling"]
45+
build-backend = "hatchling.build"
46+
47+
[tool.rye]
48+
managed = true
49+
dev-dependencies = []
50+
51+
[tool.rye.scripts]
52+
unit = "pytest tests/unit"
53+
integration = "python -c \"import sys; sys.exit(0)\""
54+
55+
[tool.hatch.metadata]
56+
allow-direct-references = true
57+
58+
[tool.hatch.build.targets.wheel]
59+
packages = ["src/lbox"]
60+
61+
[tool.pytest.ini_options]
62+
addopts = "-rP -vvv --durations=20 --cov=lbox.example --import-mode=importlib"

libs/lbox-clients/src/lbox/exceptions.py

Whitespace-only changes.

libs/labelbox/src/labelbox/request_client.py renamed to libs/lbox-clients/src/lbox/request_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
# type: ignore
21
import json
32
import logging
43
import os
54
import sys
65
from datetime import datetime, timezone
76
from types import MappingProxyType
87

8+
import labelbox.exceptions
99
import requests
1010
import requests.exceptions
1111
from google.api_core import retry
1212

13-
import labelbox.exceptions
14-
from labelbox import __version__ as SDK_VERSION
15-
1613
logger = logging.getLogger(__name__)
1714

1815
_LABELBOX_API_KEY = "LABELBOX_API_KEY"
@@ -33,6 +30,7 @@ class RequestClient:
3330

3431
def __init__(
3532
self,
33+
sdk_version,
3634
api_key=None,
3735
endpoint="https://api.labelbox.com/graphql",
3836
enable_experimental=False,
@@ -69,6 +67,7 @@ def __init__(
6967
self.endpoint = endpoint
7068
self.rest_endpoint = rest_endpoint
7169
self._connection: requests.Session = self._init_connection()
70+
self.sdk_version = sdk_version
7271

7372
def _init_connection(self) -> requests.Session:
7473
connection = (
@@ -87,7 +86,7 @@ def _default_headers(self):
8786
"Authorization": "Bearer %s" % self.api_key,
8887
"Accept": "application/json",
8988
"Content-Type": "application/json",
90-
"X-User-Agent": f"python-sdk {SDK_VERSION}",
89+
"X-User-Agent": f"python-sdk {self.sdk_version}",
9190
"X-Python-Version": f"{python_version_info()}",
9291
}
9392

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
# @patch.dict(os.environ, {'LABELBOX_API_KEY': 'bar'})
4+
def test_headers():
5+
client = RequestClient(api_key="api_key", endpoint="http://localhost:8080/_gql")
6+
assert client.headers
7+
assert client.headers["Authorization"] == "Bearer api_key"
8+
assert client.headers["Content-Type"] == "application/json"
9+
assert client.headers["User-Agent"]
10+
assert client.headers["X-Python-Version"]

0 commit comments

Comments
 (0)