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.
- 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.
| Task | Official client only | toolkit |
|---|---|---|
| Set a category or status | Look up the numeric ID | Use the name, like categories.id("Measurement") |
| Get the ID of a new entry | Parse it from the response headers | Returned directly by init() |
| Fill in field values | Read the whole metadata JSON and rebuild it | Write only the fields you need with fields.update({"name": value}) |
| Attach a file | Check for and delete files with the same name yourself | files.upload() checks for duplicates and replaces them |
| Handle eLabFTW version differences | Write separate code per version | Handled 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.
| Term | Meaning | Where to find it in the toolkit |
|---|---|---|
| Experiment | A record of one experiment or measurement | elab.experiments |
| Resource (Database item) | Things you refer to repeatedly, like samples, instruments, or reagents | elab.items |
| Template | A starting point for experiments, with body text and metadata fields set up in advance | template_name= |
| Category and status | How 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 |
| Tag | A label for searching | .tags |
| Link | A connection between an experiment and a resource | .links |
Create your first experiment
There are 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
python -m pip install elabftw-toolkitThis 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.
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
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 olderHOST_URL/API_KEYnames aren't read) - Check that you call
load_dotenv()(.envisn'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
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.
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.
df = elab.experiments.query.search(title_contains="first")
dfWhat to read next
| If you want to | Read |
|---|---|
| Use templates and categories in real work | 4. Creating entries and templates |
| See common tasks end to end | 11. Recipes |
| Decide where to record sample names and conditions | Understanding metadata |
| Write measurement results as a table in the body | 9. HTML tables and steps |
| Find past entries by condition | 3. Listing and search |
| Prevent a finished entry from being edited | 8. Lock and timestamp |
| Exchange sample and measurement records as MaiML | How MaiML export works |