欧洲XFEL校准常数数据管理Web应用(calCat)的Python客户端,可在https://in.xfel.eu/calibration找到。
项目描述
Calcat是为欧洲XFEL校准常数数据管理设计的Web应用。
这个库(calibration_client)是欧洲XFEL校准常数目录Web应用calCat(https://in.xfel.eu/calibration)公开的RESTful API的客户端。
仓库
依赖关系
oauthlib (https://pypi.python.org/pypi/oauthlib)
requests (https://github.com/psf/requests)
requests-oauthlib (https://github.com/requests/requests-oauthlib)
oauth2_xfel_client (https://git.xfel.eu/ITDM/oauth2_xfel_client)
安装
Python项目
如果之前没有安装,请安装依赖项
1.1. 对于OS X发行版
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. 对于Linux发行版
sudo apt-get update sudo apt-get install python3.9
在Python环境中使calibration_client库可用
2.1. 使用pip安装它
# Install dependencies from local wheels files pip install . --no-index --find-links ./external_dependencies/ # Install dependencies from the pypi pip install . # Force re-installation of packages pip install . --ignore-installed安装它将在当前Python安装的site-packages文件夹下放置两个文件夹
calibration_client包含源代码;
calibration_client-11.4.0.dist-info包含Wheels配置文件。
要确定Python site-packages文件夹,请运行
python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
用法
要使用此项目,您需要导入它
from calibration_client import CalibrationClient
与MdC(元数据目录)的连接
from calibration_client import CalibrationClient # Necessary configuration variables to establish a connection # Go to https://in.xfel.eu/calibration/oauth/applications to make a token for # the calibration catalogue. user_id = 'PUT_HERE_YOUR_CLIENT_KEY' user_secret = 'PUT_HERE_YOUR_SECRET_KEY' user_email = 'luis.maia@xfel.eu' # metadata_web_app_url = 'https://in.xfel.eu/calibration' token_url = 'https://in.xfel.eu/calibration/oauth/token' refresh_url = 'https://in.xfel.eu/calibration/oauth/token' auth_url = 'https://in.xfel.eu/calibration/oauth/authorize' scope = '' base_api_url = 'https://in.xfel.eu/calibration/api/' # Authentication via OAUTH2 # Generate the connection (example with minimum parameter options) client_conn = CalibrationClient(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) # Authentication via OAUTH2 # Generate the connection (example with all parameter options) client_conn = CalibrationClient(use_oauth2=True 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, session_token=None, max_retries=3, timeout=12, ssl_verify=True) # Authentication via Proxy Service # Generate the connection (example with minimum parameter options) client_conn = CalibrationClient(use_oauth2=False, base_api_url="http://HOSTNAME:PORT/api/")
与CalCat(校准目录)的交互
2.1 示例数据_group_types
params_h = { 'detector_identifier': 'TEST_DET_CI-2', 'snapshot_at': '' } resp = client_conn.get_all_phy_det_units_from_detector(params_h) resp # >>> {'success': True, # 'data': [ { "id":-1, # "physical_name":"PHYSICAL_DETECTOR_UNIT-1_DO_NOT_DELETE", # "karabo_da":"TEST_DAQ_DA_01", # "virtual_device_name":"Q1M1", # "uuid":1000, # "float_uuid":4.94e-321, # "detector_type_id":-1, # "detector_id":-2, # "flg_available":true, # "description":"None", # "detector":{ # "id":-2, # "name":"DET_TEST-2_DO_NOT_DELETE", # "identifier":"TEST_DET_CI-2", # "karabo_name":"TEST_DET_CI_-2", # "karabo_id_control":"TEST_DET_CI-2_CTRL00", # "flg_available":true, # "description":"None" # }, # "detector_type":{ # "id":-1, # "name":"UNIT_TEST_DETECTOR_TYPE-1_DO_NOT_DELETE", # "flg_available":true, # "description":"None" # } # }, # { ... }, # { ... } ], # 'app_info': {}, # 'info': 'Got physical_detector_unit successfully'} resp['success'] # >>> True resp['data'][0]['karabo_da'] # >>> 'TEST_DAQ_DA_01'
对于更多示例,请查看tests/文件夹。
开发与测试
在开发过程中,并在提交更改之前,请验证以下内容
所有测试继续成功通过(要验证,请运行pytest)
# Go to the source code directory cd calibration_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 calibration_client package pytest --cov calibration_client --cov-report term-missing
代码继续遵守pycodestyle代码约定(要验证,请运行pycodestyle)
pycodestyle . pycodestyle . --exclude venv
要为依赖项生成所有wheel文件,请执行
# Generate Wheels to itself and dependencies pip wheel --wheel-dir=./external_dependencies . pip wheel --wheel-dir=./external_dependencies --find-links=./external_dependencies .
请确保在external_dependencies文件夹中有所需的依赖项版本,因为现在在setup.py中没有设置版本。
在https://pypi.ac.cn上注册库
要注册此Python库,需要以下步骤
# 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
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。