annofabapi-0.9.1
0.9.1
0.9.0
0.8.0
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.68.0
0.67.1
0.67.0
0.65.0
0.64.0
0.63.0
0.62.1
0.62.0
0.61.0
0.60.3
0.60.2
0.60.1
0.60.0
0.6.0
0.59.0
0.58.0
0.57.0
0.55.3
0.55.2
0.55.1
0.55.0
0.54.1
0.54.0
0.53.0
0.52.4
0.52.3
0.52.2
0.52.1
0.52.0
0.51.1
0.51.0
0.50.2
0.50.1
0.50.0
0.5.1
0.5.0
0.49.0
0.48.3
0.48.2
0.48.1
0.48.0
0.47.2
0.47.1
0.47.0
0.46.5
0.46.4
0.46.3
0.46.2
0.46.1
0.46.0
0.45.2
0.45.1
0.45.0
0.44.0
0.43.0
0.42.2
0.42.1
0.42.0
0.41.2
0.41.1
0.41.0
0.40.5
0.40.4
0.40.3
0.40.2
0.40.1
0.40.0
0.4.2
0.4.1
0.4.0
0.39.0
0.38.9
0.38.8
0.38.7
0.38.6
0.38.5
0.38.4
0.38.3
0.38.2
0.38.11
0.38.10
0.38.1
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.1
0.33.0
0.32.0
0.31.0
0.30.3
0.30.2
0.30.1
0.30.0
0.3.1
0.3.0
0.29.5
0.29.4
0.29.3
0.29.2
0.29.1
0.29.0
0.28.1
0.28.0
0.27.9
0.27.8
0.27.7
0.27.6
0.27.5
0.27.4
0.27.3
0.27.2
0.27.12
0.27.11
0.27.10
0.27.1
0.27.0
0.26.0
0.25.2
0.25.1
0.25.0
0.24.3
0.24.2
0.24.1
0.24.0
0.23.2
0.23.1
0.23.0
0.22.0
0.21.4
0.21.3
0.21.2
0.21.1
0.21.0
0.20.1
0.20.0
0.2.0
0.19.6
0.19.5
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.0
0.17.0
0.16.0
0.15.3
0.15.2
0.15.1
0.15.0
0.14.1
0.14.0
0.13.1
0.13.0
0.12.0
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.0
0.1.2
0.1.1
0.1.0
0.0.1
0.9.1
0.9.0
0.8.0
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.68.0
0.67.1
0.67.0
0.65.0
0.64.0
0.63.0
0.62.1
0.62.0
0.61.0
0.60.3
0.60.2
0.60.1
0.60.0
0.6.0
0.59.0
0.58.0
0.57.0
0.55.3
0.55.2
0.55.1
0.55.0
0.54.1
0.54.0
0.53.0
0.52.4
0.52.3
0.52.2
0.52.1
0.52.0
0.51.1
0.51.0
0.50.2
0.50.1
0.50.0
0.5.1
0.49.0
0.48.3
0.48.2
0.48.1
0.48.0
0.47.2
0.47.1
0.47.0
0.46.5
0.46.4
0.46.3
0.46.2
0.46.1
0.46.0
0.45.2
0.45.1
0.45.0
0.44.0
0.43.0
0.42.2
0.42.1
0.42.0
0.41.2
0.41.1
0.41.0
0.40.5
0.40.4
0.40.3
0.40.2
0.40.1
0.40.0
0.39.0
0.38.9
0.38.8
0.38.7
0.38.6
0.38.5
0.38.4
0.38.3
0.38.2
0.38.11
0.38.10
0.38.1
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.1
0.33.0
0.32.0
0.31.0
0.30.3
0.30.2
0.30.1
0.30.0
0.29.5
0.29.4
0.29.3
0.29.2
0.29.1
0.29.0
0.28.1
0.28.0
0.27.9
0.27.8
0.27.7
0.27.6
0.27.5
0.27.4
0.27.3
0.27.2
0.27.12
0.27.11
0.27.10
0.27.1
0.27.0
0.26.0
0.25.2
0.25.1
0.25.0
0.24.3
0.24.2
0.24.1
0.24.0
0.23.2
0.23.1
0.23.0
0.22.0
0.21.4
0.21.3
0.21.2
0.21.1
0.21.0
0.20.1
0.20.0
0.19.6
0.19.5
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.0
0.17.0
0.16.0
0.15.3
0.15.2
0.15.1
0.15.0
0.14.1
0.14.0
0.13.1
0.13.0
0.12.0
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.0
توضیحات
Python Clinet Library of Annofab WebAPI (https://annofab.com/docs/api/)
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | annofabapi-0.9.1 |
| نام | annofabapi |
| نسخه کتابخانه | 0.9.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | yuji38kwmt |
| ایمیل نویسنده | - |
| آدرس صفحه اصلی | https://github.com/kurusugawa-computer/annofab-api-python-client |
| آدرس اینترنتی | https://pypi.org/project/annofabapi/ |
| مجوز | MIT |
# annofab-api-python-client
[Annofab Web API](https://annofab.com/docs/api/) のPythonクライアントライブラリです。
[](https://app.travis-ci.com/kurusugawa-computer/annofab-api-python-client)
[](https://github.com/kurusugawa-computer/annofab-api-python-client/actions/workflows/codeql-analysis.yml)
[](https://badge.fury.io/py/annofabapi)
[](https://pypi.org/project/annofabapi/)
[](https://annofab-api-python-client.readthedocs.io/en/latest/?badge=latest)
* **Annofab Web API Documentation:** https://annofab.com/docs/api/
* **Reference Documentation:** https://annofab-api-python-client.readthedocs.io/en/latest/
* **annofab-cli** https://github.com/kurusugawa-computer/annofab-cli
* 「タスクの一括差し戻し」や、「プロジェクト間の差分表示」など、Annofabの画面で実施するには時間がかかる操作を、CLIツールとして提供しています。
* **開発者用ドキュメント**: [README_for_developer.md](https://github.com/kurusugawa-computer/annofab-api-python-client/blob/main/README_for_developer.md)
# 注意
* 作者または著作権者は、ソフトウェアに関してなんら責任を負いません。
* 現在、APIは開発途上版です。予告なく互換性のない変更がある可能性をご了承ください。
* put, post, delete系のメソッドを間違えて実行してしまわないよう、注意してください。特に「プロジェクト削除」や「アノテーション仕様更新」のAPIには十分注意してください。
# 廃止予定
### 2022/08/23 以降
検査コメント関連のWebAPIの廃止に伴い、以下のメソッドやクラスを廃止します。
* `annofabapi.AnnofabApi.batch_update_inspections`:替わりに`annofabapi.AnnofabApi.batch_update_comments`を使用してください。
* `annofabapi.AnnofabApi.get_inspections`:替わりに`annofabapi.AnnofabApi.get_comments`を使用してください。
* annofabapi.Wrapper.update_status_of_inspections
* annofabapi.dataclasses.inspection
* annofabapi.models.InspectionStatus
### 2022/12/01 以降
以下のデータクラスを廃止します。
* `annofabapi.dataclass.instruction.*`
* `annofabapi.dataclass.statistics.*`
* `annofabapi.dataclass.webhook.*`
* `annofabapi.dataclass.my.*`
* `annofabapi.dataclass.organization.OrganizationActivity`
# Features
cURLやPostmanなどよりも簡単にAnnofab Web APIにアクセスできます。
* ログインを意識せずに、APIを利用できます。
* アクセス過多などで失敗した場合は、リトライされます。
* 「画像を入力データとして登録する」機能など、APIを組み合わせた機能も利用できます。
# Requirements
* Python 3.8+
# Install
```
$ pip install annofabapi
```
https://pypi.org/project/annofabapi/
# Usage
## インスタンス生成
### user_id, passwordをコンストラクタ引数に渡す場合
```python
# APIアクセス用のインスタンスを生成
from annofabapi import build
user_id = "XXXXXX"
password = "YYYYYY"
service = build(user_id, password)
```
### `.netrc`に認証情報を記載する場合
`.netrc`ファイルに、AnnofabのユーザIDとパスワードを記載します。
```plain:.netrc
machine annofab.com
login annofab_user_id
password annofab_password
```
```python
from annofabapi import build_from_netrc
service = build_from_netrc()
```
#### For Linux
* パスは`$HOME/.netrc`
* `$ chmod 600 $HOME/.netrc`でパーミッションを変更する
#### For Windows
* パスは`%USERPROFILE%\.netrc`
### 環境変数に認証情報を設定する場合
環境変数`ANNOFAB_USER_ID`、`ANNOFAB_PASSWORD`にユーザIDとパスワードを設定します。
```python
from annofabapi import build_from_env
service = build_from_env()
```
### `.netrc`または環境変数に認証情報を設定する場合
``build()`` を実行すると、環境変数または `.netrc` ファイルから認証情報を読み込みます。
```python
from annofabapi import build
service = build()
```
優先順位は以下の通りです。
1. 環境変数
2. `.netrc`
## `service.api`のサンプルコード
* `service.api`には、Web APIに対応するメソッドが定義されています。
* メソッド名は、[Annofab Web APIのOpenAPI specification](https://annofab.com/docs/api/swagger.yaml)に記載されている`operationId`を、スネークケースに変換したものです。
* 各メソッドの戻り値の型は`Tupple[Content, Response]`です。
Responseは[requestsモジュールのReponseオブジェクト](https://2.python-requests.org/en/master/api/#requests.Response)です。
ContentはReponseの中身です。
```python
project_id = "ZZZZZZ"
# `status`が`complete`のタスクを取得する
content, response = service.api.get_tasks(project_id, query_params={"status": "complete"})
print(type(content))
# <class 'dict'>
print(content)
# {'list': [{'project_id': 'ZZZZZZ', 'task_id': '20190317_2', 'phase': 'acceptance', ...
print(type(response))
# <class 'requests.models.Response'>
print(response.headers["Content-Type"])
# application/json
```
## `service.wrapper`のサンプルコード
`service.wrapper`には、`server.api`を組み合わせたメソッドが定義されています。
```python
# `status`が`complete`のタスクすべてを取得する
tasks = service.wrapper.get_all_tasks(project_id, query_params={"status": "complete"})
print(type(tasks))
# <class 'list'>
print(tasks)
# [{'project_id': 'ZZZZZZ', 'task_id': '20190317_2', 'phase': 'acceptance', ...
# simpleアノテーションzipのダウンロード
service.wrapper.download_annotation_archive(project_id, 'output_dir')
# 画像ファイルを入力データとして登録する
service.wrapper.put_input_data_from_file(project_id, 'sample_input_data_id', f'sample.png')
```
## アノテーションzipの読み込み
ダウンロードしたアノテーションzipを、JSONファイルごとに読み込みます。
zipファイルを展開したディレクトリも読み込み可能です。
```python
import zipfile
from pathlib import Path
from annofabapi.parser import lazy_parse_simple_annotation_dir, lazy_parse_simple_annotation_zip, SimpleAnnotationZipParser, SimpleAnnotationDirParser, lazy_parse_simple_annotation_zip_by_task
# Simpleアノテーションzipの読み込み
iter_parser = lazy_parse_simple_annotation_zip(Path("simple-annotation.zip"))
for parser in iter_parser:
simple_annotation = parser.parse()
print(simple_annotation)
# Simpleアノテーションzipを展開したディレクトリの読み込み
iter_parser = lazy_parse_simple_annotation_dir(Path("simple-annotation-dir"))
for parser in iter_parser:
simple_annotation = parser.parse()
print(simple_annotation)
# Simpleアノテーションzipをタスク単位で読み込む
task_iter_parser = lazy_parse_simple_annotation_zip_by_task(Path("simple-annotation.zip"))
for task_parser in task_iter_parser:
print(task_parser.task_id)
for parser in task_parser.lazy_parse():
simple_annotation = parser.parse()
print(simple_annotation)
# Simpleアノテーションzip内の1個のJSONファイルを読み込み
with zipfile.ZipFile('simple-annotation.zip', 'r') as zip_file:
parser = SimpleAnnotationZipParser(zip_file, "task01/12345678-abcd-1234-abcd-1234abcd5678.json")
simple_annotation = parser.parse()
print(simple_annotation)
# Simpleアノテーションzip内を展開したディレクトリ内の1個のJSONファイルを読み込み
parser = SimpleAnnotationDirParser(Path("task01/12345678-abcd-1234-abcd-1234abcd5678.json"))
simple_annotation = parser.parse()
print(simple_annotation)
```
## DataClass
`annofabapi.dataclass`に、データ構造用のクラスがあります。
これらのクラスを利用すれば、属性で各値にアクセスできます。
```python
from annofabapi.dataclass.task import Task
dict_task, _ = service.api.get_task(project_id, task_id)
task = Task.from_dict(dict_task)
print(task.task_id)
print(task.status)
```
## 備考
### `annofabapi`のログを出力する方法(サンプル)
```python
import logging
logging_formatter = '%(levelname)-8s : %(asctime)s : %(name)s : %(message)s'
logging.basicConfig(format=logging_formatter)
logging.getLogger("annofabapi").setLevel(level=logging.DEBUG)
```
نیازمندی
| مقدار | نام |
|---|---|
| - | requests |
| - | python-dateutil |
| - | backoff |
| - | dataclasses-json |
| - | more-itertools |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.8,<4.0 | Python |
نحوه نصب
نصب پکیج whl annofabapi-0.9.1:
pip install annofabapi-0.9.1.whl
نصب پکیج tar.gz annofabapi-0.9.1:
pip install annofabapi-0.9.1.tar.gz