Skip to main content

elabftw-toolkit

PyPI Python Docs License

eLabFTW の実験ノート(Experiment)と Resource / Database item を Python から操作するための、非公式の toolkit です。 テンプレートからの作成、項目の読み書き、ファイルの添付、リンク、権限、lock などのよくある作業を、短いスクリプトで書けます。

📖 ドキュメント(利用者ガイド・チートシート・レシピ集): https://jasri-jp.github.io/elabftw-toolkit/

English / 利用者ガイド / ドキュメントサイト

eLabFTW 本体・公式 SDK とは別のプロジェクトです。eLabFTW のバージョンや設定によって動きが変わることがあるので、本番で使う前に検証用の entry で試してください。

できること

  • 作る:テンプレートから実験ノートや Resource item を作る(本文・項目・Steps・権限を引き継ぐ)
  • 読む・書く:項目の値を entry.fields["purity"] のように dict と同じ感覚で扱う
  • 探す:一覧を表 (DataFrame) で、全件を JSON で取得する。条件検索や title での検索もできる
  • 添付する:ファイルの添付(同じファイルは飛ばす)、一括ダウンロード、本文への画像の追加、PDF / ELN / JSON での書き出し
  • つなぐ・管理する:entry どうしのリンク、タグ、権限、lock とタイムスタンプ、本文の表と Steps
  • 安全に書き込む:書き込まずに試す(dry_run)、スキーマでの確認、二重登録の防止、変更者の記録
  • 書き出す:MaiML(JIS K 0200)形式への書き出し(追加インストールが必要)

インストール

Python 3.10 以上が必要です。

python -m pip install elabftw-toolkit            # 基本
python -m pip install "elabftw-toolkit[maiml]"   # MaiML への書き出しも使う場合
python -m pip install "elabftw-toolkit[mcp]"     # MCP サーバー(Claude Desktop など)も使う場合
python -m pip install "elabftw-toolkit[benten]"  # BENTEN のメタデータ(YAML・Excel)も扱う場合

開発する場合(ソースを直しながら使う)は、clone して editable install にします。

git clone https://github.com/jasri-jp/elabftw-toolkit.git
cd elabftw-toolkit
python -m pip install -e ".[maiml,mcp,benten]"

設定

eLabFTW の接続先と API key を環境変数で指定します。

ELABFTW_HOST_URL="https://your-elabftw.example.jp"
ELABFTW_API_KEY="your-api-key"
  • API key をファイルに置くときは、ELABFTW_API_KEY の代わりに ELABFTW_KEY_FILE="/path/to/api_key.txt" を使います。
  • .env ファイルは自動では読みません。使うときは先に from dotenv import load_dotenv; load_dotenv() を呼びます。
  • 引数での指定や SSL の設定は 1. はじめに を見てください。

5 分で試す

import elabftw_toolkit

elab = elabftw_toolkit.client("your-team-name")

# 試料を title で探して開く
sample = elab.items.find("TEST_SAMPLE", category_title="試料")
entry = elab.items.entry(sample.id)

# 項目を読む・書く
print(entry.fields["purity"])
entry.fields.update({"purity": "99.9%", "form": "粉末"})

# lock されていても、一時的に外して書き換える(終わったら元に戻る)
with entry.unlocked():
    entry.fields["purity"] = "99.99%"

# ファイルを添付する(同じファイルがあれば飛ばす)
entry.files.upload("coa.pdf")

# テンプレートから実験ノートを作り、試料とつなぐ
exp_id = elab.experiments.init(
    title="2026T0001-XAFS-TEST_SAMPLE",
    template_name="計測試験",
    category_id=elab.experiments.categories.id("計測"),
)
elab.experiments.entry(exp_id).set_item_field_and_link(
    field_name="sample_id", item_title="TEST_SAMPLE", item_category_title="試料",
)

"試料"・"計測"・"計測試験" などの名前は例です。お使いの eLabFTW の設定に合わせてください。

利用者ガイド

やりたいこと ページ
使い始める 1. はじめに、12. トラブルシューティング
読む・探す 2. entry と項目、3. 一覧と検索
作る・添付する・つなぐ 4. 作成とテンプレート、5. 添付ファイルと画像、6. リンクとタグ
権限・lock・本文の表 7. 権限、8. lock とタイムスタンプ、9. HTML の表と Steps
まとめて処理する・書き出す 11. よくある作業の手順集、10. MaiML への書き出し
安全に書き込む 15. 確かめと計画
関数を調べる・古いスクリプトを直す 14. API 一覧
開発に参加する 13. テストと開発
Claude などの AI から使う・AI と一緒に作る 16. MCP サーバー、17. AI と一緒に作る

