12 rundb - Helper classes for retrieving information from the RunDB
13 ----------------------------------------------------------------
15 This modules contains classes useful to deal with the RunDB:
17 * `RunDB`, a simple API class to just get run information from the RunDB
26 Simple API class to just get run information from the RunDB.
29 apikey (str): RunDB API key (see
30 `this question <https://questions.belle2.org/question/11145/obtaining-an-access-token-for-rundb-api-2021-version/>`_
31 or `this Confluence page <https://confluence.desy.de/x/DZ8CCg>`_ how to get one)
32 username (str): DESY username
36 URL =
"https://rundb.belle2.org"
38 def __init__(self, apikey=None, username=None):
39 """Create an object and setup authentication."""
45 username = getpass.getuser()
47 self.
_session_session.auth = (username, getpass.getpass(f
"DESY password ({username}): "))
50 self.
_session_session.headers.update({
'Authorization': f
'Bearer {apikey}'})
52 self.
_session_session.headers.update({
'Content-Type':
'application/json'})
55 """Deal with API pagination of an initial request to the API.
57 It will return all the objects from all pages lazily requesting new pages
58 as objects are consumed. Will work for all list requests to the server.
62 request.raise_for_status()
64 result = request.json()
67 yield from result[
'results']
69 if result[
'next']
is None:
73 request = self.
_session_session.get(result[
'next'])
76 """Return the run information from the run registry.
78 All arguments are forwarded to the run registry ``/run/`` method
79 documented at the following `link <https://rundb.belle2.org/rest/v1/swagger/>`_.
80 Please check there for up to date documentation, at the time of
81 this writing the supported arguments are:
83 * min_experiment (int)
85 * max_experiment (int)
87 * min_date (iso8601 date string, e.g. 2020-05-06)
88 * max_date (iso8601 date string, e.g. 2020-05-06)
89 * all_detectors_running (bool)
90 * expand (bool): If true return full run objects, not just a summary
91 links to the run objects
93 If ``expand=False`` you can request the full objects for each run by calling
94 `get_details` with the returned run summary object as argument.
95 ``expand=False`` is much faster if no further details are needed but
96 getting the details in a separate step for many many runs will be slow
97 so depending on how many runs are selected one or the other may be
100 req = self.
_session_session.get(f
'{self.URL}/rest/v1/runs/', params=search_params)
105 Return details for a run summary object returned from `get_run_info`
106 if ``expand`` was not set to True
109 run_summary: a run summary object returned from `get_run_info`
112 req = self.
_session_session.get(run_summary[
'url'])
114 req.raise_for_status()
def get_details(self, run_summary)
def get_run_info(self, **search_params)
def _pagination(self, request)
_session
session object for connection to the RunDB
def __init__(self, apikey=None, username=None)