Context Management in qnexus¶
Functions for managing context in the client.
- qnexus.context.deactivate_project(
- token: Token[ProjectRef | None],
Deactivate a project from the current context.
- qnexus.context.get_active_project(
- project_required: bool = False,
Get a reference to the active project if set.
>>> get_active_project()
>>> from qnexus.models.annotations import Annotations >>> token = set_active_project_token( ... ProjectRef(id="dca33f7f-9619-4cf7-a3fb-56256b117d6e", ... annotations=Annotations(name="example"))) >>> get_active_project() ProjectRef( id=UUID('dca33f7f-9619-4cf7-a3fb-56256b117d6e'), annotations=Annotations(name='example', description=None, properties=OrderedDict()) )
>>> deactivate_project(token)
- qnexus.context.get_active_properties() OrderedDict[str, bool | int | float | str] ¶
Get the keys and values of the currently active properties.
>>> get_active_properties() OrderedDict()
>>> token = update_active_properties_token(foo=3, bar=True) >>> get_active_properties() OrderedDict([('foo', 3), ('bar', True)])
>>> deactivate_properties(token)
- qnexus.context.merge_project_from_context(
- func: Callable,
Decorator to merge a project from the context. ProjectRef in kwargs takes precedence (will be selected).
- qnexus.context.merge_properties_from_context(
- func: Callable,
Decorator to take the union of properties from the context with any provided in kwargs. Properties in kwargs take precendence.
- qnexus.context.set_active_project(
- project: ProjectRef,
Globally set a project as active.
- qnexus.context.set_active_project_token(
- project: ProjectRef,
Globally set a project as active, returning a Token to the ProjectRef in the context.
- qnexus.context.update_active_properties( ) None ¶
Globally update and merge properties with the existing ones.
- qnexus.context.update_active_properties_token( ) Token[OrderedDict[str, bool | int | float | str] | None] ¶
Globally update and merge properties with the existing ones, returning a token to the PropertiesDict in the context.
- qnexus.context.using_project(
- project: ProjectRef,
Attach a ProjectRef to the current context.
All operations in the context will make use of the project.
>>> from qnexus.models.annotations import Annotations >>> project = ProjectRef( ... id="cd325b9c-d4a2-4b6e-ae58-8fad89749fac", ... annotations=Annotations(name="example")) >>> with using_project(project): ... get_active_project() ProjectRef( id=UUID('cd325b9c-d4a2-4b6e-ae58-8fad89749fac'), annotations=Annotations(name='example', description=None, properties=OrderedDict()) )
>>> get_active_project()