From your Python code
madbot-cli is also a Python library, madbot_cli. A platform whose tool already knows what it produced (a LIMS, a pipeline runner) can call it from its code, without writing a deposit file. This block makes the same deposit with an example script: one function per step, that you can copy into your tool.
The script reads the same Zenodo record, creates one sample per station from a table, as a LIMS would export it, then deposits on the Recherche Data Gouv demo.
-
Get the script and its table, in a new working folder:
Fenêtre de terminal mkdir integration && cd integrationcurl -O https://gitlab.com/ifb-elixirfr/madbot/madbot/-/raw/dev/cli/examples/integration/integrate.pycurl -O https://gitlab.com/ifb-elixirfr/madbot/madbot/-/raw/dev/cli/examples/integration/samples.csvsamples.csvstands for an export of your tool: one row per station, with its name, its title, the file to bind it to (mesures.csv) and its coordinates. -
Read the top of the script. The
PARAMSdictionary says everything the script does: the workspace and the node, the source and its files, the table of the samples, the repository, its settings and the metadata. Change three things:"workspace": set"madbot CLI workshop", your workspace of the workshop. The script finds there the connection to Zenodo thatbrowse --connectcreated;- the
"title"of the node and the"title"of the submission: set"Stream water quality, from Python"for both. The script finds a node and a submission by their title: with the title of the example, “Stream water quality”, it would take up the node and the deposit you made withapply; - the contact, under
recherche_data_gouv__general__contact: your name, your institution and your e-mail address.
-
Prepare the submission, without sending it. The top of the script declares what it needs: Python 3.10 or later and madbot-cli.
uv runreads it, takes a suitable Python, fetching one when needed, and installs madbot-cli in an environment of its own, leaving the rest alone:Fenêtre de terminal uv run integrate.pyMADBOT_API,MADBOT_TOKENandRECHERCHE_DATA_GOUV_CREDENTIALSmust be set in this terminal, as in the previous blocks. The script tells each step:node 'Stream water quality, from Python'linked 3 new filescreated sample st1bound sample st1 to mesures.csvcreated sample st2bound sample st2 to mesures.csvcreated sample st3bound sample st3 to mesures.csvsubmission 'Stream water quality, from Python': ready -
Send, by running it again with
--submit:Fenêtre de terminal uv run integrate.py --submitThe steps already done say nothing any more. The script sends the submission, waits for the answer of the repository and prints its DOI:
node 'Stream water quality, from Python'linked 0 new filessubmission 'Stream water quality, from Python': readyDOI: doi:10.82233/… -
Run it a last time, with
--submit. Nothing is created, and the submission already deposited is not sent again: the script gives its state,submitted, and its DOI again.
Optional What the script does
main, at the bottom of the script, chains one function per step:
| Function | What it does | What it calls in madbot_cli |
|---|---|---|
connect_to_madbot |
reads the address and the token, checks the version of madbot | Client.from_env, check_version |
ensure_node |
finds or creates the workspace, then the node | find_workspace, create_workspace, find_node, create_node |
link_files |
opens the Zenodo record, links the three files, waits until they are read | connect, browse_path, link_data, wait_for_data |
ensure_samples |
creates the samples of the table that are missing, binds them to their files | list_samples, create_sample, bind_sample |
ensure_submission |
finds or creates the submission, adds the files to it | find_submission, create_submission, add_submission_data |
fill_metadata |
writes the values, then has the submission checked | set_metadata, generate_metadata |
submit |
sends a ready submission, once | missing_metadata, submit |
With the deposit file, plan and apply make these comparisons for you. Without a file, the code does: each function looks for what it needs before creating it. This is what lets you run the script again after each production. The page Integrate madbot in your Python code of the documentation details each function.
Checkpoint
Section titled “Checkpoint”If you are stuck
Section titled “If you are stuck”ModuleNotFoundError: No module named 'madbot_cli': the script was run withpython integrate.py. That Python does not have madbot-cli: run it withuv run integrate.py, as in step 3.- “Give the address of the madbot API in the MADBOT_API environment variable” or “Give the credentials in the RECHERCHE_DATA_GOUV_CREDENTIALS environment variable”: the variable is not set in this terminal. Run the
exportof the block where you set it again. - “The submission is draft, not ready. Mandatory values missing: …”: a mandatory value is missing, and its slug is given. Add it in
PARAMS, undermetadata, then run again.madbot-cli field <slug>tells what it accepts. - “No ‘…’ there”: a file name of
namesmatches no file of the Zenodo record. Names are written exactly asmadbot-cli browsegives them. - “… is not linked to the node”: the
filescolumn of the table names a file thatnamesdoes not link. Add it tonames, or fix the table.

