Code Reference#
studygovernor
Package#
- studygovernor.convert_to_bool(value)#
- Return type:
Union
[str
,bool
]
- studygovernor.create_app(test_config=None, use_sentry=True)#
- studygovernor.load_app_config(app, test_config)#
- studygovernor.load_config_from_env()#
- studygovernor.set_config_defaults(config)#
- studygovernor.set_default_config_value(config, key, value, warning=None)#
- studygovernor.uia_username_mapper(identity)#
- Return type:
str
studygovernor.callbacks
Module#
- studygovernor.callbacks.clean_config(config)#
Clean a config so that it is guaranteed to be serializable
- Return type:
Dict
[str
,Union
[bool
,float
,int
,str
,None
,List
[Union
[bool
,float
,int
,str
,None
]],Dict
[str
,Union
[bool
,float
,int
,str
,None
]]]]
- studygovernor.callbacks.clean_value(value)#
- Return type:
Union
[bool
,float
,int
,str
,None
]
- studygovernor.callbacks.dispatch_callback(callback_execution, config)#
Dispatch the callback to the appropriate backend.
- studygovernor.callbacks.master_callback(*, callback_function, callback_arguments, callback_execution_url, callback_execution_secret, config)#
- studygovernor.callbacks.replace_mapping(string, mapping)#
Performs multiple substitutions in a string, will use each key-value pair a replacements.
- Parameters:
string (
str
) – String to perform substitutions onmapping (
Mapping
[str
,str
]) – The mapping containing all replacements pairs
- Returns:
Updated string after replacements
- studygovernor.callbacks.update_callback_execution(url, secret, data)#
studygovernor.exceptions
Module#
- exception studygovernor.exceptions.ConditionFunctionCallFailedError(condition, stacktrace)#
Bases:
StateChangeError
- exception studygovernor.exceptions.ConditionFunctionReturnValueError(condition, function, args, kwargs, return_value)#
- exception studygovernor.exceptions.ConditionNotMetError(experiment, transition, condition)#
Bases:
StateChangeError
- exception studygovernor.exceptions.CouldNotFindResourceError(id_, type_, message=None)#
Bases:
StudyGovernorHTTPError
Could not find a resource
- code: t.Optional[int] = 404#
- exception studygovernor.exceptions.NoValidTransitionError(sourcestate, targetstate)#
Bases:
StateChangeError
- exception studygovernor.exceptions.RESTResponseError#
Bases:
StudyGovernorClientError
The REST response is not what was expected
- exception studygovernor.exceptions.StateChangeError#
Bases:
StudyGovernorError
Exceptions encountered during a state change
- exception studygovernor.exceptions.StateNotFoundError(requested_state)#
Bases:
StateChangeError
- exception studygovernor.exceptions.StudyGovernorClientError#
Bases:
StudyGovernorError
Error class for all client-side errors
- exception studygovernor.exceptions.StudyGovernorError#
Bases:
Exception
Base class for exceptions in the study governor codebase
- property fields#
- marshal(api_prefix)#
- exception studygovernor.exceptions.StudyGovernorHTTPError(description, response=None)#
Bases:
StudyGovernorError
,HTTPException
All exceptions that should lead to an HTTP error response
- code: t.Optional[int] = 500#
- property description#
- exception studygovernor.exceptions.StudyGovernorSSLError#
Bases:
StudyGovernorClientError
There was a problem creating an SSL connection
- exception studygovernor.exceptions.UnknownConditionFunction(condition, module, function)#
Bases:
StateChangeError
studygovernor.fields
Module#
- class studygovernor.fields.MappingField(**kwargs)#
Bases:
Raw
- format(value)#
Formats a field’s value. No-op by default - field classes that modify how the value of existing object keys should be presented should override this and apply the appropriate formatting.
- Parameters:
value – The value to format
- Raises:
MarshallingError – In case of formatting problem
Ex:
class TitleCase(Raw): def format(self, value): return unicode(value).title()
- class studygovernor.fields.ObjectUrl(object_class, api_prefix=None, **kwargs)#
Bases:
Raw
- format(value)#
Formats a field’s value. No-op by default - field classes that modify how the value of existing object keys should be presented should override this and apply the appropriate formatting.
- Parameters:
value – The value to format
- Raises:
MarshallingError – In case of formatting problem
Ex:
class TitleCase(Raw): def format(self, value): return unicode(value).title()
- class studygovernor.fields.OptionalDatetime(dt_format='iso8601', **kwargs)#
Bases:
DateTime
- format(value)#
Formats a field’s value. No-op by default - field classes that modify how the value of existing object keys should be presented should override this and apply the appropriate formatting.
- Parameters:
value – The value to format
- Raises:
MarshallingError – In case of formatting problem
Ex:
class TitleCase(Raw): def format(self, value): return unicode(value).title()
- class studygovernor.fields.SubUrl(object_class, subfield, **kwargs)#
Bases:
Raw
- format(value)#
Formats a field’s value. No-op by default - field classes that modify how the value of existing object keys should be presented should override this and apply the appropriate formatting.
- Parameters:
value – The value to format
- Raises:
MarshallingError – In case of formatting problem
Ex:
class TitleCase(Raw): def format(self, value): return unicode(value).title()
studygovernor.util.filters
Module#
- studygovernor.util.filters.hyphenate_filter(s)#
Filter for lowercasing and hyphenating a string.
- studygovernor.util.filters.json_format_filter(s)#
Filter for pretty formatting json’s.
- studygovernor.util.filters.python_code_filter(s)#
- studygovernor.util.filters.register_filters(app)#
Special function that registers all member of this module ending in “_filter”.
- studygovernor.util.filters.yaml_dump_filter(s)#
Filter for pretty formatting json’s.
studygovernor.util.helpers
Module#
- studygovernor.util.helpers.create_workflow(workflow_definition, verbose=False)#
- studygovernor.util.helpers.get_object_from_arg(id, model, model_name=None, skip_id=False, allow_none=False, filters=None)#
- Return type:
TypeVar
(T
)
- studygovernor.util.helpers.get_uri(route, id, blueprint=None)#
- studygovernor.util.helpers.has_permission_all(*args)#
- studygovernor.util.helpers.has_permission_any(*args)#
- studygovernor.util.helpers.http_auth_optional(realm)#
Decorator that protects endpoints using Basic HTTP authentication.
- Parameters:
realm – optional realm name
If authentication fails, this version will continue normally! This is to enable secondary fall-back with tokens.
Once authenticated, if so configured, CSRF protection will be tested.
- … warning::
Auth is optional, so this will not prohibit access to the route without further logic!
- studygovernor.util.helpers.initialize_workflow(workflow, app, verbose=False, force=True, upgrade=False)#
- studygovernor.util.helpers.upgrade_workflow(workflow, workflow_definition, db, verbose=False)#
studygovernor.models
Module#
- class studygovernor.models.Action(experiment=None, transition=None, freetext=None)#
Bases:
Model
- property api_uri: str#
- Return type:
str
- end_time#
- executions#
- experiment#
- experiment_id#
- freetext#
- id#
- return_value#
- start_time#
- success#
- transition#
- transition_id#
- property web_uri: str#
- Return type:
str
- class studygovernor.models.Callback(**kwargs)#
Bases:
Model
” Data model representing the definition of a callback. This defines how a callback should be executed, but is not linked to a specific execution.
- callback_arguments#
- condition#
- description#
- executions#
- function#
- id#
- initial_delay#
- label#
- run_timeout#
- state#
- state_id#
- variable_map#
- wait_timeout#
- class studygovernor.models.CallbackExecution(**kwargs)#
Bases:
Model
Data model representing one execution of a callback. Links back to the callback definition and the source action.
- action_id#
- property api_uri: str#
- Return type:
str
- callback_id#
- property cohort#
- created#
- property experiment#
- property external_systems#
- finished#
- id#
- result#
- result_log#
- result_values#
- run_log#
- run_start#
- secret_key#
- status#
- property subject#
- uri(blueprint=None)#
- Return type:
str
- wait_start#
- property web_uri: str#
- Return type:
str
- class studygovernor.models.CallbackExecutionResult(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
str
,Enum
” Defined the valid result categories for a callback execution
- property badge_class#
- failed = 'failed'#
- none = 'none'#
- success = 'success'#
- timeout = 'timeout'#
- class studygovernor.models.CallbackExecutionStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
str
,Enum
” Defined the valid states for callback execution
- property badge_class#
- created = 'created'#
- finished = 'finished'#
- queued = 'queued'#
- property resolved#
- running = 'running'#
- skipped = 'skipped'#
- waiting = 'waiting'#
- class studygovernor.models.Cohort(**kwargs)#
Bases:
Model
- description#
- external_system_urls#
- property external_urls#
- id#
- label#
- subjects#
- class studygovernor.models.Experiment(**kwargs)#
Bases:
Model
- actions#
- property api_uri: str#
- Return type:
str
- external_experiment_links#
- property external_ids#
- find_external_id(external_system_name)#
- id#
- label#
- scandate#
- scans#
- subject#
- subject_id#
- property variable_map#
- variables#
- property web_uri: str#
- Return type:
str
- class studygovernor.models.ExternalCohortUrls(**kwargs)#
Bases:
Model
- cohort#
- cohort_id#
- external_system#
- external_system_id#
- id#
- url#
- class studygovernor.models.ExternalExperimentLinks(external_id=None, experiment=None, external_system=None)#
Bases:
Model
- experiment#
- experiment_id#
- external_id#
- external_system#
- external_system_id#
- id#
- class studygovernor.models.ExternalSubjectLinks(external_id=None, subject=None, external_system=None)#
Bases:
Model
- external_id#
- external_system#
- external_system_id#
- id#
- subject#
- subject_id#
- class studygovernor.models.ExternalSystem(id=None, system_name=None, url=None)#
Bases:
Model
- external_cohort_urls#
- external_experiment_links#
- external_subject_links#
- history#
- id#
- system_name#
- url#
- class studygovernor.models.ExternalSystemHistory(**kwargs)#
Bases:
Model
- external_system#
- id#
- system_id#
- timestamp#
- url#
- class studygovernor.models.Role(**kwargs)#
Bases:
Model
,BaseRole
This implements the BaseRole from the .auth.models module. In this specific case, the BaseRole is sufficient.
- description#
- id#
- name#
- permissions: t.Union[str, set, list, None]#
- update_datetime#
- users#
- class studygovernor.models.Scan(experiment=None, scantype=None)#
Bases:
Model
- experiment#
- experiment_id#
- id#
- scantype#
- scantype_id#
- class studygovernor.models.Scantype(id=None, modality=None, protocol=None)#
Bases:
Model
- id#
- modality#
- protocol#
- scans#
- class studygovernor.models.State(**kwargs)#
Bases:
Model
- callbacks#
- property experiments#
- freetext#
- get_transition_to(target_state)#
- id#
- label#
- transition_destinations#
- transition_sources#
- workflow#
- workflow_id#
- class studygovernor.models.Subject(**kwargs)#
Bases:
Model
- property api_uri: str#
- Return type:
str
- cohort#
- cohort_id#
- date_of_birth#
- experiments#
- property external_ids#
- external_subject_links#
- id#
- label#
- property web_uri: str#
- Return type:
str
- class studygovernor.models.Transition(id=None, source_state=None, destination_state=None, condition=None)#
Bases:
Model
- actions#
- condition#
- destination_state#
- destination_state_id#
- id#
- source_state#
- source_state_id#
- class studygovernor.models.User(**kwargs)#
Bases:
Model
,BaseUser
- active#
- confirmed_at#
- create_datetime#
- create_time#
- current_login_at#
- current_login_ip#
- email#
- fs_uniquifier#
- id#
- last_login_at#
- last_login_ip#
- login_count#
- name#
- password#
- roles#
- tf_phone_number#
- tf_primary_method#
- tf_totp_secret#
- update_datetime#
- username#
- class studygovernor.models.Variable(**kwargs)#
Bases:
Model
- experiment#
- experiment_id#
- id#
- label#
- type#
- value#
- class studygovernor.models.VariableType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
Enum
- bool = 'bool'#
- date = 'date'#
- datetime = 'datetime'#
- float = 'float'#
- int = 'int'#
- json = 'json'#
- none = 'none'#
- classmethod pack(value)#
- Return type:
Tuple
[VariableType
,str
]
- str = 'str'#
- time = 'time'#
- classmethod unpack(value, var_type)#
- Return type:
Any
- studygovernor.models.log_history(mapper, connection, target)#