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.check_json_serializable(data)#
Check if given data is JSON serializable
- Parameters:
data (
Any) – Data to check- Return type:
bool- Returns:
Bool indicating the data is serializable
- 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:
StudyGovernorHTTPErrorCould not find a resource
- code: int | None = 404#
- exception studygovernor.exceptions.NoValidTransitionError(sourcestate, targetstate)#
Bases:
StateChangeError
- exception studygovernor.exceptions.RESTResponseError#
Bases:
StudyGovernorClientErrorThe REST response is not what was expected
- exception studygovernor.exceptions.StateChangeError#
Bases:
StudyGovernorErrorExceptions encountered during a state change
- exception studygovernor.exceptions.StateNotFoundError(requested_state)#
Bases:
StateChangeError
- exception studygovernor.exceptions.StudyGovernorClientError#
Bases:
StudyGovernorErrorError class for all client-side errors
- exception studygovernor.exceptions.StudyGovernorError#
Bases:
ExceptionBase class for exceptions in the study governor codebase
- property fields#
- marshal(api_prefix)#
- exception studygovernor.exceptions.StudyGovernorHTTPError(description, response=None)#
Bases:
StudyGovernorError,HTTPExceptionAll exceptions that should lead to an HTTP error response
- code: int | None = 500#
- property description#
- exception studygovernor.exceptions.StudyGovernorSSLError#
Bases:
StudyGovernorClientErrorThere 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(**kwargs)#
Bases:
Model- property api_uri: str#
- Return type:
str
- end_time#
- executions#
- experiment#
- experiment_id#
- freetext#
- id#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- run_timeout#
- state#
- state_id#
- variable_map#
- wait_timeout#
- class studygovernor.models.CallbackExecution(**kwargs)#
Bases:
ModelData 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- class studygovernor.models.ExternalSubjectLinks(external_id=None, subject=None, external_system=None)#
Bases:
Model- external_id#
- external_system#
- external_system_id#
- id#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- system_name#
- url#
- class studygovernor.models.ExternalSystemHistory(**kwargs)#
Bases:
Model- external_system#
- id#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- system_id#
- timestamp#
- url#
- class studygovernor.models.Role(**kwargs)#
Bases:
Model,BaseRoleThis implements the BaseRole from the .auth.models module. In this specific case, the BaseRole is sufficient.
- description: str | None#
- id: int#
- name: str#
- permissions: list[str] | None#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- update_datetime: datetime#
- class studygovernor.models.Scan(experiment=None, scantype=None)#
Bases:
Model- experiment#
- experiment_id#
- id#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- scantype#
- scantype_id#
- class studygovernor.models.Scantype(id=None, modality=None, protocol=None)#
Bases:
Model- id#
- modality#
- protocol#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- scans#
- class studygovernor.models.State(**kwargs)#
Bases:
Model- callbacks#
- property experiments#
- freetext#
- get_transition_to(target_state)#
- id#
- label#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- source_state#
- source_state_id#
- class studygovernor.models.User(**kwargs)#
Bases:
Model,BaseUser- active: bool#
- confirmed_at: datetime | None#
- create_datetime: datetime#
- create_time#
- current_login_at: datetime#
- current_login_ip: str | None#
- email: str#
- fs_uniquifier: str#
- id: int#
- last_login_at: datetime#
- last_login_ip: str | None#
- login_count: int#
- name#
- password: str | None#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- roles: list[RoleMixin]#
- tf_phone_number: str | None#
- tf_primary_method: str | None#
- tf_totp_secret: str | None#
- update_datetime: datetime#
- username: str | None#
- class studygovernor.models.Variable(**kwargs)#
Bases:
Model- experiment#
- experiment_id#
- id#
- label#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- 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
- class studygovernor.models.Workflow(**kwargs)#
Bases:
Model- id#
- label#
- query: t.ClassVar[Query]#
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model). Can be customized per-model by overridingquery_class.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())instead.
- states#
- studygovernor.models.log_history(mapper, connection, target)#