ドキュメントサイト

公開版: https://jasri-jp.github.io/elabftw-toolkit/ (main に push すると GitHub Actions で作り直されます。.github/workflows/docs.yml)

同じガイドを、はじめての方向けの説明・チートシート・レシピと一緒にブラウザで読めます(VitePress、Node.js が要る)。

npm install
npm run dev      # ガイドを取り込んで http://localhost:5173 で開く
npm run build    # docs/.vitepress/dist/ に HTML を書き出す

Windows では docs_preview.bat をダブルクリックすると、原稿を取り込んでブラウザで開きます(Node.js が要る)。 Google Drive などの同期フォルダの中でも動くように、サイトを %USERPROFILE%\.cache\elabftw-toolkit-docs に写して、そこで動かします (初回だけ VitePress を入れるので少し時間がかかる)。原稿を直したら、もう一度ダブルクリックしてください。

内容 置き場所
利用者ガイドの原稿(日本語・英語) docs/ja・docs/en(章の順は mkdocs.yml)
トップページ・はじめての方へ・チートシート・レシピ集 docs/index.md・docs/guide/・docs/recipes/・docs/en/index.md・docs/en/guide/
図・画像 docs/public/
サイトの設定 docs/.vitepress/

scripts/sync-manual.mjs が原稿を章番号の URL(/manual/04、/en/manual/04)に写し、examples/ の見本をダウンロードできるように置きます(どちらも生成物なので git には入れない)。 Google Drive などの同期フォルダの中では node_modules のリンクを作れず、npm run dev / build が失敗します。そのときは docs_preview.bat を使うか、同期の外に写して動かしてください。

テスト

python -m pip install -e ".[maiml]" pytest
pytest    # eLabFTW には接続しない

tests/live/ は実サーバーに書き込む確認用スクリプトで、pytest では実行しません。詳しくは 13. テストと開発 を見てください。

ライセンス

Apache License 2.0(LICENSE)

このライブラリは eLabFTW の REST API を使うための補助ライブラリとして独自に実装したものです。eLabFTW のサーバー側のソースコードは含まず、改変・再配布もしていません。eLabFTW API の Python クライアント elabapi-python(MIT License)と組み合わせて使います。

設計と利用例の検討では、NAIST の eLabFTW 関連リポジトリ naist-eln/eln を参考にしましたが、コードをそのまま複製したものではありません。なお、NAIST のリポジトリの API/ には GNU Affero General Public License v3.0(AGPL-3.0)のライセンスファイルが含まれています。


Copyright 2026 Japan Synchrotron Radiation Research Institute (JASRI) and Takahiro Matsumoto

Metadata

Release files for elabftw-toolkit 0.1.3

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

Source distribution (sdist)

Source distribution for elabftw-toolkit 0.1.3
File Size Uploaded Provenance Actions
elabftw_toolkit-0.1.3.tar.gz 183.5 kB With provenance Details for elabftw_toolkit-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for elabftw-toolkit 0.1.3
File Interpreter ABI Platform Actions
elabftw_toolkit-0.1.3-py3-none-any.whl Python 3 none any Details for elabftw_toolkit-0.1.3-py3-none-any.whl

Total release size: 349.1 kB

Release files / elabftw_toolkit-0.1.3.tar.gz

Download URL elabftw_toolkit-0.1.3.tar.gz
Size 183.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ed6862785ecbdc467c856cadcc24742e6a5c721a927ab38a38aa90e0bf863292
BLAKE2b-256 checksum
How to use checksums
f739308b5691234132f3b60ff4bae9ac47d85036035aa2e32aabb05f2092521a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / elabftw_toolkit-0.1.3-py3-none-any.whl

Download URL elabftw_toolkit-0.1.3-py3-none-any.whl
Size 165.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97769e4b0c99ea4eaf6536e0a8af019294cf85233d4a5d0014af858af05748d6
BLAKE2b-256 checksum
How to use checksums
ed9e98fc650d7d6ad03caf0578288e3fdda7011da32aad667031b036a93bc371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for elabftw-toolkit 0.1.3

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for elabftw_toolkit-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

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.

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