Skip to content

Commit 74ea1de

Browse files
Add API V2 support (#97)
1 parent 4de6c13 commit 74ea1de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+8980
-68
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 2.1
44
jobs:
55
build_test:
66
docker:
7-
- image: cimg/python:3.6
7+
- image: cimg/python:3.8
88
resource_class: small
99
steps:
1010
- checkout # checkout source code to working directory
@@ -17,11 +17,11 @@ jobs:
1717
- run:
1818
name: Black Formatting Check # Only validation, without re-formatting
1919
command: |
20-
black --check -t py36 .
20+
black --check --exclude 'scaleapi/api_client/*' -t py38 .
2121
- run:
2222
name: isort Import Ordering Check # Only validation, without re-formatting
2323
command: |
24-
isort --check-only --profile black .
24+
isort --sg 'scaleapi/api_client/*' --check-only --profile black .
2525
- run:
2626
name: Flake8 Lint Check # Uses setup.cfg for configuration
2727
command: |
@@ -46,7 +46,7 @@ jobs:
4646
twine check --strict dist/*
4747
pypi_publish:
4848
docker:
49-
- image: cimg/python:3.6
49+
- image: cimg/python:3.8
5050
steps:
5151
- checkout # checkout source code to working directory
5252
- run:

.openapi-generator-ignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scaleapi/__init__.py
2+
scaleapi/api_client/v2/models/annotation.py

.openapi-generator/FILES

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
scaleapi/api_client/__init__.py
2+
scaleapi/api_client/v2/__init__.py
3+
scaleapi/api_client/v2/api/__init__.py
4+
scaleapi/api_client/v2/api/v2_api.py
5+
scaleapi/api_client/v2/api_client.py
6+
scaleapi/api_client/v2/api_response.py
7+
scaleapi/api_client/v2/configuration.py
8+
scaleapi/api_client/v2/exceptions.py
9+
scaleapi/api_client/v2/models/__init__.py
10+
scaleapi/api_client/v2/models/annotation_category.py
11+
scaleapi/api_client/v2/models/annotation_category_multiple.py
12+
scaleapi/api_client/v2/models/annotation_category_multiple_properties.py
13+
scaleapi/api_client/v2/models/annotation_category_properties.py
14+
scaleapi/api_client/v2/models/annotation_integer.py
15+
scaleapi/api_client/v2/models/annotation_integer_properties.py
16+
scaleapi/api_client/v2/models/annotation_metadata.py
17+
scaleapi/api_client/v2/models/annotation_text.py
18+
scaleapi/api_client/v2/models/annotation_text_properties.py
19+
scaleapi/api_client/v2/models/annotation_type.py
20+
scaleapi/api_client/v2/models/audio_file.py
21+
scaleapi/api_client/v2/models/base_annotation.py
22+
scaleapi/api_client/v2/models/batch.py
23+
scaleapi/api_client/v2/models/delivery.py
24+
scaleapi/api_client/v2/models/detailed_file.py
25+
scaleapi/api_client/v2/models/error_detail.py
26+
scaleapi/api_client/v2/models/error_type.py
27+
scaleapi/api_client/v2/models/expandable.py
28+
scaleapi/api_client/v2/models/expandable_annotation.py
29+
scaleapi/api_client/v2/models/expandable_batch.py
30+
scaleapi/api_client/v2/models/expandable_delivery.py
31+
scaleapi/api_client/v2/models/expandable_enum_deliveries.py
32+
scaleapi/api_client/v2/models/expandable_enum_delivery.py
33+
scaleapi/api_client/v2/models/expandable_enum_task.py
34+
scaleapi/api_client/v2/models/expandable_project.py
35+
scaleapi/api_client/v2/models/file.py
36+
scaleapi/api_client/v2/models/get_delivered_tasks_response.py
37+
scaleapi/api_client/v2/models/get_deliveries_response.py
38+
scaleapi/api_client/v2/models/get_task500_response.py
39+
scaleapi/api_client/v2/models/get_tasks_response.py
40+
scaleapi/api_client/v2/models/image_file.py
41+
scaleapi/api_client/v2/models/message.py
42+
scaleapi/api_client/v2/models/message_content.py
43+
scaleapi/api_client/v2/models/message_role.py
44+
scaleapi/api_client/v2/models/model_parameters.py
45+
scaleapi/api_client/v2/models/option.py
46+
scaleapi/api_client/v2/models/project.py
47+
scaleapi/api_client/v2/models/reference_text.py
48+
scaleapi/api_client/v2/models/submission.py
49+
scaleapi/api_client/v2/models/task.py
50+
scaleapi/api_client/v2/models/task_status.py
51+
scaleapi/api_client/v2/models/thread.py
52+
scaleapi/api_client/v2/models/turn.py
53+
scaleapi/api_client/v2/models/v1_task_task_id_get200_response.py
54+
scaleapi/api_client/v2/models/v1_task_task_id_get200_response_response.py
55+
scaleapi/api_client/v2/rest.py

.openapi-generator/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.11.0

.pre-commit-config.yaml

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
default_language_version:
2-
python: python3.6
2+
python: python3.8
33
default_stages: [commit]
44

55
repos:
6-
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
77
rev: v3.2.0
88
hooks:
9-
- id: trailing-whitespace
10-
- id: end-of-file-fixer
11-
- id: check-added-large-files
12-
- id: check-yaml
13-
- id: check-case-conflict
14-
- repo: https://github.com/pycqa/isort
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-added-large-files
12+
- id: check-yaml
13+
- id: check-case-conflict
14+
- repo: https://github.com/pycqa/isort
1515
rev: 5.8.0
1616
hooks:
17-
- id: isort
17+
- id: isort
1818
name: isort
1919
args: ["--profile", "black"]
20-
- repo: https://github.com/psf/black
20+
exclude: ^scaleapi/api_client/
21+
- repo: https://github.com/psf/black
2122
rev: 20.8b1
2223
hooks:
23-
- id: black
24-
- repo: https://github.com/PyCQA/flake8
24+
- id: black
25+
exclude: ^scaleapi/api_client/
26+
- repo: https://github.com/PyCQA/flake8
2527
rev: 3.8.4
2628
hooks:
27-
- id: flake8
28-
- repo: local
29+
- id: flake8
30+
exclude: ^scaleapi/api_client/
31+
- repo: local
2932
hooks:
30-
- id: pylint
33+
- id: pylint
3134
name: pylint
3235
entry: pylint
3336
language: python
3437
types: [python]
3538
files: scaleapi/
39+
exclude: ^scaleapi/api_client/
3640
additional_dependencies:
37-
- 'pylint>=2.7.4'
38-
- 'requests>=2.25.0'
39-
- 'urllib3>=1.26.0'
40-
- 'pytest>=6.2.2'
41-
language_version: python3.6
41+
- "pylint>=2.7.4"
42+
- "requests>=2.25.0"
43+
- "urllib3>=1.26.0"
44+
- "pytest>=6.2.2"
45+
- "python_dateutil>=2.8.2"
46+
- "pydantic>=2"
47+
- "typing-extensions>=4.7.1"
48+
language_version: python3.8

.pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[MASTER]
2+
ignore-paths=
3+
^scaleapi/api_client/*
24
disable=
35
missing-module-docstring,
46
too-few-public-methods,

README.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,58 @@ For example:
914914
print(err.message) # Parameter is invalid, reason: "attachments" is required
915915
916916
917+
V2 API
918+
______
919+
920+
If your project is using V2 API, you can use the ``.v2`` API client and also ``v2_get_tasks()`` to retrieve tasks in the V2 API format. See our `V2 API documentation`__.
921+
922+
__ https://docs.genai.scale.com/get-started/quickstart
923+
924+
.. list-table::
925+
:widths: 25 25 50
926+
:header-rows: 1
927+
928+
* - Method
929+
- HTTP request
930+
- Description
931+
* - **get_task**
932+
- **GET** /v2/task
933+
- Get a Task
934+
* - **get_tasks**
935+
- **GET** /v2/tasks
936+
- Get Multiple Tasks
937+
* - **get_deliveries**
938+
- **GET** /v2/deliveries
939+
- List All Deliveries
940+
* - **get_delivery**
941+
- **GET** /v2/delivery
942+
- Get Tasks in a Delivery
943+
* - **get_annotation**
944+
- **GET** /v2/annotation
945+
- Get an Annotation
946+
947+
For example:
948+
949+
.. code-block:: python
950+
951+
# Get a task with the V2 format
952+
task = client.v2.get_task('30553edd0b6a93f8f05f0fee')
953+
954+
# Get tasks in the V2 format (paged)
955+
tasks = client.v2.get_tasks(
956+
project_name = "My Project"
957+
)
958+
959+
# Get tasks in the V2 format (generator)
960+
tasks = client.v2_get_tasks(
961+
project_name = "My Project"
962+
)
963+
964+
# Iterating through the generator
965+
for task in tasks:
966+
# Download task or do something!
967+
print(task.task_id)
968+
917969
918970
Troubleshooting
919971
_______________

docs/dev_requirements.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ pre-commit==2.11.1
44
isort>=5.7.0
55
pytest>=6.2.2
66
pylint>=2.7.2
7-
twine>=3.4.1
7+
twine==6.0.1
8+
pkginfo>=1.12.0
9+
urllib3>=1.26.0
10+
python_dateutil>=2.8.2
11+
pydantic>=2
12+
typing-extensions>=4.7.1

docs/developer_guide.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,27 @@ $ git clone git@github.com:scaleapi/scaleapi-python-client.git
1212

1313
If you use a virtual environment (via venv or conda), please activate it before installing the following packages.
1414

15-
_Python SDK v2+ supports only Python 3.6+_
15+
_Python SDK v2+ supports only Python 3.8+_
1616

1717
```bash
1818
$ pip install -r docs/dev_requirements.txt
1919
```
20+
2021
### 3. Setup pre-commit
2122

2223
Assure pre-commit<sup>[1]</sup> is installed:
24+
2325
```bash
2426
$ pre-commit --version
2527
# pre-commit 2.11.1
2628
```
2729

2830
Configure pre-commit for the repo:
31+
2932
```bash
3033
pre-commit install
3134
```
35+
3236
Now `pre-commit` will run automatically on `git commit`!
3337

3438
### 4. (Optional) VS Code Settings
@@ -41,15 +45,14 @@ If you want to make those settings only apply to current workspace (not VS Code
4145
- Auto-formats python files on save according to `black`
4246

4347
Append following lines to the json file:
48+
4449
```json
45-
"python.linting.enabled": true,
46-
"python.linting.pylintEnabled": true,
47-
"python.linting.flake8Enabled": true,
48-
"python.formatting.provider": "black",
49-
"[python]": {
50+
"pylint.enabled": true,
51+
"flake8.enabled": true,
52+
"[python]": {
5053
"editor.formatOnSave": true,
51-
"editor.defaultFormatter": "ms-python.python"
52-
},
54+
"editor.defaultFormatter": "ms-python.black-formatter"
55+
},
5356
```
5457

5558
In Python SDK we follow [Google's Python Docstring Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for comments and docstring of modules, functions and classes. [Python Docstring Generator](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring) is a useful VS Code extension that helps to generate docstrings.
@@ -95,10 +98,23 @@ tests/test_client.py::test_transcription_ok PASSED [
9598
.........
9699
```
97100
98-
#### 7. Deployment and Publishing of a new version
101+
#### 7. Updating auto-generated v2 client
102+
103+
The V2 API client is auto-generated from openapi.yaml using the v2_generator.json config. Run this to update the client:
104+
105+
```bash
106+
$ export SCALE_API_KEY="your_key" && SCALE_API_AUTH_HEADER=$(python -c "import urllib.parse; print(urllib.parse.quote('Bearer $SCALE_API_KEY'))")
107+
$ openapi-generator-cli generate --auth "Authorization:$SCALE_API_AUTH_HEADER" --config v2_generator.json
108+
```
109+
110+
Additionally, update the [Annotation model](../scaleapi/api_client/v2/models/annotation.py) `from_json` type discrimination if there are changes
111+
112+
#### 8. Deployment and Publishing of a new version
99113
100114
Please refer to [Deployment and Publishing Guide](pypi_update_guide.md) for details.
101-
_____
115+
116+
---
117+
102118
<sup>[1] pre-commit configuration is available in `.pre-commit-config.yaml`</sup>
103119
104120
<sup>[2] Pylint configuration is available in `.pylintrc`</sup>

openapitools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
3+
"spaces": 2,
4+
"generator-cli": {
5+
"version": "7.11.0"
6+
}
7+
}

0 commit comments

Comments
 (0)