Python Clinet Library of AnnoFab API (https://annofab.com/docs/api/)
Project description
annofab-api-python-client
AnnoFab Web APIのPythonクライアントライブラリです。
注意
- 作者または著作権者は、ソフトウェアに関してなんら責任を負いません。
- 現在、APIは開発途上版です。予告なく互換性のない変更がある可能性をご了承ください。
- put, post, delete系のメソッドを間違えて実行してしまわないよう、注意してください。特に「プロジェクト削除」や「アノテーション仕様更新」のAPIには十分注意してください。
Features
cURLやPostmanなどよりも簡単にAnnoFab Web APIにアクセスできます。
- ログインを意識せずに、APIを利用できます。
- アクセス過多などで失敗した場合は、リトライされます。
- 「画像を入力データとして登録する」機能など、APIを組み合わせた機能も利用できます。
Requirements
- Python 3.6+
Install
$ pip install annofabapi
https://pypi.org/project/annofabapi/
Usage
インスタンス生成
user_id, passwordをコンストラクタ引数に渡す
# APIアクセス用のインスタンスを生成
from annofabapi import build
user_id = "XXXXXX"
password = "YYYYYY"
service = build(user_id, password)
.netrc
に記載されたuser_id, passwordから生成
.netrc
ファイルに、AnnofabのユーザIDとパスワードを記載する。
machine annofab.com
login annofab_user_id
password annofab_password
from annofabapi import build_from_netrc
service = build_from_netrc()
For Linux
- パスは
$HOME/.netrc
$ chmod 600 $HOME/.netrc
でパーミッションを変更する
For Windows
- パスは
%USERPROFILE%\.netrc
service.api
のサンプルコード
service.api
には、Web APIに対応するメソッドが定義されています。- メソッド名は、AnnoFab Web APIのOpenAPI specificationに記載されている
operationId
をスネークケースに変換したものです。 - 各メソッドの戻り値は
Tupple[Content, Response]
です。 ResponseはrequestsモジュールのReponseオブジェクトです。 ContentはReponseの中身です。
project_id = "ZZZZZZ"
# `status`が`complete`のタスクを取得する
content, response = service.api.get_tasks(project_id, query_params={'status': 'complete'})
print(content)
# {'list': [{'project_id': ...
# simpleアノテーションzipのダウンロード用URLを取得する
content, response = service.api.get_annotation_archive(project_id)
url = response.headers['Location']
service.wrapper
のサンプルコード
service.wrapper
は、APIを組み合わせたメソッドが定義されています。
# `status`が`complete`のタスクすべてを取得する
tasks = service.wrapper.get_all_tasks(project_id, query_params={'status': 'complete'})
print(tasks)
# [{'project_id': ...
# 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')
src_project_id = "AAAAAA"
dest_project_id = "BBBBBB"
# プロジェクトメンバをコピー(誤って実行しないように注意すること)
service.wrapper.copy_project_members(src_project_id, dest_project_id)
# アノテーション仕様のコピー(誤って実行しないように注意すること)
service.wrapper.copy_annotation_specs(src_project_id, dest_project_id)
備考
ログの出力方法の例
import logging
logging_formatter = '%(levelname)s : %(asctime)s : %(name)s : %(funcName)s : %(message)s'
logging.basicConfig(format=logging_formatter)
logging.getLogger("annofabapi").setLevel(level=logging.DEBUG)
リトライの処理をカスタマイズ
TODO
Usage for Develper
README_for_developer.mdを参照してください。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
annofabapi-0.4.2-py3-none-any.whl
(30.2 kB
view hashes)
Close
Hashes for annofabapi-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aede924267cf1fd297b8a8daf1eeb98b68abed891ea3bd2a6bfa45b059775b0 |
|
MD5 | 9a65437ca3ee99cab09f4073b3adef9b |
|
BLAKE2b-256 | 22cde60d315a23e624cfe7efd931c9c396045e3479ab43874a3bc475b604937d |