Skip to main content

A CLI app to interact with BIG-MAP Archive data repositories

Project description

big-map-archive-api-client

This is a command line client to interact with BIG-MAP Archive data repositories.

Table of contents

Quick start

Installation

big-map-archive-api-client is a Python package hosted on PyPI.

We recommend that you proceed as follows to install the Python package and its dependencies on a Linux machine:

  1. Create a virtual environment
python -m venv /home/<username>/.virtualenvs/<virtual_env_name>
  1. Activate the virtual environment
source /home/<username>/.virtualenvs/<virtual_env_name>/bin/activate
  1. Install the wheel package if needed (see here)
pip install wheel
  1. Install the big-map-archive-api-client package along with its dependencies in the virtual environment. Install version 1.2.0 for the latest version of the BIG-MAP Archive:
pip install big-map-archive-api-client==1.2.0
  1. [Optional] Once installed, check that the executable file associated with bma is indeed located in the virtual environment:
which bma
  1. [Optional] Create a project directory (to store configuration, input, and output files).

Configuration files

Each command requires a YAML configuration file that specifies the domain name and an API token for the targeted data repository. This is indicated by the command options --config-file and --bma-config-file. We also recommend to place such a file in your project directory and to name it bma_config.yaml. Its content should be similar to:

domain_name: "big-map-archive-demo.materialscloud.org" # Options: archive.big-map.eu, big-map-archive-demo.materialscloud.org, big-map-archive-demo-public.materialscloud.org
token: "123456789"

Note that to get an API token for the targeted BIG-MAP Archive, you need an account on the data repository. To request an account, email us at big-map-archive@materialscloud.org. Once logged in, navigate to https://<archive_domain_name>/account/settings/applications and create a token.

The command bma finales-db back-up requires another YAML configuration file that specifies the IP address and the port for the targeted FINALES server, and credentials for a user account on the server. This corresponds to the command option --finales-config-file. We recommend to place such a file in your project directory and to name it finales_config.yaml. Its content should be similar to:

ip_address: "0.0.0.0" # Replace by IP address for a FINALES server
port: "1234" # Replace by port for a FINALES server
username: "test" # Replace by valid username
password: "test" # Replace by valid password

Metadata files

Several commands (e.g., bma record create) use a YAML file specified by the command option --metadata-file to create/update a record's metadata. We recommend to place such a file in your project directory and to name it metadata.yaml. Its content should be similar to:

resource_type: "Dataset" # Choose one of these options: Dataset, Software, Other
title: "Mobilities in Two-Dimensional Materials" # Record's title
authors: # Record's list of authors with their affiliations
  - family_name: "Doe"
    given_name: "Jane"
    affiliations:
      - "Physics Institute, École Polytechnique Fédérale de Lausanne, CH-1015 Lausanne, Switzerland"
  - family_name: "Dell"
    given_name: "John"
    affiliations:
      - "Department of Physics, Technical University of Denmark (DTU), 2800 Kongens Lyngby, Denmark"
      - "Physics Institute, École Polytechnique Fédérale de Lausanne, CH-1015 Lausanne, Switzerland"
description: "Two-dimensional materials are emerging as a promising platform for ultrathin channels..." # Abstract-like description of the record
license: "BIG-MAP Archive License" # Choose one of these options: BIG-MAP Archive License, Creative Commons Attribution Share Alike 4.0 International, MIT License
keywords: # Any keyword is accepted
  - "2D materials"
  - "transport"
references: # Choose among these options for the reference scheme: arxiv, doi, isbn, url
  - scheme: "arxiv"
    identifier: "2308.08462"
  - scheme: "doi"
    identifier: "10.1093/ajae/aaq063"
  - scheme: "isbn"
    identifier: "978-3-16-148410-0"
  - scheme: "url"
    identifier: "https://arxiv.org/abs/2308.08462"

Data files

Two commands offer the possibility to attach data files of your choosing to your records: bma record create and bma record update.

Please comply with the following rules:

  • a maximum of 100 files per record and
  • a total file size smaller than 100 GB per record.

The command option --data-files should point to the directory where the files to be uploaded and attached to the new record are located. We usually place such a folder in our project directory and name it upload.

Community

To publish a record to a community you need to specify the community slug. Login at https://<archive_domain_name>. The list of communities you have access to is at the link https://<archive_domain_name>/api/communities. Look for the value slug, you will need to add this value when publishing a record to the community. Example: for the BIG-MAP community the slug is bigmap, for BATTERY2030 the slug is battery2030.

