3. Listing and search (list / all / paging / cache / find)
How to get entries as a list and how to find them by conditions. Which one to use:
| Goal | Use | Returns |
|---|---|---|
| Look at a table | list() | pandas DataFrame (main columns only) |
| Use the contents (fields, attachments, links) in a script | all() | list of API v2 JSON dicts |
| Filter by conditions | query.search() / query.first() / query.ids() | DataFrame / one row / list of IDs |
| Get exactly one entry by title | find() | the single exact match |
The short version
python
for x in elab.items.all(full=True, category_title="Sample", cache_dir="cache"):
print(x["id"], x["title"], elabftw_toolkit.extra_fields(x).get("purity"))
sample = elab.items.find("TEST_SAMPLE", category_title="Sample") # one entry by exact titleViewing a list as a table: list() and the latest ID
python
experiments_df = elab.experiments.list(debug=True)
latest_experiment_id = elab.experiments.latest_id()
items_df = elab.items.list(category_title="Sample", debug=True)
latest_item_id = elab.items.latest_id(category_title="Sample")list()returns all entries by default (the API is called page by page).- To limit the number, pass
limit/offset(counted in descending id order). - Both Experiments and Resource items can be filtered with
category_id/category_title.category_titleis applied after fetching, solimitcounts entries before filtering (category_idis filtered on the server). latest_id()returns the entry with the newest date (_date); on the same date, the one with the larger id.
python
recent_df = elab.experiments.list(limit=50)
measurement_df = elab.experiments.list(category_title="Measurement")
latest_measurement_id = elab.experiments.latest_id(category_title="Measurement")Reading all entries as JSON: all()
list() returns a DataFrame for viewing. When a script needs the contents of entries (metadata, attachments, links, and so on), use all(). It returns a list of API v2 JSON dicts (in descending id order).
python
rows = elab.items.all() # the list API response as is (fast)
samples = elab.items.all(category_title="Sample") # filter by category
entries = elab.items.all(full=True) # complete entries, re-read one by one
entries = elab.experiments.all(full=True, cache_dir="cache") # re-read only changed entries
for x in entries:
fields = elabftw_toolkit.extra_fields(x) # {name: value}
names = [u["real_name"] for u in x.get("uploads", [])]| Argument | Meaning |
|---|---|
full=False (default) | The list API response as is. Fast, but metadata, uploads, and so on may be missing |
full=True | Complete entries re-read one by one (including metadata, uploads, links) |
cache_dir="cache" | With full=True, entries are saved to <cache_dir>/eln_<hostname>_<kind>.json; next time, entries whose modified_at in the list is unchanged are not re-read |
category_title="Sample" | Return only entries in this category |
How many entries were re-read is logged (logger elabftw_toolkit, INFO).
python
import logging
logging.basicConfig(level=logging.INFO)Searching by conditions: query
Searching Experiments
python
experiments_df = elab.experiments.query.search(
title_contains="XAFS",
category_title="Measurement",
status_title="Planned",
tags=["2026T", "BL99XU"],
tag_match="all",
debug=True,
)
experiment = elab.experiments.query.first(title_contains="XAFS", category_title="Measurement") # first hit
experiment_ids = elab.experiments.query.ids(tags=["BL99XU"]) # list of IDsSearching Resource / Database items
python
items_df = elab.items.query.search(
title_contains="MrX",
category_title="People and organizations",
status_title="Registered",
tag_match="all",
debug=True,
)
item = elab.items.query.first(title_contains="2026", category_title="Proposal")
item_ids = elab.items.query.ids(category_title="Sample")Searches fetch all entries (or limit entries) page by page; limit counts in descending id order. query.first() raises ValueError when nothing matches; query.ids() returns an empty list.
Where each condition is applied
qortitle_contains,category_id, andstatus_idare passed to the eLabFTW API (read_experiments()/read_items()) to narrow candidates on the server.title_containsis used as the API'sqand then applied again as a substring match on thetitlecolumn with pandas.category_titleandstatus_titleare not passed to the API; the fetched results are filtered by exact match with pandas. This can mean more entries are fetched first. In large environments, prefercategory_id/status_idwhen possible.- For tags, with
tag_match="all"thetagsare also passed to the API and then checked again with pandas. Withtag_match="any"the API does not use the tag condition; filtering happens with pandas after fetching.
Getting one entry by exact title: find()
python
experiment = elab.experiments.find("2026T0001-XAFS-test_sample-300K", category_title="Measurement")
item = elab.items.find("TEST_SAMPLE", category_title="Sample")
print(item.id, item.title)- The title must match exactly. If nothing or more than one entry is found,
ValueErroris raised. Narrow multiple hits withcategory_title(orcategory_id). - Titles containing parentheses and similar characters also work (all entries are scanned and titles compared). This can be slow with many entries. When checking many titles, fetch the list once with
all()and compare locally (11. Recipes).