Skip to content

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.

  1. Get the script and its table, in a new working folder:

    Fenêtre de terminal
    mkdir integration && cd integration
    curl -O https://gitlab.com/ifb-elixirfr/madbot/madbot/-/raw/dev/cli/examples/integration/integrate.py
    curl -O https://gitlab.com/ifb-elixirfr/madbot/madbot/-/raw/dev/cli/examples/integration/samples.csv

    samples.csv stands 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.

  2. Read the top of the script. The PARAMS dictionary 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 that browse --connect created;
    • 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 with apply;
    • the contact, under recherche_data_gouv__general__contact: your name, your institution and your e-mail address.
  3. Prepare the submission, without sending it. The top of the script declares what it needs: Python 3.10 or later and madbot-cli. uv run reads 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.py

    MADBOT_API, MADBOT_TOKEN and RECHERCHE_DATA_GOUV_CREDENTIALS must be set in this terminal, as in the previous blocks. The script tells each step:

    node 'Stream water quality, from Python'
    linked 3 new files
    created sample st1
    bound sample st1 to mesures.csv
    created sample st2
    bound sample st2 to mesures.csv
    created sample st3
    bound sample st3 to mesures.csv
    submission 'Stream water quality, from Python': ready
  4. Send, by running it again with --submit:

    Fenêtre de terminal
    uv run integrate.py --submit

    The 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 files
    submission 'Stream water quality, from Python': ready
    DOI: doi:10.82233/…
  5. 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.

  • ModuleNotFoundError: No module named 'madbot_cli': the script was run with python integrate.py. That Python does not have madbot-cli: run it with uv 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 export of 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, under metadata, then run again. madbot-cli field <slug> tells what it accepts.
  • “No ‘…’ there”: a file name of names matches no file of the Zenodo record. Names are written exactly as madbot-cli browse gives them.
  • “… is not linked to the node”: the files column of the table names a file that names does not link. Add it to names, or fix the table.