Skip to content

Commit 121d1eb

Browse files
caitlinwheelessmatt-bernstein
authored andcommitted
docs: Update readme (#603)
1 parent c0db6e7 commit 121d1eb

File tree

1 file changed

+40
-89
lines changed

1 file changed

+40
-89
lines changed

README.md

Lines changed: 40 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ poetry add label-studio-sdk
2424
# Usage
2525

2626
```python
27-
from label_studio_sdk.client import LabelStudio
27+
from label_studio_sdk import LabelStudio
2828

29-
ls = LabelStudio(
29+
client = LabelStudio(
3030
base_url='YOUR_LABEL_STUDIO_URL',
3131
api_key="YOUR_API_KEY",
3232
)
@@ -103,105 +103,56 @@ from label_studio_sdk._legacy import Project
103103

104104
</details>
105105

106-
# Examples
107-
108-
Check more examples [here](https://api.labelstud.io/).
109-
110-
## Create a new project
106+
# Example: Create a new project with tasks
111107

112108
```python
113-
from label_studio_sdk.label_interface import LabelInterface
114-
from label_studio_sdk.label_interface.create import labels
115-
116-
project = ls.projects.create(
117-
title="Project name",
118-
description="Project description",
119-
label_config=LabelInterface.create({
120-
"image": "Image",
121-
"bbox": labels(["cat", "dog"], tag_type="RectangleLabels")
122-
})
123-
)
124-
```
109+
# Import the SDK and the client module
110+
from label_studio_sdk import LabelStudio
125111

126-
## Create a new task
127-
128-
```python
129-
task = ls.tasks.create(
130-
project=project.id,
131-
data={"image": "https://example.com/image.jpg"}
112+
client = LabelStudio(
113+
base_url="http://localhost:8080", # <-- put your LS URL here
114+
api_key="YOUR_API_KEY", # <-- put your API key here
132115
)
133-
```
134-
Now you can open the project `PROJECT_ID` in the Label Studio UI and create annotations for the task.
135116

136-
## Export annotations
137-
138-
```python
139-
annotations = [
140-
task.annotations
141-
for task in ls.tasks.list(project=project.id, fields='all')
142-
if task.annotations
143-
]
144-
```
145-
146-
147-
## Async client
148-
149-
```python
150-
from label_studio_sdk.client import AsyncLabelStudio
151-
152-
client = AsyncLabelStudio(
153-
api_key="YOUR_API_KEY",
117+
label_config = """
118+
<View>
119+
<Header value="Choose text sentiment:"/>
120+
<Text name="text" value="$text"/>
121+
<Choices name="sentiment" toName="text" choice="single">
122+
<Choice value="Positive"/>
123+
<Choice value="Negative"/>
124+
<Choice value="Neutral"/>
125+
</Choices>
126+
</View>
127+
"""
128+
129+
# Create project
130+
project = client.projects.create(
131+
title="Sentiment Classification",
132+
label_config=label_config
154133
)
155-
```
156134

157-
## Advanced
135+
# (Optional) validate the config to catch mistakes early
136+
client.projects.validate_label_config(id=project.id, label_config=label_config)
158137

159-
### Timeouts
160-
By default, requests time out after 60 seconds. You can configure this with a
161-
timeout option at the client or request level.
162-
163-
```python
164-
from label_studio_sdk.client import LabelStudio
165-
166-
ls = LabelStudio(
167-
# All timeouts set to 20 seconds
168-
timeout=20.0
138+
# Create a single task
139+
task = client.tasks.create(
140+
project=project.id,
141+
data={"text": "Label Studio is the best!"} # 'text' matches value="$text"
169142
)
170-
171-
ls.projects.create(..., {
172-
# Override timeout for a specific method
173-
timeout=20.0
174-
})
175-
```
176-
177-
### Custom HTTP client
178-
You can override the httpx client to customize it for your use-case. Some common use-cases
179-
include support for proxies and transports.
180-
181-
```python
182-
import httpx
183-
184-
from label_studio_sdk.client import LabelStudio
185-
186-
ls = LabelStudio(
187-
http_client=httpx.Client(
188-
proxies="http://my.test.proxy.example.com",
189-
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
190-
),
143+
print(f"Created task id: {task.id}")
144+
145+
# Or create multiple tasks at once
146+
client.projects.import_tasks(
147+
id=project.id,
148+
request=[
149+
{"text": "I love Label Studio"},
150+
{"text": "Label Studio helps me ship faster"},
151+
]
191152
)
192153
```
193154

194-
## Enterprise features
195-
196-
### Create comments
197-
198-
```python
199-
comment = ls.comments.create(
200-
project=project.id,
201-
annotation=annotation.id,
202-
text="Comment text"
203-
)
204-
```
155+
For additional examples, see [our API reference](https://api.labelstud.io/).
205156

206157
<!-- Begin Contributing, generated by Fern -->
207158
# Contributing

0 commit comments

Comments
 (0)