annotide 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- annotide-0.1.0/LICENSE +201 -0
- annotide-0.1.0/NOTICE +7 -0
- annotide-0.1.0/PKG-INFO +18 -0
- annotide-0.1.0/README.md +108 -0
- annotide-0.1.0/annotide/__init__.py +22 -0
- annotide-0.1.0/annotide/cli.py +214 -0
- annotide-0.1.0/annotide/client.py +660 -0
- annotide-0.1.0/annotide/errors.py +58 -0
- annotide-0.1.0/annotide/mcp_server.py +213 -0
- annotide-0.1.0/annotide/models.py +2683 -0
- annotide-0.1.0/annotide/py.typed +0 -0
- annotide-0.1.0/annotide.egg-info/PKG-INFO +18 -0
- annotide-0.1.0/annotide.egg-info/SOURCES.txt +20 -0
- annotide-0.1.0/annotide.egg-info/dependency_links.txt +1 -0
- annotide-0.1.0/annotide.egg-info/entry_points.txt +2 -0
- annotide-0.1.0/annotide.egg-info/requires.txt +11 -0
- annotide-0.1.0/annotide.egg-info/top_level.txt +1 -0
- annotide-0.1.0/pyproject.toml +62 -0
- annotide-0.1.0/setup.cfg +4 -0
- annotide-0.1.0/tests/test_cli.py +185 -0
- annotide-0.1.0/tests/test_client.py +401 -0
- annotide-0.1.0/tests/test_mcp_server.py +226 -0
annotide-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
annotide-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Annotide Python SDK, CLI and MCP server
|
|
2
|
+
Copyright 2026 R Squared Data Solutions (https://annotide.com)
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE). The Annotide
|
|
5
|
+
server this SDK talks to is licensed separately, under the Elastic License
|
|
6
|
+
2.0. "Annotide" is a trademark of R Squared Data Solutions; the Apache
|
|
7
|
+
License grants no rights to it (section 6).
|
annotide-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: annotide
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cloud-agnostic annotation platform — Python SDK and CLI (API-3)
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
License-File: NOTICE
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Provides-Extra: mcp
|
|
11
|
+
Requires-Dist: mcp<3,>=2.2; extra == "mcp"
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: mcp<3,>=2.2; extra == "dev"
|
|
14
|
+
Requires-Dist: pytest>=8.3; extra == "dev"
|
|
15
|
+
Requires-Dist: ruff>=0.8; extra == "dev"
|
|
16
|
+
Requires-Dist: mypy>=1.13; extra == "dev"
|
|
17
|
+
Requires-Dist: datamodel-code-generator>=0.83; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
annotide-0.1.0/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# annotide
|
|
2
|
+
|
|
3
|
+
Python SDK and command line for the Annotide API (API-3). One
|
|
4
|
+
runtime dependency (`httpx`); responses are plain dicts typed with
|
|
5
|
+
`TypedDict`s generated from the API's OpenAPI document.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install -e sdk # from a checkout; not on a package index yet
|
|
9
|
+
export ANNOTIDE_URL=https://annotate.example.com
|
|
10
|
+
export ANNOTIDE_API_KEY=... # Settings → API keys; use a service account for CI
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Python
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from annotide import Client, JobFailedError
|
|
17
|
+
|
|
18
|
+
with Client() as client: # reads ANNOTIDE_URL / ANNOTIDE_API_KEY
|
|
19
|
+
project = next(p for p in client.list_projects() if p["name"] == "Cars")
|
|
20
|
+
|
|
21
|
+
# Freeze the dataset, then export it reproducibly.
|
|
22
|
+
snapshot = client.take_snapshot(
|
|
23
|
+
project["id"],
|
|
24
|
+
"2026-q3",
|
|
25
|
+
split={"train": 0.8, "val": 0.1, "test": 0.1, "seed": 0, "group_by": "folder"},
|
|
26
|
+
)
|
|
27
|
+
client.export(project["id"], "coco", "train.zip", snapshot_id=snapshot["id"], split="train")
|
|
28
|
+
|
|
29
|
+
# Import existing labels; a dry run reports what would happen.
|
|
30
|
+
report = client.import_file(project["id"], "labels.json", "coco", dry_run=True)
|
|
31
|
+
print(report["result"])
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- Errors are `ApiError` (`status`, `title`, `detail` from the RFC 9457
|
|
35
|
+
body); a job that ends `failed`/`cancelled` raises `JobFailedError`, one
|
|
36
|
+
that outlives its `timeout` raises `JobTimeoutError`.
|
|
37
|
+
- A 429 waits for `Retry-After` and repeats. Gateway errors (502/503/504)
|
|
38
|
+
repeat only when that is harmless: reads, and creates, which always carry
|
|
39
|
+
an `Idempotency-Key` so a repeat answers the first row.
|
|
40
|
+
- Export downloads go straight to storage with the signed URL; the API key
|
|
41
|
+
is never sent there.
|
|
42
|
+
- `client.request(method, path, ...)` reaches any endpoint without a method.
|
|
43
|
+
|
|
44
|
+
## Command line
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
annotide whoami
|
|
48
|
+
annotide projects list | jq -r '.name'
|
|
49
|
+
annotide snapshots create <project> 2026-q3 --split 0.8,0.1,0.1 --group-by folder
|
|
50
|
+
annotide export <project> --format coco --snapshot <id> --split train -o train.zip
|
|
51
|
+
annotide import <project> labels.json --format coco --class-map '{"auto": "car"}' --dry-run
|
|
52
|
+
annotide jobs wait <job>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Lists print as JSON Lines, single objects as JSON; errors go to stderr with
|
|
56
|
+
exit status 1. The key is read from `ANNOTIDE_API_KEY` only, so it never
|
|
57
|
+
lands in shell history.
|
|
58
|
+
|
|
59
|
+
## MCP server for AI agents (API-8)
|
|
60
|
+
|
|
61
|
+
`annotide mcp` serves the [Model Context Protocol](https://modelcontextprotocol.io)
|
|
62
|
+
over stdio, so an AI agent (Claude Code, Claude Desktop, or any MCP client)
|
|
63
|
+
can pre-label a project. It calls the REST API with an API key, so the agent
|
|
64
|
+
can do exactly what that account may do. It can list projects and their label
|
|
65
|
+
schema, view items (images come back as images), read annotations, claim and
|
|
66
|
+
release tasks, and post pre-labels. It cannot submit, review, delete or
|
|
67
|
+
export.
|
|
68
|
+
|
|
69
|
+
Setup, once per agent:
|
|
70
|
+
|
|
71
|
+
1. **Service account.** Settings → API keys → Service accounts: create one,
|
|
72
|
+
mint a `write` key, and add the account to the project as an annotator.
|
|
73
|
+
2. **Model.** Models → Register model, name it after the agent, and leave
|
|
74
|
+
the endpoint empty. That makes it an *external producer*: the platform
|
|
75
|
+
never calls it, and the agent posts the pre-labels. Add version 1 and
|
|
76
|
+
note its id.
|
|
77
|
+
3. **Client config.** For Claude Code (`.mcp.json`) or Claude Desktop:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"mcpServers": {
|
|
82
|
+
"annotation": {
|
|
83
|
+
"command": "annotation",
|
|
84
|
+
"args": ["mcp"],
|
|
85
|
+
"env": {
|
|
86
|
+
"ANNOTIDE_URL": "https://annotate.example.com",
|
|
87
|
+
"ANNOTIDE_API_KEY": "ak_…",
|
|
88
|
+
"ANNOTIDE_MODEL_VERSION_ID": "<model version id>"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Install with `pip install "annotide[mcp]"`. Pre-labels arrive as
|
|
96
|
+
`draft` versions authored by the model version. People review and submit
|
|
97
|
+
them as usual, and a pre-label never replaces human work (ML-10).
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
make install # from the repository root: creates sdk/.venv
|
|
103
|
+
cd sdk && .venv/bin/pytest && .venv/bin/mypy annotide tests tools
|
|
104
|
+
make openapi # after an API change: docs/openapi.json + models.py
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`annotide/models.py` is generated; never edit it by hand. CI fails when
|
|
108
|
+
it or `docs/openapi.json` is stale.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Python SDK for the Annotide API (API-3).
|
|
2
|
+
|
|
3
|
+
from annotide import Client
|
|
4
|
+
|
|
5
|
+
with Client("https://annotate.example.com", api_key="...") as client:
|
|
6
|
+
snapshot = client.take_snapshot(project_id, "2026-q3")
|
|
7
|
+
client.export(project_id, "coco", "dataset.zip", snapshot_id=snapshot["id"])
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from annotide.client import Client
|
|
11
|
+
from annotide.errors import AnnotationError, ApiError, JobFailedError, JobTimeoutError
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"AnnotationError",
|
|
17
|
+
"ApiError",
|
|
18
|
+
"Client",
|
|
19
|
+
"JobFailedError",
|
|
20
|
+
"JobTimeoutError",
|
|
21
|
+
"__version__",
|
|
22
|
+
]
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"""`annotation` — command line over the SDK (API-3).
|
|
2
|
+
|
|
3
|
+
Reads the key from `ANNOTIDE_API_KEY` only (a flag would end up in shell
|
|
4
|
+
history and `ps`); the site from `--url` or `ANNOTIDE_URL`. Single objects
|
|
5
|
+
print as indented JSON, lists as JSON Lines, so output pipes into `jq`.
|
|
6
|
+
|
|
7
|
+
annotide projects list
|
|
8
|
+
annotide snapshots create <project> "2026-q3" --split 0.8,0.1,0.1
|
|
9
|
+
annotide export <project> --format coco --snapshot <id> -o dataset.zip
|
|
10
|
+
annotide import <project> labels.json --format coco --dry-run
|
|
11
|
+
annotide mcp # MCP server for AI agents over stdio (API-8)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import json
|
|
18
|
+
import sys
|
|
19
|
+
from collections.abc import Callable, Iterable
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from annotide import __version__
|
|
23
|
+
from annotide.client import URL_ENV, Client
|
|
24
|
+
from annotide.errors import AnnotationError
|
|
25
|
+
|
|
26
|
+
ClientFactory = Callable[[str | None], Client]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _print_one(value: Any) -> None:
|
|
30
|
+
print(json.dumps(value, indent=2, ensure_ascii=False))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _print_many(values: Iterable[Any]) -> None:
|
|
34
|
+
for value in values:
|
|
35
|
+
print(json.dumps(value, ensure_ascii=False))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _split(text: str) -> dict[str, float]:
|
|
39
|
+
try:
|
|
40
|
+
train, val, test = (float(part) for part in text.split(","))
|
|
41
|
+
except ValueError as exc:
|
|
42
|
+
raise argparse.ArgumentTypeError("expected three ratios, e.g. 0.8,0.1,0.1") from exc
|
|
43
|
+
return {"train": train, "val": val, "test": test}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _class_map(text: str) -> dict[str, str | None]:
|
|
47
|
+
try:
|
|
48
|
+
value = json.loads(text)
|
|
49
|
+
except ValueError as exc:
|
|
50
|
+
raise argparse.ArgumentTypeError(f"not JSON: {exc}") from exc
|
|
51
|
+
if not isinstance(value, dict):
|
|
52
|
+
raise argparse.ArgumentTypeError('expected a JSON object, e.g. {"car": "vehicle"}')
|
|
53
|
+
return value
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
57
|
+
parser = argparse.ArgumentParser(
|
|
58
|
+
prog="annotide",
|
|
59
|
+
description="Annotide command line. The API key is read from ANNOTIDE_API_KEY.",
|
|
60
|
+
)
|
|
61
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
62
|
+
parser.add_argument("--url", help=f"site root, e.g. https://annotate.example.com (${URL_ENV})")
|
|
63
|
+
commands = parser.add_subparsers(dest="command", required=True, metavar="command")
|
|
64
|
+
|
|
65
|
+
commands.add_parser("whoami", help="the user or service account the key acts as")
|
|
66
|
+
commands.add_parser(
|
|
67
|
+
"mcp",
|
|
68
|
+
help="serve the Model Context Protocol over stdio for AI agents (needs the mcp extra)",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
projects = commands.add_parser("projects", help="projects").add_subparsers(
|
|
72
|
+
dest="action", required=True
|
|
73
|
+
)
|
|
74
|
+
projects.add_parser("list", help="projects you are a member of")
|
|
75
|
+
stats = projects.add_parser("stats", help="dashboard numbers of one project")
|
|
76
|
+
stats.add_argument("project")
|
|
77
|
+
|
|
78
|
+
items = commands.add_parser("items", help="items").add_subparsers(dest="action", required=True)
|
|
79
|
+
items_list = items.add_parser("list", help="a project's items")
|
|
80
|
+
items_list.add_argument("project")
|
|
81
|
+
items_list.add_argument("--status")
|
|
82
|
+
items_list.add_argument("--media-type")
|
|
83
|
+
items_list.add_argument("--q", help="path substring")
|
|
84
|
+
|
|
85
|
+
snapshots = commands.add_parser("snapshots", help="dataset snapshots").add_subparsers(
|
|
86
|
+
dest="action", required=True
|
|
87
|
+
)
|
|
88
|
+
snapshots_list = snapshots.add_parser("list", help="a project's snapshots")
|
|
89
|
+
snapshots_list.add_argument("project")
|
|
90
|
+
create = snapshots.add_parser("create", help="freeze a snapshot and wait for it")
|
|
91
|
+
create.add_argument("project")
|
|
92
|
+
create.add_argument("name")
|
|
93
|
+
create.add_argument("--split", type=_split, help="train,val,test ratios, e.g. 0.8,0.1,0.1")
|
|
94
|
+
create.add_argument("--seed", type=int, default=0, help="split seed (default 0)")
|
|
95
|
+
create.add_argument("--group-by", help='keep groups together: "folder" or "meta.<key>"')
|
|
96
|
+
create.add_argument("--timeout", type=float, default=600.0)
|
|
97
|
+
|
|
98
|
+
export = commands.add_parser("export", help="export and download an archive")
|
|
99
|
+
export.add_argument("project")
|
|
100
|
+
export.add_argument("--format", required=True, help="coco, yolo or native")
|
|
101
|
+
export.add_argument("-o", "--output", required=True, help="file or directory to write")
|
|
102
|
+
export.add_argument("--snapshot", help="snapshot id (recommended: reproducible)")
|
|
103
|
+
export.add_argument("--split", choices=["train", "val", "test"])
|
|
104
|
+
export.add_argument("--timeout", type=float, default=1800.0)
|
|
105
|
+
|
|
106
|
+
imp = commands.add_parser("import", help="upload an annotation file and import it")
|
|
107
|
+
imp.add_argument("project")
|
|
108
|
+
imp.add_argument("file")
|
|
109
|
+
imp.add_argument("--format", required=True, help="coco, yolo, voc, cvat or label_studio")
|
|
110
|
+
imp.add_argument("--status", choices=["submitted", "draft"])
|
|
111
|
+
imp.add_argument("--class-map", type=_class_map, help='JSON, e.g. {"car": "vehicle"}')
|
|
112
|
+
imp.add_argument("--dry-run", action="store_true", help="report only, write nothing")
|
|
113
|
+
imp.add_argument("--timeout", type=float, default=1800.0)
|
|
114
|
+
|
|
115
|
+
jobs = commands.add_parser("jobs", help="background jobs").add_subparsers(
|
|
116
|
+
dest="action", required=True
|
|
117
|
+
)
|
|
118
|
+
jobs_list = jobs.add_parser("list", help="a project's jobs")
|
|
119
|
+
jobs_list.add_argument("project")
|
|
120
|
+
jobs_list.add_argument("--status")
|
|
121
|
+
jobs_list.add_argument("--type")
|
|
122
|
+
for name, text in (("get", "one job"), ("wait", "wait until a job finishes")):
|
|
123
|
+
sub = jobs.add_parser(name, help=text)
|
|
124
|
+
sub.add_argument("job")
|
|
125
|
+
if name == "wait":
|
|
126
|
+
sub.add_argument("--timeout", type=float, default=600.0)
|
|
127
|
+
return parser
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def run(args: argparse.Namespace, client: Client) -> None:
|
|
131
|
+
command, action = args.command, getattr(args, "action", None)
|
|
132
|
+
if command == "whoami":
|
|
133
|
+
_print_one(client.me())
|
|
134
|
+
elif command == "projects" and action == "list":
|
|
135
|
+
_print_many(client.list_projects())
|
|
136
|
+
elif command == "projects" and action == "stats":
|
|
137
|
+
_print_one(client.get_stats(args.project))
|
|
138
|
+
elif command == "items":
|
|
139
|
+
_print_many(
|
|
140
|
+
client.list_items(
|
|
141
|
+
args.project, status=args.status, media_type=args.media_type, q=args.q
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
elif command == "snapshots" and action == "list":
|
|
145
|
+
_print_many(client.list_snapshots(args.project))
|
|
146
|
+
elif command == "snapshots" and action == "create":
|
|
147
|
+
split = None
|
|
148
|
+
if args.split is not None:
|
|
149
|
+
split = {**args.split, "seed": args.seed, "group_by": args.group_by}
|
|
150
|
+
_print_one(client.take_snapshot(args.project, args.name, split=split, timeout=args.timeout))
|
|
151
|
+
elif command == "export":
|
|
152
|
+
path = client.export(
|
|
153
|
+
args.project,
|
|
154
|
+
args.format,
|
|
155
|
+
args.output,
|
|
156
|
+
snapshot_id=args.snapshot,
|
|
157
|
+
split=args.split,
|
|
158
|
+
timeout=args.timeout,
|
|
159
|
+
)
|
|
160
|
+
print(path)
|
|
161
|
+
elif command == "import":
|
|
162
|
+
_print_one(
|
|
163
|
+
client.import_file(
|
|
164
|
+
args.project,
|
|
165
|
+
args.file,
|
|
166
|
+
args.format,
|
|
167
|
+
class_mapping=args.class_map,
|
|
168
|
+
status=args.status,
|
|
169
|
+
dry_run=args.dry_run,
|
|
170
|
+
timeout=args.timeout,
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
elif command == "jobs" and action == "list":
|
|
174
|
+
_print_many(client.list_jobs(args.project, status=args.status, type=args.type))
|
|
175
|
+
elif command == "jobs" and action == "get":
|
|
176
|
+
_print_one(client.get_job(args.job))
|
|
177
|
+
elif command == "jobs" and action == "wait":
|
|
178
|
+
_print_one(client.wait_for_job(args.job, timeout=args.timeout))
|
|
179
|
+
else: # pragma: no cover - argparse rejects anything else
|
|
180
|
+
raise AnnotationError(f"unknown command {command} {action or ''}".rstrip())
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _serve_mcp(url: str | None) -> int:
|
|
184
|
+
"""`annotide mcp`: the MCP server needs the `mcp` extra and owns stdout."""
|
|
185
|
+
try:
|
|
186
|
+
from annotide import mcp_server
|
|
187
|
+
except ImportError:
|
|
188
|
+
print(
|
|
189
|
+
'annotation: the MCP server needs the extra: pip install "annotide[mcp]"',
|
|
190
|
+
file=sys.stderr,
|
|
191
|
+
)
|
|
192
|
+
return 2
|
|
193
|
+
mcp_server.build_server(lambda: Client(url)).run("stdio")
|
|
194
|
+
return 0
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def main(argv: list[str] | None = None, client_factory: ClientFactory | None = None) -> int:
|
|
198
|
+
args = build_parser().parse_args(argv)
|
|
199
|
+
if args.command == "mcp":
|
|
200
|
+
return _serve_mcp(args.url)
|
|
201
|
+
factory: ClientFactory = client_factory or (lambda url: Client(url))
|
|
202
|
+
try:
|
|
203
|
+
with factory(args.url) as client:
|
|
204
|
+
run(args, client)
|
|
205
|
+
except AnnotationError as exc:
|
|
206
|
+
print(f"annotation: {exc}", file=sys.stderr)
|
|
207
|
+
return 1
|
|
208
|
+
except KeyboardInterrupt:
|
|
209
|
+
return 130
|
|
210
|
+
return 0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if __name__ == "__main__":
|
|
214
|
+
raise SystemExit(main())
|