2
3

More than 3 years have passed since last update.

2021-07-30 Qiita の Python 用 API の概要

Last updated at Posted at 2021-07-30

qiita_v2 は Qiita の Web API の Python 用のラッパです。触り始めたところですけれど、簡単に利用できます。ただ、利用できるメソッドが多いのとドキュメントがほとんどないので、自分なりに整理してみました。

情報源

インストール

pip install qiita_v2

Python 用 API について学ぼう

Python に特化した技術文書はなさそう。Web API のドキュメント を読みながら想像するのが正しそうだけれど、Python の doc string で学ぶ手抜きをしました。

まず Python に API を読み込みます。

from qiita_v2.client import QiitaClient

ここで QiitaClient の doc string を見てもよいかもしれないけれども、情報密度が低く、一覧性に乏しいので今ひとつ。

ひとまず、QiitaClient クラスのインスタンスのメソッド一覧を眺めてみました。

>>> QiitaClient(config_file='/Users/wakita/.qiita-vim').__dir__()
['access_token', 'team', '__module__', '__doc__', 'create_access_token', 'delete_access_token',

 ... 中略 ...

 'delete_reaction_project', 'HOST', 'USER_AGENT', 'ACCEPT', 'HEADER', '__init__', '_url_prefix',

 ... 中略 ... ]

メソッド一覧のなかから気になるメソッドの使い方を調べるには help(QiitaClient.list_user_items) のように help 関数に頼りましょう。

Help on function list_user_items in module qiita_v2.client:

list_user_items(self, user_id, params=None, headers=None)
    特定のユーザの投稿一覧を返します。

上のメソッド一覧は煩雑なので、整理しました。

header, get, post, put, patch, delete, request,

get_{authenticated_user{, _items},
     comment{, _likes, _reactions},
     item{, _likes, _reactions, _stock},
     project{, _likes, _reactions},
     tag{, _following},
     template,
     user{, _following},

{create, delete}_{access_token, item, item_comment, project}

list_{item_{comments, stockers}, items, projects, tag_items, tags, teams, templates,
      user_{followees, followers, following_tags, items, stocks}, users}

{like, update, delete}_{comment, item, project},
{, delete}_reaction_{comment, item, project},

{create, update, delete}_template,
create_expanded_template

{, un}{follow_{tag, user}, {lgtm_item, stock_item, thank_comment}}
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3