Skip to main content

KAKEN API Client Library for Python

Project description

KAKEN API Client Library for Python

Python Tests Lint Documentation PyPI version

Note: このライブラリは VSCode Cline Anthropic Claude 3.7 Sonnet によって作成されています。

KAKEN API(科研費API)のPythonクライアントライブラリです。このライブラリを使用すると、科研費の研究課題や研究者の情報を簡単に検索・取得することができます。

インストール

pip install kaken_api

使用方法

初期化

from kaken_api import KakenApiClient

# アプリケーションIDを指定して初期化
client = KakenApiClient(app_id="your_app_id")

# または、アプリケーションIDなしで初期化(一部の機能が制限される場合があります)
client = KakenApiClient()

# キャッシュを無効化して初期化
client = KakenApiClient(use_cache=False)

# カスタムキャッシュディレクトリを指定して初期化
client = KakenApiClient(cache_dir="/path/to/cache")

キャッシュ機能

このライブラリには、APIリクエストの結果をキャッシュする機能が組み込まれています。これにより、同じリクエストを繰り返し行う場合に、APIサーバーへの負荷を軽減し、レスポンス時間を短縮することができます。

キャッシュはデフォルトで有効になっており、~/.kaken_api_cacheディレクトリに保存されます。キャッシュを無効化したり、カスタムキャッシュディレクトリを指定したりすることもできます。

# キャッシュを無効化
client = KakenApiClient(use_cache=False)

# カスタムキャッシュディレクトリを指定
client = KakenApiClient(cache_dir="/path/to/cache")

# キャッシュをクリア
client.cache.clear()

研究課題の検索

# キーワードで検索
projects = client.projects.search(keyword="人工知能")

# 詳細な検索条件を指定
projects = client.projects.search(
    project_title="深層学習",
    research_category="基盤研究",
    grant_period_from=2020,
    grant_period_to=2023,
    results_per_page=50,
    language="ja",
)

# 検索結果の処理
print(f"検索結果: {projects.total_results}件")
for project in projects.projects:
    print(f"課題番号: {project.award_number}")
    print(f"課題名: {project.title}")
    print("---")

研究者の検索

# キーワードで検索
researchers = client.researchers.search(keyword="田中")

# 詳細な検索条件を指定
researchers = client.researchers.search(
    researcher_name="田中",
    researcher_institution="東京大学",
    results_per_page=50,
    language="ja",
)

# 検索結果の処理
print(f"検索結果: {researchers.total_results}件")
for researcher in researchers.researchers:
    if researcher.name:
        print(f"研究者名: {researcher.name.full_name}")
    for affiliation in researcher.affiliations:
        if affiliation.institution:
            print(f"所属機関: {affiliation.institution.name}")
        if affiliation.department:
            print(f"部局: {affiliation.department.name}")
        if affiliation.job_title:
            print(f"職名: {affiliation.job_title.name}")
    print("---")

アプリケーションIDの取得

KAKEN APIを利用するには、CiNiiのアプリケーションIDが必要です。以下の手順で取得してください。

  1. CiNii全般 - メタデータ・API - API利用登録 のページにアクセスします。
  2. 「API利用登録」のリンクをクリックし、必要事項を入力して登録します。
  3. 登録が完了すると、アプリケーションIDが発行されます。

GitHub Actionsでのテスト実行

このリポジトリではGitHub Actionsを使用して自動テストを実行しています。APIを使用するテストを実行するには、GitHub SecretsにアプリケーションIDを設定する必要があります。

  1. GitHubリポジトリの「Settings」→「Secrets and variables」→「Actions」に移動します。
  2. 「New repository secret」ボタンをクリックします。
  3. 名前に「KAKEN_APP_ID」、値にアプリケーションIDを入力して保存します。

これにより、GitHub Actions上でもAPIを使用するテストが実行されるようになります。

なお、フォークされたリポジトリからのプルリクエストでは、セキュリティ上の理由からシークレットにアクセスできないため、APIを使用するテストはスキップされます。

ライセンス

MIT License

参考資料

Submodules

[submodule "kaken_definition"]
        path = kaken_definition
        url = https://bitbucket.org/niijp/kaken_definition
[submodule "grants_masterxml_kaken"]
        path = grants_masterxml_kaken
        url = https://bitbucket.org/niijp/grants_masterxml_kaken

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaken_api-0.1.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kaken_api-0.1.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file kaken_api-0.1.0.tar.gz.

File metadata

  • Download URL: kaken_api-0.1.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for kaken_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9aed11b00c50746365e80f3e9ee74d3dbebf20d5a60cb8311406adbb92c781bd
MD5 2020335e4dbc605654b7d73297cfa1b4
BLAKE2b-256 8ba033e558f3a10c68279592c3681e70928bff3c3f158909fce38d4641bad07b

See more details on using hashes here.

File details

Details for the file kaken_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kaken_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for kaken_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fe992d8fe95768e86ccc0a5e7962b2a006257a007497040dd2362d00f7ef0d4
MD5 8df10c25168cb649efa844f5c7cd60dc
BLAKE2b-256 26bd4e598a5368dd5599dabd95d91dc13bd98dd8fe941ed73b274114ef9a1771

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page