Skip to main content

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

Metadata

Release files for kaken-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kaken-api 0.1.0
File Size Uploaded Provenance
kaken_api-0.1.0.tar.gz 20.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kaken-api 0.1.0
File Interpreter ABI Platform
kaken_api-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.5 kB

Release files / kaken_api-0.1.0.tar.gz

Download URL kaken_api-0.1.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9aed11b00c50746365e80f3e9ee74d3dbebf20d5a60cb8311406adbb92c781bd
BLAKE2b-256 checksum
How to use checksums
8ba033e558f3a10c68279592c3681e70928bff3c3f158909fce38d4641bad07b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / kaken_api-0.1.0-py3-none-any.whl

Download URL kaken_api-0.1.0-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fe992d8fe95768e86ccc0a5e7962b2a006257a007497040dd2362d00f7ef0d4
BLAKE2b-256 checksum
How to use checksums
26bd4e598a5368dd5599dabd95d91dc13bd98dd8fe941ed73b274114ef9a1771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for kaken-api 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page