Usage

You may want to test a command against a demo instance, before executing it against the main data repository.

Overview

bma --help
Usage: bma [OPTIONS] COMMAND [ARGS]...

  Command line client to interact with a BIG-MAP Archive.

Options:
  --help  Show this message and exit.

Commands:
  finales-db  Copy data from the database of a FINALES server to a...
  record      Manage records on a BIG-MAP Archive.
bma record --help
Usage: bma record [OPTIONS] COMMAND [ARGS]...

  Manage records on a BIG-MAP Archive.

Options:
  --help  Show this message and exit.

Commands:
  create   Create a record on a BIG-MAP Archive and optionally publish it.
  get      Get the metadata of a published version of an entry on a...
  get-all  Get the metadata of the latest published version for each...
  update   Update a published version of an archive entry, or create a...
bma finales-db --help
Usage: bma finales-db [OPTIONS] COMMAND [ARGS]...

  Copy data from the database of a FINALES server to a BIG-MAP Archive.

Options:
  --help  Show this message and exit.

Commands:
  back-up  Perform a partial back-up from the database of a FINALES...

Get records

bma record get --help
Usage: bma record get [OPTIONS]

  Get the metadata of a published version of an entry on a BIG-MAP Archive and
  save it to a file.

Options:
  --config-file FILE  Path to the YAML file that specifies the domain name and
                      a personal access token for the targeted BIG-MAP
                      Archive. See bma_config.yaml in the GitHub repository.
                      [required]
  --record-id TEXT    Id of the published version of an archive entry (e.g.,
                      "pxrf9-zfh45").  [required]
  --output-file FILE  Path to the JSON file where the obtained record's
                      metadata will be exported to.  [required]
  --help              Show this message and exit.
bma record get-all --help
Usage: bma record get-all [OPTIONS]

  Get the metadata of the latest published version for each entry on a BIG-MAP
  Archive and save them to a file.

Options:
  --config-file FILE  Path to the YAML file that specifies the domain name and
                      a personal access token for the targeted BIG-MAP
                      Archive. See bma_config.yaml in the GitHub repository.
                      [required]
  --all-versions      Get all published versions for each entry. By default,
                      only the latest published version for each entry is
                      retrieved.
  --output-file FILE  Path to the JSON file where the obtained record's
                      metadata will be exported to.  [required]
  --help              Show this message and exit.

Create records

bma record create --help
Usage: bma record create [OPTIONS]

  Create a record on a BIG-MAP Archive and optionally publish it.

Options:
  --config-file FILE      Path to the YAML file that specifies the domain name
                          and a personal access token for the targeted BIG-MAP
                          Archive. See bma_config.yaml in the GitHub
                          repository.  [required]
  --metadata-file FILE    Path to the YAML file for the record's metadata
                          (title, list of authors, etc). See
                          data/input/example/create_record/metadata.yaml in
                          the GitHub repository.  [required]
  --data-files DIRECTORY  Path to the directory that contains the data files
                          to be uploaded and linked to the record. See
                          data/input/example/create_record/upload in the
                          GitHub repository.  [required]
  --slug TEXT             Community slug of the record. Example: for the BIG-
                          MAP community the slug is bigmap.  [required]
  --publish               Publish the created record.
  --help                  Show this message and exit.

Update records

bma record update --help
Usage: bma record update [OPTIONS]

  Update a published version of an archive entry, or create a new version and
  optionally publish it. When updating a published version, only the metadata
  (title, list of authors, etc) can be modified.

Options:
  --config-file FILE              Path to the YAML file that specifies the
                                  domain name and a personal access token for
                                  the targeted BIG-MAP Archive. See
                                  bma_config.yaml in the GitHub repository.
                                  [required]
  --record-id TEXT                Id of the published version (e.g.,
                                  "pxrf9-zfh45").  [required]
  --update-only                   Update the metadata of the published
                                  version, without creating a new version. By
                                  default, a new version is created.
  --metadata-file FILE            Path to the YAML file that contains the
                                  metadata (title, list of authors, etc) for
                                  updating the published version or creating a
                                  new version. See data/input/example/update_r
                                  ecord/metadata.yaml in the GitHub
                                  repository.  [required]
  --data-files DIRECTORY          Path to the directory that contains the data
                                  files to be linked to the newly created
                                  version. See
                                  data/input/example/update_record/upload in
                                  the GitHub repository.  [required]
  --link-all-files-from-previous  Link all files that are already linked to
                                  the previous version to the new version,
                                  with the exception of files whose content
                                  changed.
  --publish                       Publish the newly created version.
  --help                          Show this message and exit.

