Skip to content

Add API V2 support #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2.1
jobs:
build_test:
docker:
- image: cimg/python:3.6
- image: cimg/python:3.8
resource_class: small
steps:
- checkout # checkout source code to working directory
Expand All @@ -17,11 +17,11 @@ jobs:
- run:
name: Black Formatting Check # Only validation, without re-formatting
command: |
black --check -t py36 .
black --check --exclude 'scaleapi/api_client/*' -t py38 .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to run it through black after we generate. We run the typescript one through prettier

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big deal if it's not easy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah there's also some others in the precommit, can try to do something similar next time

- run:
name: isort Import Ordering Check # Only validation, without re-formatting
command: |
isort --check-only --profile black .
isort --sg 'scaleapi/api_client/*' --check-only --profile black .
- run:
name: Flake8 Lint Check # Uses setup.cfg for configuration
command: |
Expand All @@ -46,7 +46,7 @@ jobs:
twine check --strict dist/*
pypi_publish:
docker:
- image: cimg/python:3.6
- image: cimg/python:3.8
steps:
- checkout # checkout source code to working directory
- run:
Expand Down
2 changes: 2 additions & 0 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scaleapi/__init__.py
scaleapi/api_client/v2/models/annotation.py
55 changes: 55 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
scaleapi/api_client/__init__.py
scaleapi/api_client/v2/__init__.py
scaleapi/api_client/v2/api/__init__.py
scaleapi/api_client/v2/api/v2_api.py
scaleapi/api_client/v2/api_client.py
scaleapi/api_client/v2/api_response.py
scaleapi/api_client/v2/configuration.py
scaleapi/api_client/v2/exceptions.py
scaleapi/api_client/v2/models/__init__.py
scaleapi/api_client/v2/models/annotation_category.py
scaleapi/api_client/v2/models/annotation_category_multiple.py
scaleapi/api_client/v2/models/annotation_category_multiple_properties.py
scaleapi/api_client/v2/models/annotation_category_properties.py
scaleapi/api_client/v2/models/annotation_integer.py
scaleapi/api_client/v2/models/annotation_integer_properties.py
scaleapi/api_client/v2/models/annotation_metadata.py
scaleapi/api_client/v2/models/annotation_text.py
scaleapi/api_client/v2/models/annotation_text_properties.py
scaleapi/api_client/v2/models/annotation_type.py
scaleapi/api_client/v2/models/audio_file.py
scaleapi/api_client/v2/models/base_annotation.py
scaleapi/api_client/v2/models/batch.py
scaleapi/api_client/v2/models/delivery.py
scaleapi/api_client/v2/models/detailed_file.py
scaleapi/api_client/v2/models/error_detail.py
scaleapi/api_client/v2/models/error_type.py
scaleapi/api_client/v2/models/expandable.py
scaleapi/api_client/v2/models/expandable_annotation.py
scaleapi/api_client/v2/models/expandable_batch.py
scaleapi/api_client/v2/models/expandable_delivery.py
scaleapi/api_client/v2/models/expandable_enum_deliveries.py
scaleapi/api_client/v2/models/expandable_enum_delivery.py
scaleapi/api_client/v2/models/expandable_enum_task.py
scaleapi/api_client/v2/models/expandable_project.py
scaleapi/api_client/v2/models/file.py
scaleapi/api_client/v2/models/get_delivered_tasks_response.py
scaleapi/api_client/v2/models/get_deliveries_response.py
scaleapi/api_client/v2/models/get_task500_response.py
scaleapi/api_client/v2/models/get_tasks_response.py
scaleapi/api_client/v2/models/image_file.py
scaleapi/api_client/v2/models/message.py
scaleapi/api_client/v2/models/message_content.py
scaleapi/api_client/v2/models/message_role.py
scaleapi/api_client/v2/models/model_parameters.py
scaleapi/api_client/v2/models/option.py
scaleapi/api_client/v2/models/project.py
scaleapi/api_client/v2/models/reference_text.py
scaleapi/api_client/v2/models/submission.py
scaleapi/api_client/v2/models/task.py
scaleapi/api_client/v2/models/task_status.py
scaleapi/api_client/v2/models/thread.py
scaleapi/api_client/v2/models/turn.py
scaleapi/api_client/v2/models/v1_task_task_id_get200_response.py
scaleapi/api_client/v2/models/v1_task_task_id_get200_response_response.py
scaleapi/api_client/v2/rest.py
1 change: 1 addition & 0 deletions .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.11.0
47 changes: 27 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
default_language_version:
python: python3.6
python: python3.8
default_stages: [commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-yaml
- id: check-case-conflict
- repo: https://github.com/pycqa/isort
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-yaml
- id: check-case-conflict
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
- id: isort
name: isort
args: ["--profile", "black"]
- repo: https://github.com/psf/black
exclude: ^scaleapi/api_client/
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
- id: black
exclude: ^scaleapi/api_client/
- repo: https://github.com/PyCQA/flake8
rev: 3.8.4
hooks:
- id: flake8
- repo: local
- id: flake8
exclude: ^scaleapi/api_client/
- repo: local
hooks:
- id: pylint
- id: pylint
name: pylint
entry: pylint
language: python
types: [python]
files: scaleapi/
exclude: ^scaleapi/api_client/
additional_dependencies:
- 'pylint>=2.7.4'
- 'requests>=2.25.0'
- 'urllib3>=1.26.0'
- 'pytest>=6.2.2'
language_version: python3.6
- "pylint>=2.7.4"
- "requests>=2.25.0"
- "urllib3>=1.26.0"
- "pytest>=6.2.2"
- "python_dateutil>=2.8.2"
- "pydantic>=2"
- "typing-extensions>=4.7.1"
language_version: python3.8
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[MASTER]
ignore-paths=
^scaleapi/api_client/*
disable=
missing-module-docstring,
too-few-public-methods,
Expand Down
52 changes: 52 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,58 @@ For example:
print(err.message) # Parameter is invalid, reason: "attachments" is required


V2 API
______

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`__.

__ https://docs.genai.scale.com/get-started/quickstart

.. list-table::
:widths: 25 25 50
:header-rows: 1

* - Method
- HTTP request
- Description
* - **get_task**
- **GET** /v2/task
- Get a Task
* - **get_tasks**
- **GET** /v2/tasks
- Get Multiple Tasks
* - **get_deliveries**
- **GET** /v2/deliveries
- List All Deliveries
* - **get_delivery**
- **GET** /v2/delivery
- Get Tasks in a Delivery
* - **get_annotation**
- **GET** /v2/annotation
- Get an Annotation

For example:

.. code-block:: python

# Get a task with the V2 format
task = client.v2.get_task('30553edd0b6a93f8f05f0fee')

# Get tasks in the V2 format (paged)
tasks = client.v2.get_tasks(
project_name = "My Project"
)

# Get tasks in the V2 format (generator)
tasks = client.v2_get_tasks(
project_name = "My Project"
)

# Iterating through the generator
for task in tasks:
# Download task or do something!
print(task.task_id)


Troubleshooting
_______________
Expand Down
7 changes: 6 additions & 1 deletion docs/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ pre-commit==2.11.1
isort>=5.7.0
pytest>=6.2.2
pylint>=2.7.2
twine>=3.4.1
twine==6.0.1
pkginfo>=1.12.0
urllib3>=1.26.0
python_dateutil>=2.8.2
pydantic>=2
typing-extensions>=4.7.1
36 changes: 26 additions & 10 deletions docs/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ $ git clone git@github.com:scaleapi/scaleapi-python-client.git

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

_Python SDK v2+ supports only Python 3.6+_
_Python SDK v2+ supports only Python 3.8+_

```bash
$ pip install -r docs/dev_requirements.txt
```

### 3. Setup pre-commit

Assure pre-commit<sup>[1]</sup> is installed:

```bash
$ pre-commit --version
# pre-commit 2.11.1
```

Configure pre-commit for the repo:

```bash
pre-commit install
```

Now `pre-commit` will run automatically on `git commit`!

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

Append following lines to the json file:

```json
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"[python]": {
"pylint.enabled": true,
"flake8.enabled": true,
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.python"
},
"editor.defaultFormatter": "ms-python.black-formatter"
},
```

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.
Expand Down Expand Up @@ -95,10 +98,23 @@ tests/test_client.py::test_transcription_ok PASSED [
.........
```

#### 7. Deployment and Publishing of a new version
#### 7. Updating auto-generated v2 client

The V2 API client is auto-generated from openapi.yaml using the v2_generator.json config. Run this to update the client:

```bash
$ export SCALE_API_KEY="your_key" && SCALE_API_AUTH_HEADER=$(python -c "import urllib.parse; print(urllib.parse.quote('Bearer $SCALE_API_KEY'))")
$ openapi-generator-cli generate --auth "Authorization:$SCALE_API_AUTH_HEADER" --config v2_generator.json
```

Additionally, update the Annotation model type discrimination if there are changes

#### 8. Deployment and Publishing of a new version

Please refer to [Deployment and Publishing Guide](pypi_update_guide.md) for details.
_____

---

<sup>[1] pre-commit configuration is available in `.pre-commit-config.yaml`</sup>

<sup>[2] Pylint configuration is available in `.pylintrc`</sup>
Expand Down
7 changes: 7 additions & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.11.0"
}
}
Loading