Python Client for European XFEL Metadata Catalogue Web App available at https://in.xfel.eu/metadata
Project description
MyMdC is the Web App design for Data Management at European XFEL.
This library (metadata_client) is a client for the RESTful APIs exposed by the European XFEL Metadata Catalogue Web Application - myMdC (https://in.xfel.eu/metadata).
Repository:
Dependencies:
oauthlib (https://pypi.python.org/pypi/oauthlib)
requests (https://github.com/kennethreitz/requests)
requests-oauthlib (https://github.com/requests/requests-oauthlib)
oauth2_xfel_client (https://git.xfel.eu/gitlab/ITDM/oauth2_xfel_client)
Installation
Python project
Install requirements, if never done before
1.1. For OS X distributions:
1.1.1. Homebrew brew install python3 1.1.2 Port sudo port install python36 sudo port select --set python3 python36 sudo port install py36-pip sudo port select --set pip pip361.2. For Linux distributions:
sudo apt-get update sudo apt-get install python3.6
Make metadata_client library available in your python environment
2.1. Install it via pip:
# Install dependencies from local wheels files pip install . --no-index --find-links ./external_dependencies/ # Install dependencies from the pypi pip install .Installing it will place two folders under the current Python installation site-packages folder:
metadata_client with the sources;
metadata_client-3.2.2.dist-info/ with Wheels configuration files.
To identify your Python site-packages folder run:
python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
Usage
To use this project you need to import it:
from metadata_client import MetadataClient
Connection to the MdC (Metadata Catalog):
from metadata_client import MetadataClient # Necessary configuration variables to establish a connection # Go to https://in.xfel.eu/metadata/oauth/applications to make a token for # the metadata catalogue. user_id = '201ed15ff071a63e76cb0b91a1ab17b36d5f92d24b6df4497aa646e39c46a324' user_secret = 'a8ae80f5e96531f19bf2d2b6102f5a537196aca44a673ad36533310e07529757' user_email = 'luis.maia@xfel.eu' # metadata_web_app_url = 'https://in.xfel.eu/metadata' token_url = 'https://in.xfel.eu/metadata/oauth/token' refresh_url = 'https://in.xfel.eu/metadata/oauth/token' auth_url = 'https://in.xfel.eu/metadata/oauth/authorize' scope = '' base_api_url = 'https://in.xfel.eu/metadata/api/' # Generate the connection client_conn = MetadataClient(client_id=user_id, client_secret=user_secret, user_email=user_email, token_url=token_url, refresh_url=refresh_url, auth_url=auth_url, scope=scope, base_api_url=base_api_url)
Interaction with the MdC (Metadata Catalog):
2.1 Example data_group_types:
all_group_types = client_conn.get_all_data_group_types() all_group_types # >>> {'success': True, # 'data': [{'description': '', 'identifier': 'RAW', 'name': 'Raw', 'flg_available': True, 'id': 1}, # {'description': '', 'identifier': 'CAL', 'name': 'Calibration', 'flg_available': True, 'id': 2}, # {'description': '', 'identifier': 'PROC', 'name': 'Processed', 'flg_available': True, 'id': 3}, # {'description': '', 'identifier': 'REDU', 'name': 'Reduced', 'flg_available': True, 'id': 4}, # {'description': '', 'identifier': 'SIM', 'name': 'Simulation', 'flg_available': True, 'id': 5}, # {'description': '', 'identifier': 'UNK', 'name': 'Unknown', 'flg_available': True, 'id': 6}], # 'app_info': {}, # 'info': 'Got data_group_type successfully'} all_group_types['success'] # >>> True all_group_types['data'][0] # >>> {'description': '', 'identifier': 'RAW', 'name': 'Raw', 'flg_available': True, 'id': 1} all_group_types['data'][0]['name'] # >>> 'Raw'2.2 Example instruments:
all_xfel_instruments = client_conn.get_all_xfel_instruments() >>> for instrument in all_xfel_instruments['data']: ... print('id = {0} | name = {1}'.format(instrument['id'], instrument['name'])) ... # id = -1 | name = test-instrument # id = 1 | name = SPB/SFX SASE1 # id = 2 | name = FXE SASE1 # id = 3 | name = SQS SASE3 # id = 4 | name = SCS SASE3 # id = 5 | name = MID SASE2 # id = 6 | name = HED SASE2 # id = 7 | name = Hera South Detector Test Stand # id = 8 | name = SASE1 Test Stand # id = 9 | name = SASE2 Test Stand # id = 10 | name = SASE3 Test Stand2.3 Get instrument active proposal:
active_proposal = client_conn.get_active_proposal_by_instrument(1)2.4 Register Run replica:
# (e.g. proposal_number == 1234) # (e.g. proposal_number == 12) # (e.g. repository_identifier == 'XFEL_GPFS_OFFLINE_RAW_CC') resp = client_conn.register_run_replica( proposal_number, run_number, repository_identifier ) # resp = {'success': True, # 'info': 'Run replica registered successfully', # 'data': {'experiment_id': '-1', # 'sample_id': '-1', # 'run_id': '1588', # 'data_group_id': '777'}, # 'app_info': {}}2.5 Unregister Run replica:
# (e.g. proposal_number == 1234) # (e.g. proposal_number == 12) # (e.g. repository_identifier == 'XFEL_GPFS_OFFLINE_RAW_CC') resp = client_conn.unregister_run_replica( proposal_number, run_number, repository_identifier ) # resp = {'success': True, # 'info': 'Run replica unregistered successfully', # 'data': {'data_group_id': '-1', # 'repository_id': '1', # 'flg_available': 'false'}, # 'app_info': {}}
For additional examples, please take a look in the tests/ folder.
Development & Testing
When developing, and before commit changes, please validate that:
All tests continue passing successfully (to validate that run pytest):
# Go to the source code directory cd metadata_client # Upgrade package and all its required packages pip install . -U --upgrade-strategy eager # Install test dependencies pip install '.[test]' -U --upgrade-strategy eager # Run all tests using pytest pytest # When running all tests against the standard http application OAUTHLIB_INSECURE_TRANSPORT=1 pytest # Run all tests and get information about coverage for all files inside metadata_client package pytest --cov metadata_client --cov-report term-missing
Code keeps respecting pycodestyle code conventions (to validate that run pycodestyle):
pycodestyle .
To generate all the wheels files for the dependencies, execute:
# Generate Wheels to itself and dependencies pip wheel --wheel-dir=./external_dependencies . pip wheel --wheel-dir=./external_dependencies --find-links=./external_dependencies .
Check that you have the desired dependency versions in external_dependencies folder, since no versions are now set in setup.py.
Registering library on https://pypi.org
To register this python library, the following steps are necessary:
# Install twine python -m pip install --upgrade twine # Generates source distribution (.tar.gz) and wheel (.whl) files in the dist/ folder python setup.py sdist python setup.py bdist_wheel # Upload new version .egg and .whl files twine upload dist/* # In case a test is necessary, it is possible to test it against test.pypi.org twine upload --repository-url https://test.pypi.org/legacy/ dist/* --verbose
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file metadata_client-3.2.2.tar.gz
.
File metadata
- Download URL: metadata_client-3.2.2.tar.gz
- Upload date:
- Size: 60.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.6.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aef8741904254c13317a974e131abaa9d1b93bf4697c9f771520d3fb5743bc94 |
|
MD5 | ff06e0864286eb00309700e350d7dae6 |
|
BLAKE2b-256 | b3954cd31f5fe832e6f0c79257cc39b96a565b61f9273cc33e1a27c1afb8db87 |
File details
Details for the file metadata_client-3.2.2-py3-none-any.whl
.
File metadata
- Download URL: metadata_client-3.2.2-py3-none-any.whl
- Upload date:
- Size: 111.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.6.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc452cb1822ec3b9b2821a603b9fe4b57704d47b4776729f4a2895e6e3f56bd5 |
|
MD5 | 48092e722fb689a1e6c585de5ac019b5 |
|
BLAKE2b-256 | dfa067fb4861e2940503d3384c997a6786289f899ba6e7dce497635e6430736a |