Skip to content

First steps ​

This page is for people using elabftw-toolkit for the first time. It covers what the toolkit does, how it works, and how to create your first experiment. You only need basic Python: calling functions and running pip install.

What is elabftw-toolkit? ​

eLabFTW is an electronic lab notebook you use in your browser. You normally create experiments and attach files in the web interface, but repeating the same steps for every measurement gets tedious.

elabftw-toolkit is a library that lets you do those steps from Python in a single line.

How elabftw-toolkit fits in

  • Your Python script (or Jupyter notebook) calls toolkit functions
  • The toolkit sends requests to the eLabFTW API, the interface programs use to talk to eLabFTW
  • The results show up in eLabFTW right away, so you can check them in your browser as usual

Useful when you want to

  • Create experiments in a fixed format automatically for every measurement
  • Attach measurement data files to the matching experiment in one go
  • Search past experiments by condition and view the results as a table (DataFrame)

Why not use the official Python client? ​

eLabFTW has an official Python client, elabapi-python, and the toolkit uses it internally. The official client maps the API one-to-one, though, so even creating one experiment means writing several low-level steps yourself. The toolkit bundles the routine code you'd otherwise write every time.

TaskOfficial client onlytoolkit
Set a category or statusLook up the numeric IDUse the name, like categories.id("Measurement")
Get the ID of a new entryParse it from the response headersReturned directly by init()
Fill in field valuesRead the whole metadata JSON and rebuild itWrite only the fields you need with fields.update({"name": value})
Attach a fileCheck for and delete files with the same name yourselffiles.upload() checks for duplicates and replaces them
Handle eLabFTW version differencesWrite separate code per versionHandled by the toolkit (for example, lock and unlock)

For anything the toolkit doesn't cover, use the official client directly through elab.api_client. Mixing the two is fine.

Key eLabFTW terms ​

toolkit function names use eLabFTW terms directly. Knowing how they relate up front makes the rest easier.

How eLabFTW terms relate

TermMeaningWhere to find it in the toolkit
ExperimentA record of one experiment or measurementelab.experiments
Resource (Database item)Things you refer to repeatedly, like samples, instruments, or reagentselab.items
TemplateA starting point for experiments, with body text and metadata fields set up in advancetemplate_name=
Category and statusHow an entry is classified (for example "Measurement") and how far along it is (for example "Planned")categories.id() / statuses.id()
Fields (extra_fields)Values for fixed fields, like sample name or temperature, stored in the metadata.fields
TagA label for searching.tags
LinkA connection between an experiment and a resource.links

Create your first experiment ​

There are five steps.

Five steps

1. Create an API key ​

Sign in to eLabFTW in your browser and create a new key on the API keys page in your user settings. You'll be creating and updating experiments, so choose Read/Write access.

The key is only shown once, so copy it somewhere safe.

Treat your API key like a password

Anyone with your API key can act as you in eLabFTW. Don't paste it into emails, chats, or Git repositories.

2. Install the toolkit ​

bash
python -m pip install elabftw-toolkit

This installs it from PyPI. For MaiML or the MCP server, add extras such as "elabftw-toolkit[maiml,mcp]".

See 1. Getting started for details.

3. Put the URL and API key in .env ​

Create a file named .env in your working folder with these two lines.

bash
ELABFTW_HOST_URL="https://your-elabftw.example.jp"
ELABFTW_API_KEY="your API key"

For ELABFTW_HOST_URL, use the address you open eLabFTW at in your browser (from https:// to the host name).

If you use Git

Add .env to .gitignore so your API key never ends up in the repository.

4. Check the connection ​

python
from dotenv import load_dotenv
import elabftw_toolkit

load_dotenv()

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

Replace "your-team-name" with the name of your team in eLabFTW. If there's no error, you're connected.

If you can't connect
  • Check that the variables are named ELABFTW_HOST_URL / ELABFTW_API_KEY (the older HOST_URL / API_KEY names aren't read)
  • Check that you call load_dotenv() (.env isn't loaded automatically)
  • Check that no spaces were copied before or after the API key
  • Check that the team name exactly matches what eLabFTW shows

5. Create your first experiment ​

python
exp_id = elab.experiments.init(title="My first experiment")
print(exp_id)

The number printed is the ID of the new experiment. Open eLabFTW in your browser and you'll see "My first experiment" in your list of experiments.

Next, attach a file from your computer.

python
elab.experiments.entry(exp_id).files.upload("./data/result.dat")

Finally, search by title to check that you can find it. Results come back as a pandas DataFrame.

python
df = elab.experiments.query.search(title_contains="first")
df
If you want toRead
Use templates and categories in real work4. Creating entries and templates
See common tasks end to end11. Recipes
Decide where to record sample names and conditionsUnderstanding metadata
Write measurement results as a table in the body9. HTML tables and steps
Find past entries by condition3. Listing and search
Prevent a finished entry from being edited8. Lock and timestamp
Exchange sample and measurement records as MaiMLHow MaiML export works

Apache License 2.0