Back up FINALES databases

bma finales-db back-up --help
Usage: bma finales-db back-up [OPTIONS]

  Back up the SQLite database of a FINALES server to a BIG-MAP Archive. This creates and publishes a new entry version, which provides links to data extracted from the database (capabilities, requests, and results for requests) and a copy of the whole database.
Options:
  --bma-config-file FILE          Path to the YAML file that specifies the
                                  domain name and a personal access token for
                                  the targeted BIG-MAP Archive. See
                                  bma_config.yaml in the GitHub repository.
                                  [required]
  --finales-config-file FILE      Path to the YAML file that specifies the IP
                                  address, the port, and the credentials of a
                                  user account for the targeted FINALES
                                  server. See finales_config.yaml in the
                                  GitHub repository.  [required]
  --record-id TEXT                Id of the published version for the previous
                                  back-up (e.g., "pxrf9-zfh45"). For the first
                                  back-up, leave to the default.
  --metadata-file FILE            Path to the YAML file that contains the
                                  metadata (title, list of authors, etc) for
                                  creating a new version. See data/input/examp
                                  le/create_record/metadata.yaml in the GitHub
                                  repository.  [required]
  --link-all-files-from-previous  Link all files that are already linked to
                                  the previous version to the new version,
                                  with the exception of files whose content
                                  changed.
  --no-publish                    Do not publish the newly created version.
                                  This is discouraged in production. If you
                                  select this option, either publish or delete
                                  the newly created draft, e.g., via the GUI.
  --slug TEXT                     Community slug of the record. Example: for
                                  the BIG-MAP community the slug is bigmap.
                                  [required]
  --help                          Show this message and exit.

While executing the command, a user will be asked for confirmation if:

  • The user attempts to create an entry (i.e., no record id is provided) but he/she already owns a published record with the same title. This is to prevent users from creating new entries inadvertently.
  • The user tries to update an existing entry (a record id is provided) but the new version would have a different title. This is to enforce our 'one title per "campaign"' policy (see Back-up policy for FINALES databases)

When backing up a production database, put the corresponding metadata.yaml file under version control in the big-map-archive-api-client-finales GitHub repository.

Back-up policy for FINALES databases

The following back-up policy applies to the database of FINALES servers in production:

  • There should be a single entry in the main BIG-MAP Archive per "campaign" on the FINALES server.
  • An entry may have multiple versions, with one version created and published each time a back-up of the database occurs. Note that if a data file remains unchanged from one version to the next, the file is uploaded only once. However, the corresponding file link appears in the two entry versions. This saves storage space and reduces back-up time.
  • A title is given to each version of an entry. It can be changed but, since it serves as an identifier of the campaign, should ideally remain unchanged across all versions of the same entry. To enforce this 'one title per "campaign"' policy, the command bma finales-db back-up asks for confirmation if the user attempts to change the title while creating a new version.
  • A single service account is used for doing back-ups of a given "campaign".
  • The same service account can be used for multiple "campaigns".

Support

If you have any comments or questions, email us at big-map-archive@materialscloud.org.

Issue

If you find a bug, please create an issue directly into GitHub. If possible, give enough details so that the BIG-MAP Archive team is able to reproduce the encountered problem. Thank you!

Acknowledgements

This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 957189. The project is part of BATTERY 2030+, the large-scale European research initiative for inventing the sustainable batteries of the future.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

big-map-archive-api-client-1.2.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

big_map_archive_api_client-1.2.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file big-map-archive-api-client-1.2.0.tar.gz.

File metadata

File hashes

Hashes for big-map-archive-api-client-1.2.0.tar.gz
Algorithm Hash digest
SHA256 c1e52f5f2d85f47d4fe7d37438faf0301534b76bfeb7d24d03dc98a354a807ff
MD5 b0031bd09b6376b9b7c28d331b3663c1
BLAKE2b-256 30d680453bbdaab184fd60dd1aa1829fe57995f766da6865b3f4f384c87ae472

See more details on using hashes here.

File details

Details for the file big_map_archive_api_client-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for big_map_archive_api_client-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb367a6e17c20594c477206e147958db5377b768650a8746f42ea72641000ea9
MD5 eec2e680cdb84a9b18dc331870ae11da
BLAKE2b-256 bdab7146993eeb441e0567c69f0be82b1d782e8babf5837356dfef3ac39aa1a5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page