metax-access¶
metax-access is a Python module used to communicate with Metax. It contains many utility functions, which help making HTTP requests to Metax.
Installation¶
If you’re on CentOS, you can install Python interpreter and git by running the following command in terminal:
$ sudo yum install -y python3 git
Clone the metax-access repository to your machine by running:
$ git clone https://github.com/Digital-Preservation-Finland/metax-access.git
Change to the newly created directory and install metax-access by running:
$ cd metax-access
$ make github
$ source venv/bin/activate
make github
runs github target in the Makefile, which installs
metax-access in a virtual environment and creates a default config file
~/.metax.cfg. source venv/bin/activate
activates the newly created
virtual environment. Finally, edit the ~/.metax.cfg file with editor of your
choice, e.g.:
$ vi ~/.metax.cfg
to look like:
[metax]
host=https://metax.fairdata.fi
user=
password=
token=YOUR_PERSONAL_TOKEN
The token can be acquired from https://metax.fairdata.fi/secure.
Usage¶
metax-access has a command-line user interface, which is used with the command
metax_access
. Try:
$ metax_access --help
and:
$ metax_access COMMAND --help
where COMMAND is one of the provided subcommands: post
, get
,
delete
or patch
.
These commands can be used to send POST, GET, DELETE or PATCH requests to
Metax correspondingly. The requests are sent to specific Metax resources, which
are:
file
dataset
contract
For example, a GET request to dataset with identifier DATASET_IDENTIFIER can be sent with command:
$ metax_access get dataset DATASET_IDENTIFIER
Creating and modifying Metax datasets¶
Let’s go through a practical example of:
Fetching a minimal dataset template from Metax.
Modifying the template dataset and POSTing it to Metax.
Editing the dataset with a PATCH request.
Deleting the dataset.
GET the minimal dataset template and save it to dataset_template.json with the command:
$ metax_access -o dataset_template.json get template dataset
Modify the template dataset with the editor of your choice, e.g.:
$ vi dataset_template.json
If you are using the Pre-Ingest File Storage API instead of IDA, you should at
the very least change the data_catalog to:
urn:nbn:fi:att:data-catalog-pas
. Once you have edited the template
dataset, you can POST it to Metax with the command:
$ metax_access post dataset dataset_template.json
Datasets that have been POSTed to Metax can be edited with PATCH requests. Start by writing the dataset into a file:
$ metax_access -o dataset.json get dataset DATASET_IDENTIFIER
Edit the created file dataset.json
to fix the mistakes and send a
PATCH request with the command:
$ metax_access patch dataset DATASET_IDENTIFIER dataset.json
Finally, if you want to remove your datasets from metax, you can send a DELETE request:
$ metax_access delete dataset DATASET_IDENTIFIER