Skip to content
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

Add SDK docs #4928

Merged
merged 32 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5172f49
Update readme
zhiltsov-max Sep 9, 2022
cb2abd6
Add requirements file for docs
zhiltsov-max Sep 9, 2022
bf9e68e
Move sdk developer guide
zhiltsov-max Sep 9, 2022
1b4cc0b
Add sdk and cli integration docs
zhiltsov-max Sep 9, 2022
19c5d83
Add integration docs
zhiltsov-max Sep 9, 2022
7fbe1de
Add rest
zhiltsov-max Sep 9, 2022
22b563f
Add pypi links
zhiltsov-max Sep 9, 2022
4cd549e
Fixes
zhiltsov-max Sep 9, 2022
9fc9262
Update changelog
zhiltsov-max Sep 9, 2022
3b3c9a5
Fix bandit warnings
zhiltsov-max Sep 9, 2022
a88927a
Fix linter warnings
zhiltsov-max Sep 9, 2022
a4b759f
Fix linter issues
zhiltsov-max Sep 12, 2022
a81173b
Add integration components compatibility info
zhiltsov-max Sep 12, 2022
d120217
Move doc sections back, rename integration section
zhiltsov-max Sep 13, 2022
d1c129f
update changelog
zhiltsov-max Sep 13, 2022
61627cc
Update section name and readme links
zhiltsov-max Sep 13, 2022
4273707
remove rest api page from contributing
zhiltsov-max Sep 13, 2022
56d5434
Remove cli page from manual
zhiltsov-max Sep 13, 2022
f3e917e
Remove extra descriptions
zhiltsov-max Sep 13, 2022
ff6fa4b
Allow unauthorized access to server api docs
zhiltsov-max Sep 13, 2022
a99713d
Add docs for auth methods
zhiltsov-max Sep 13, 2022
17e7ad3
Allow to control SSL verification with env variable in CLI
zhiltsov-max Sep 13, 2022
b521f4c
Merge branch 'develop' into zm/update-docs
zhiltsov-max Sep 13, 2022
d42834e
Update changelog
zhiltsov-max Sep 13, 2022
7c79c90
Fix host schema detection test after new changes
zhiltsov-max Sep 14, 2022
fa39bbc
Update site/content/en/docs/api_sdk/_index.md
zhiltsov-max Sep 15, 2022
3907d1a
Update site/content/en/docs/api_sdk/sdk/developer-guide.md
zhiltsov-max Sep 15, 2022
4249d7c
Update site/content/en/docs/api_sdk/sdk/developer-guide.md
zhiltsov-max Sep 15, 2022
83d7f2e
Fix readme links
zhiltsov-max Sep 15, 2022
2f1f155
Fix links in docs
zhiltsov-max Sep 15, 2022
d1ccd8c
Use cli arg for ssl check control
zhiltsov-max Sep 15, 2022
8bdf579
Remove strange parameters
zhiltsov-max Sep 15, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/github_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- name: Build docs
run: |
pip install gitpython packaging toml
pip install -r site/requirements.txt
python site/build_docs.py

