14. API reference
A table of the most common calls. See the individual pages for how to use them. Experiments and Resource items have methods with almost the same names (the tables write elab.experiments.entry(experiment_id) / elab.items.entry(item_id) separately).
Client wrapper
| Call | Description |
|---|---|
elabftw_toolkit.client(team_name, host_url=None, api_key=None, *, key_file=None, verify_ssl=False, check=False) | Create an eLabFTW API client wrapper |
elab.api_client | Property returning the underlying elabapi_python.ApiClient |
elab.team_id | Property returning the ID of the team specified when the client was created |
elab.check_connection() | Check the API connection |
elab.get(path, **params) / elab.patch(path, body) | Call API v2 directly (returns JSON) |
elab.entry(kind, id) | Get an entry with the kind given as a string |
elab.permission_base | Namespace of base permission constants for permissions |
elabftw_toolkit.extra_fields(entry) / extra_field_units(entry) / metadata_of(entry) | Read field values, units, or the metadata dict from an already fetched entry (dict) |
elabftw_toolkit.make_experiment_title(proposal_id=, sample_context=) | Build a title of the form <proposal_id>-<sample_context> |
IDs and lists
| Call | Description |
|---|---|
elab.teams.list() | Get the list of teams as a DataFrame |
elab.teams.id(team_name) | Get a team ID from a team name |
elab.teams.current_id() | Get the ID of the team specified when the client was created |
elab.experiments.categories.list() | List Experiment categories |
elab.experiments.categories.id(category_name) | Get an Experiment category ID from its name |
elab.experiments.statuses.list() | List Experiment statuses |
elab.experiments.statuses.id(status_name) | Get an Experiment status ID from its name |
elab.items.categories.list() | List Resource item categories |
elab.items.categories.id(category_name) | Get a Resource item category ID from its name |
elab.items.statuses.list() | List Resource item statuses |
elab.items.statuses.id(status_name) | Get a Resource item status ID from its name |
templates / experiments / items
| Call | Description |
|---|---|
elab.experiments.templates.list() | List Experiment templates |
elab.experiments.templates.id(template_name) | Get a template ID from its name |
elab.experiments.templates.entry(template_id) | Get the template itself from a template ID |
elab.experiments.templates.raw(template_id) | Get the raw template entity |
elab.experiments.templates.check(template) | Display the template body and metadata for inspection |
elab.experiments.templates.prepare_metadata(...) | Prepare template metadata for a new Experiment |
elab.items.templates.list() | List Resource item templates / item types |
elab.items.templates.id(template_name) | Get a Resource item template / item type ID from its name |
elab.items.templates.entry(template_id) | Get Resource item template / item type information |
elab.items.templates.raw(template_id) | Get Resource item template / item type information |
elab.experiments.list() | List Experiments as a DataFrame |
elab.experiments.all(full=False, cache_dir=None, category_title=None) | Get Experiments as a list of API JSON dicts |
elab.experiments.latest_id() | Get the latest Experiment ID |
elab.experiments.init(..., tags=...) | Create an Experiment, optionally initializing its tags |
elab.experiments.find(title, ...) | Find an Experiment by exact title |
elab.experiments.entry(experiment_id).category() | Get the Experiment's category ID and title |
elab.experiments.entry(experiment_id).category_id() | Get the Experiment's category ID |
elab.experiments.entry(experiment_id).category_title() | Get the Experiment's category title |
elab.experiments.entry(experiment_id).set_category(...) | Update the Experiment's category by ID or title |
elab.experiments.entry(experiment_id).status() | Get the Experiment's status ID and title |
elab.experiments.entry(experiment_id).status_id() | Get the Experiment's status ID |
elab.experiments.entry(experiment_id).status_title() | Get the Experiment's status title |
elab.experiments.entry(experiment_id).set_status(...) | Update the Experiment's status by ID or title |
elab.experiments.entry(experiment_id).download(...) | Export the Experiment |
elab.experiments.entry(experiment_id).lock() | Lock the Experiment |
elab.experiments.entry(experiment_id).unlock() | Unlock the Experiment |
elab.experiments.entry(experiment_id).timestamp() | Timestamp the Experiment |
elab.experiments.entry(experiment_id).is_locked() | Whether the entry is locked (same for items) |
elab.experiments.entry(experiment_id).unlocked(relock=None) | Unlock for editing and restore the state on exit (use with with) |
elab.experiments.entry(experiment_id).raw() | Get the entry as API v2 JSON |
elab.experiments.entry(experiment_id).patch(**fields) | PATCH attributes (body, title, etc.) as is |
elab.experiments.entry(experiment_id).fields | Read and write extra_fields as {field name: value} |
elab.experiments.entry(experiment_id).id | The entry ID (same for items) |
elab.items.list(...) | List Resource / Database items as a DataFrame |
elab.items.all(full=False, cache_dir=None, category_title=None) | Get Resource / Database items as a list of API JSON dicts |
elab.items.latest_id(...) | Get the latest Resource / Database item ID |
elab.items.init(..., tags=...) | Create a Resource / Database item, optionally initializing its tags |
elab.items.find(title, ...) | Find a Resource / Database item by exact title |
elab.items.entry(item_id).category() | Get the item's category ID and title |
elab.items.entry(item_id).category_id() | Get the item's category ID |
elab.items.entry(item_id).category_title() | Get the item's category title |
elab.items.entry(item_id).set_category(...) | Update the item's category by ID or title |
elab.items.entry(item_id).status() | Get the item's status ID and title |
elab.items.entry(item_id).status_id() | Get the item's status ID |
elab.items.entry(item_id).status_title() | Get the item's status title |
elab.items.entry(item_id).set_status(...) | Update the item's status by ID or title |
elab.items.entry(item_id).download(...) | Export the Resource / Database item |
elab.items.entry(item_id).lock() | Lock the Resource / Database item |
elab.items.entry(item_id).unlock() | Unlock the Resource / Database item |
elab.items.entry(item_id).timestamp() | Timestamp the Resource / Database item |
elab.items.entry(item_id).unlocked(relock=None) / .raw() / .patch(**fields) / .fields | Same as for Experiments |
search / metadata / link / tags
| Call | Description |
|---|---|
elab.experiments.query.search(...) | Search Experiments by conditions |
elab.experiments.query.first(...) | Get the first search result |
elab.experiments.query.ids(...) | Get the IDs of the search results |
elab.items.query.search(...) | Search Resource / Database items by conditions |
elab.items.query.first(...) | Get the first search result |
elab.items.query.ids(...) | Get the IDs of the search results |
elab.experiments.entry(experiment_id).metadata.get() | Get Experiment metadata |
elab.experiments.entry(experiment_id).metadata.update(...) | Update Experiment metadata |
elab.experiments.entry(experiment_id).metadata.structured() | Get Experiment structured metadata |
elab.experiments.entry(experiment_id).metadata.update_structured(...) | Update Experiment structured metadata |
elab.experiments.entry(experiment_id).metadata.delete_structured() | Delete Experiment structured metadata |
elab.items.entry(item_id).metadata.get() | Get Resource / Database item metadata |
elab.items.entry(item_id).metadata.update(...) | Update Resource / Database item metadata |
elab.items.entry(item_id).metadata.structured() | Get Resource / Database item structured metadata |
elab.items.entry(item_id).metadata.update_structured(...) | Update Resource / Database item structured metadata |
elab.items.entry(item_id).metadata.delete_structured() | Delete Resource / Database item structured metadata |
entry(id).set_item_field(field_name, item_title=, item_category_title=) / set_item_field_and_link(...) | Put a Resource item into an items-type field (_and_link also creates the link; Experiments and items) |
entry(id).set_experiment_field(field_name, experiment_title=, experiment_category_title=) / set_experiment_field_and_link(...) | Put an Experiment into an experiments-type field (Experiments and items) |
elab.experiments.entry(experiment_id).links | Get the link service with the Experiment as the source |
elab.items.entry(item_id).links | Get the link service with the Resource item as the source |
entry(id).links.add_item(target_item_id=) / .add_experiment(target_experiment_id=) / .item_list() / .experiment_list() / .unlink_item(...) / .unlink_experiment(...) | Create, list, and remove links |
elab.tags.load_allowed(csv_path) | Load the list of allowed tags from a CSV file |
elab.experiments.entry(experiment_id).tags.add(...) | Add tags to an Experiment |
elab.experiments.entry(experiment_id).tags.clear(...) | Remove tags from an Experiment |
elab.items.entry(item_id).tags.add(...) | Add tags to a Resource / Database item |
elab.items.entry(item_id).tags.clear(...) | Remove tags from a Resource / Database item |
steps / permissions
| Call | Description |
|---|---|
elab.experiments.entry(experiment_id).steps.list() | Get the Experiment's Steps |
elab.experiments.entry(experiment_id).steps.add(body, ...) | Add a Step to the Experiment |
elab.experiments.entry(experiment_id).steps.update(step_id, body=..., finished=...) | Update a Step's body |
elab.experiments.entry(experiment_id).steps.set_finished(step_id, ...) | Update a Step's checked state |
elab.experiments.entry(experiment_id).steps.set_finished_by_body(...) | Find a Step by its body and update its checked state |
elab.items.entry(item_id).steps.list() | Get the Resource / Database item's Steps |
elab.items.entry(item_id).steps.add(body, ...) | Add a Step to the Resource / Database item |
entry(id).steps.toggle(step_id) / .delete(step_id) / .replace(step_bodies) / .copy_to(target_entity_id) / .raw() | Toggle, delete, replace, copy, or get raw Steps (Experiments and items) |
elab.experiments.entry(experiment_id).permissions.read() | Get the Experiment's permissions |
elab.experiments.entry(experiment_id).permissions.base_permissions() | List the base permissions |
elab.experiments.entry(experiment_id).permissions.usergroups(...) | List User Groups |
elab.experiments.entry(experiment_id).permissions.users(...) | List users |
elab.experiments.entry(experiment_id).permissions.set_read_permissions(...) | Set the Experiment's read permissions |
elab.experiments.entry(experiment_id).permissions.set_write_permissions(...) | Set the Experiment's write permissions |
elab.experiments.entry(experiment_id).permissions.set_read_base(...) | Set only the Experiment's base read permission |
elab.experiments.entry(experiment_id).permissions.set_write_base(...) | Set only the Experiment's base write permission |
elab.items.entry(item_id).permissions.set_read_permissions(...) | Set the Resource / Database item's read permissions |
elab.items.entry(item_id).permissions.set_write_permissions(...) | Set the Resource / Database item's write permissions |
HTML table / files / images
| Call | Description |
|---|---|
elab.experiments.entry(experiment_id).tables.list() | List the HTML tables in the Experiment body |
elab.experiments.entry(experiment_id).tables.update_horizontal(...) | Update a horizontal HTML table |
elab.experiments.entry(experiment_id).tables.clear_horizontal(...) | Reset a horizontal HTML table to just the header row and an empty value row |
elab.experiments.entry(experiment_id).tables.update_vertical(...) | Update a vertical HTML table |
elab.experiments.entry(experiment_id).tables.get_horizontal(...) | Get the values of a horizontal HTML table |
elab.experiments.entry(experiment_id).tables.get_vertical(...) | Get the values of a vertical HTML table |
elab.experiments.entry(experiment_id).tables.set_collapsible(...) | Make an HTML table collapsible |
elab.items.entry(item_id).tables.list() | List the HTML tables in the Resource item body |
elab.items.entry(item_id).tables.update_horizontal(...) | Update a horizontal HTML table |
elab.items.entry(item_id).tables.clear_horizontal(...) | Reset a horizontal HTML table to just the header row and an empty value row |
elab.items.entry(item_id).tables.update_vertical(...) | Update a vertical HTML table |
elab.items.entry(item_id).tables.get_horizontal(...) | Get the values of a horizontal HTML table |
elab.items.entry(item_id).tables.get_vertical(...) | Get the values of a vertical HTML table |
elab.items.entry(item_id).tables.set_collapsible(...) | Make an HTML table collapsible |
elab.experiments.entry(experiment_id).files.list() | List the Experiment's attachments |
elab.experiments.entry(experiment_id).files.upload(...) | Upload files to the Experiment |
elab.experiments.entry(experiment_id).files.download(...) | Download a file by upload ID |
elab.experiments.entry(experiment_id).files.download_by_name(...) | Download a file by name |
elab.experiments.entry(experiment_id).files.download_all(...) | Download all attachments into a folder |
elab.experiments.entry(experiment_id).files.download_all_zip(...) | Save all attachments together as a zip archive |
elab.experiments.entry(experiment_id).files.delete(...) | Delete a file by upload ID |
elab.experiments.entry(experiment_id).files.delete_by_name(...) | Delete a file by name |
elab.experiments.entry(experiment_id).files.delete_all(confirm=True) | Delete all attachments |
elab.items.entry(item_id).files | Get the file service of a Resource item |
elab.items.entry(item_id).files.download_all_zip(...) | Save all attachments of a Resource item together as a zip archive |
elab.experiments.entry(experiment_id).images.append(...) | Upload images and append them to the Experiment body |
elab.items.entry(item_id).images.append(...) | Upload images and append them to the Resource item body |
Validation and plans (15. Validation and plans)
| Call | Description |
|---|---|
Schema.load(path) / Schema.from_dict(d) | Load a schema (JSON or Excel; BENTEN's eln_schema.json shape too) |
schema.validate(fields, category, *, resolve=None, partial=False) | Check fields; returns ValidationResult (ok, errors, warnings, to_frame(), raise_for_errors()) |
schema.validate_entry(entry_dict) | Check an entry read from the API (category from the entry) |
schema.register_rule(name, func, check_empty=False) / @schema.rule(name) | Add a custom rule (func(value, arg, ctx)) |
schema.register_enum("vocab:xxx", func) | Supply an external enum |
elab.use_schema(schema, on_write=True) | Validate automatically before writing (errors stop, warnings pass) |
entry.fields.validate(schema=None, category=None, resolve=True) / entry.validate(...) | Check the entry's current fields |
entry.fields.update({...}, dry_run=, record=, validate=) | Write with dry run / change record / schema |
entry.patch(..., dry_run=, record=) / entry.tags.add(..., dry_run=, record=) | Same |
entry.links.add_item(id, dry_run=, record=) / add_experiment(...) | Same |
entry.files.upload(path, dry_run=, record=) / entry.lock(dry_run=, record=) / unlock(...) | Same |
elab.items.init(..., dry_run=, record=, validate=) / elab.experiments.init(...) | Same (create) |
elab.plan() | Create a Plan |
plan.update_fields / patch / add_tags / add_link / upload / lock / unlock / create | Add operations |
print(plan) / plan.to_frame() / plan.to_records() / plan.to_dict() | Show old → new values |
plan.check(schema, full=False) / plan.backup(path) / plan.execute(backup_dir=, record=, schema=) | Check, back up, run (plan.created_ids) |
elab.items.find_existing(title=, category_title=, category_id=, fields=, cache_dir=, entries=) | Find existing entries by a combination of fields (experiments too) |
elab.items.upsert(title=, fields=, category_title=, match=, on_exists=, on_many=, dry_run=, record=, validate=, ...) | Create if missing, otherwise update / skip / stop (UpsertResult) |
elab.items.resolve_id(title=, category_title=, fields=) | ID of the single match (stops on 0 or 2+) |
entry.fields.set_link(name, target=None, *, title=, category_title=, fields=, also_link=False, dry_run=, record=) | Put an ID into a link field (checks the target category) |
Ref(title=, category_title=, fields=, kind=, id=) | A value resolved to an ID before writing |
ChangeRecord(by=, reason=, extra={}) | Change record (pass as record=; stored as a comment) |
entry.comments.list() / entry.comments.add(text) | Read / add comments |
elab.check_sdk() | Classes / methods the toolkit uses that are missing from the installed elabapi_python |
| Exceptions | SchemaError (.issues), LinkResolutionError / NotFoundError / AmbiguousError (.candidates), DuplicateError (.existing) |