elab_bridge package

Submodules

elab_bridge.cli module

Provide CLI for the main functionalities of the elab bridge

elab_bridge.cli.main(command_line=None)

elab_bridge.project_building module

elab_bridge.project_building.build_project(project_file, output_file=None, include_provenance=True)

Build a complete ElabFTW form from a set of template_parts and a project json file.

Parameters:
  • project_file (str) – Filepath of the project structure json file

  • output_file (str, None) – Filepath of the resulting, complete project json (with inserted template_parts. If None, the content is only returned and not saved. Default: None

  • include_provenance (bool) – If True, include hidden fields in the project json that contain git commits of source files Default: True

Return type:

(dict) json dictionary of the project

elab_bridge.project_building.customize_project(project_built_json, customization_json, output_file=None)

Fill in a built project json with project specific customizations.

This can be used to e.g. change the default values of fields or customize the list of experimenters to be selected

Parameters:
  • project_built_json (str) – The filepath to the json containing the built project (see also build_project)

  • customization_json (str) – The filepath to the json containing the project customizations

  • output_file (str) – The path to save the combined json. Default: None

Returns:

dict json representation of the customized project definition

Return type:

dict

elab_bridge.project_building.extract_customization(project_json, export_custom_json, *template_parts)

Extract custom parts of a project data dict by subtracting template parts

Parameters:
  • project_json (path) – path to the complete project json file

  • export_custom_json (path) – path to store the resulting customization json file

  • *template_parts ((list)) – list of template parts included in the project

elab_bridge.project_control module

elab_bridge.project_control.setup_project(proj_folder, working_dir=None, include_provenance=True)

Build a project json from its specifications and setup on the server

Parameters:
  • proj_folder ((path)) – folder containing the project specification files project.json, structure.json and customizations.json

  • working_dir ((path)) – directory in which to store temporarily generated project files

  • include_provenance ((bool)) – include hidden provenance information in project json. Default: True

elab_bridge.project_validation module

elab_bridge.project_validation.validate_experiment_against_template(experiment_json, template_json)

Validate a Elab experiment against an Elab template

Parameters:
  • experiment_json (path) – path to the record json of that instrument

  • template_json (path) – path to the template json of an instrument

Return type:

True

Raises:

ValueError in case of failing validation

elab_bridge.project_validation.validate_project_against_template_parts(project, *templates)

Validate a built project json

Parameters:
  • project (str, buffer) – Filepath of the json file or json buffer of the built project

  • templates (str, list) – List of file paths of the template part jsons.

Returns:

True if the validation was successful

Return type:

bool

elab_bridge.server_interface module

elab_bridge.server_interface.delete_experiment(experiment_id, server_config_json)

Delete an existing experiment.

Parameters:
  • experiment_id (int) – ID of the experiment you want to delete

  • server_config_json (str) – Path to the json file containing the api_url and the api_token

elab_bridge.server_interface.delete_template(template_id, server_config_json)

Delete an existing template.

Parameters:
  • template_id (int) – ID of the experiment you want to delete

  • server_config_json (str) – Path to the json file containing the api_url and the api_token

elab_bridge.server_interface.extended_download(save_to, server_config_json, experiment_tags=None, format='csv', experiment_axis='columns')

Download experiments based on tags or a specific experiment by ID.

Parameters:
  • save_to (str) – Path where to save the retrieved experiment data

  • server_config_json (str) – Path to the json file containing the api_url and the api_token

  • experiment_tags (list, optional) – List of tags of your experiments. Default is None.

  • experiment_id (int, optional) – ID of the experiment you want to download. Default is None.

  • format (str) – Format of the retrieved records. Options are ‘csv’ or ‘json’. Default: ‘csv’

  • experiment_axis (str) – Option to control whether in the csv format experiments are arranged in columns or rows. Default: ‘columns’

Returns:

List of the experiment(s) downloaded

Return type:

list

elab_bridge.server_interface.get_elab_config(server_config_json)

Initialize an elab project based on the provided server configuration :param server_config_json: json file containing the api_token and api_url :return: elab api client

elab_bridge.server_interface.upload_experiment(experiment_file, server_config_json, experiment_title)

Upload an experiment.

Parameters:
  • experiment_file (str) – Path to the experiment you want to upload. This has to be a json file containing the keys elabftw’ and `extra_fields.

  • server_config_json (str) – Path to the json file containing the api_url and the api_token

  • experiment_title (str) – The title of the experiment you want to upload

Returns:

  • (dict) Content of the experiment as registered on the server

  • (int) ID of the experiment

elab_bridge.server_interface.upload_template(template_file, server_config_json, template_title)

Upload a template with metadata.

Parameters:
  • template_file (str) – Path to the template you want to upload. This has to be a json file containing the keys elabftw’ and `extra_fields.

  • server_config_json (str) – Path to the json file containing the api_url and the api_token

  • template_title (str) – The title of the template you want to upload

Returns:

  • (dict) Content of the template as registered on the server

  • (int) ID of the template