- name: Deploy
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## \[2.3.0] - Unreleased
### Added
- TDB
- SDK section in docs (<https://github.com/opencv/cvat/pull/4928>)
- An env variable to enable or disable host certificate checking in CLI (<https://github.com/opencv/cvat/pull/4928>)

### Changed
- TDB
- `api/docs`, `api/swagger`, `api/schema` endpoints now allow unauthorized access (<https://github.com/opencv/cvat/pull/4928>)

### Deprecated
- TDB
Expand Down
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ Start using CVAT online for free: [cvat.ai](https://cvat.ai). Or set it up as a
- [Installation guide](https://opencv.github.io/cvat/docs/administration/basics/installation/)
- [Manual](https://opencv.github.io/cvat/docs/manual/)
- [Contributing](https://opencv.github.io/cvat/docs/contributing/)
- [Django REST API documentation](https://opencv.github.io/cvat/docs/administration/basics/rest_api_guide/)
- [Datumaro dataset framework](https://github.com/cvat-ai/datumaro/blob/develop/README.md)
- [Command line interface](https://opencv.github.io/cvat/docs/manual/advanced/cli/)
- [Server API](#api)
- [Python SDK](#sdk)
- [Command line tool](#cli)
- [XML annotation format](https://opencv.github.io/cvat/docs/manual/advanced/xml_format/)
- [AWS Deployment Guide](https://opencv.github.io/cvat/docs/administration/basics/aws-deployment-guide/)
- [Frequently asked questions](https://opencv.github.io/cvat/docs/faq/)
Expand Down Expand Up @@ -85,11 +86,6 @@ Prebuilt docker images are the easiest way to start using CVAT locally. They are

The images have been downloaded more than 1M times so far.

## REST API

CVAT has a REST API: [documentation](https://opencv.github.io/cvat/docs/administration/basics/rest_api_guide/).
Its current version is `2.0-alpha`. We focus on its improvement, and the API may be changed in the next releases.

## Screencasts 🎦

Here are some screencasts showing how to use CVAT.
Expand All @@ -104,6 +100,22 @@ Here are some screencasts showing how to use CVAT.
- [Tutorial for polygons](https://youtu.be/C7-r9lZbjBw)
- [Semi-automatic segmentation](https://youtu.be/9HszWP_qsRQ)

## API

- [Documentation](https://opencv.github.io/cvat/docs/api_sdk/api/)

## SDK

- Install with `pip install cvat-sdk`
- [PyPI package homepage](https://pypi.org/project/cvat-sdk/)
- [Documentation](https://opencv.github.io/cvat/docs/api_sdk/sdk/)

## CLI

- Install with `pip install cvat-cli`
- [PyPI package homepage](https://pypi.org/project/cvat-cli/)
- [Documentation](https://opencv.github.io/cvat/docs/api_sdk/cli/)

## Supported annotation formats

CVAT supports multiple annotation formats. You can select the format after clicking the "Upload annotation" and "Dump
Expand Down
18 changes: 14 additions & 4 deletions cvat-cli/src/cvat_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import logging
import sys
from http.client import HTTPConnection
from types import SimpleNamespace
from typing import List

from cvat_sdk import exceptions, make_client
from cvat_sdk import exceptions
from cvat_sdk.core.client import Client, Config

from cvat_cli.cli import CLI
from cvat_cli.parser import get_action_args, make_cmdline_parser
Expand All @@ -28,6 +30,16 @@ def configure_logger(level):
HTTPConnection.debuglevel = 1


def build_client(parsed_args: SimpleNamespace, logger: logging.Logger) -> Client:
config = Config(verify_ssl=not parsed_args.insecure)

return Client(
url="{host}:{port}".format(host=parsed_args.server_host, port=parsed_args.server_port),
logger=logger,
config=config,
)


def main(args: List[str] = None):
actions = {
"create": CLI.tasks_create,
Expand All @@ -43,9 +55,7 @@ def main(args: List[str] = None):
parsed_args = parser.parse_args(args)
configure_logger(parsed_args.loglevel)

with make_client(parsed_args.server_host, port=parsed_args.server_port) as client:
client.logger = logger

with build_client(parsed_args, logger=logger) as client:
action_args = get_action_args(parser, parsed_args)
try:
cli = CLI(client=client, credentials=parsed_args.auth)
Expand Down
5 changes: 5 additions & 0 deletions cvat-cli/src/cvat_cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def make_cmdline_parser() -> argparse.ArgumentParser:
description="Perform common operations related to CVAT tasks.\n\n"
)
parser.add_argument("--version", action="version", version=VERSION)
parser.add_argument(
"--insecure",
action="store_true",
help="Allows to disable SSL certificate check",
)

task_subparser = parser.add_subparsers(dest="action")

Expand Down
13 changes: 10 additions & 3 deletions cvat-sdk/cvat_sdk/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Config:
status_check_period: float = 5
"""In seconds"""

verify_ssl: Optional[bool] = None
"""
Whether to verify host SSL certificate or not.
"""


class Client:
"""
Expand All @@ -41,10 +46,12 @@ def __init__(
self, url: str, *, logger: Optional[logging.Logger] = None, config: Optional[Config] = None
):
url = self._validate_and_prepare_url(url)
self.api_map = CVAT_API_V2(url)
self.api_client = ApiClient(Configuration(host=self.api_map.host))
self.logger = logger or logging.getLogger(__name__)
self.config = config or Config()
self.api_map = CVAT_API_V2(url)
self.api_client = ApiClient(
Configuration(host=self.api_map.host, verify_ssl=self.config.verify_ssl)
)

self._repos: Dict[str, Repo] = {}

Expand Down Expand Up @@ -76,7 +83,7 @@ def _detect_schema(cls, base_url: str) -> str:
for schema in cls.ALLOWED_SCHEMAS:
with ApiClient(Configuration(host=f"{schema}://{base_url}")) as api_client:
with suppress(urllib3.exceptions.RequestError):
(_, response) = api_client.schema_api.retrieve(
(_, response) = api_client.server_api.retrieve_about(
_request_timeout=5, _parse_response=False, _check_status=False
)

Expand Down
48 changes: 0 additions & 48 deletions cvat-sdk/developer_guide.md

This file was deleted.

25 changes: 5 additions & 20 deletions cvat-sdk/gen/templates/openapi-generator/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,21 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Installation & Usage
### pip install

If the python package is hosted on a repository, you can install directly using:
To install a prebuilt package, run the following command in the terminal:

```sh
pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git
pip install cvat-sdk
```
(you may need to run `pip` with root permission: `sudo pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git`)

Then import the package:
```python
import {{{packageName}}}
```
To install from the local directory, follow [the developer guide](https://opencv.github.io/cvat/docs/integration/sdk/developer_guide).

### Setuptools
After installation you can import the package:

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).

```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)

Then import the package:
```python
import {{{packageName}}}
import cvat_sdk
```

## Getting Started

Please follow the [installation procedure](#installation--usage) and then run the following:

{{> README_common }}
Loading